@dxos/plugin-script 0.8.2-staging.7ac8446 → 0.8.2
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-Q2K5FJSC.mjs +272 -0
- package/dist/lib/browser/ScriptContainer-Q2K5FJSC.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-74DEDPHT.mjs +530 -0
- package/dist/lib/browser/chunk-74DEDPHT.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-KLEOGVXY.mjs → chunk-JQOAZJTK.mjs} +87 -156
- package/dist/lib/browser/chunk-JQOAZJTK.mjs.map +7 -0
- package/dist/lib/browser/chunk-M6QMJBKQ.mjs +87 -0
- package/dist/lib/browser/chunk-M6QMJBKQ.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 +17 -16
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-WCVXKRBR.mjs → intent-resolver-U5YRUE7W.mjs} +14 -14
- package/dist/lib/browser/intent-resolver-U5YRUE7W.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-WXZVPNGI.mjs → react-surface-3MSPT54G.mjs} +12 -12
- package/dist/lib/browser/react-surface-3MSPT54G.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-56SH6R24.cjs +289 -0
- package/dist/lib/node/ScriptContainer-56SH6R24.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-5LHP5EUJ.cjs +557 -0
- package/dist/lib/node/chunk-5LHP5EUJ.cjs.map +7 -0
- package/dist/lib/node/chunk-BYLHJ26I.cjs +91 -0
- package/dist/lib/node/chunk-BYLHJ26I.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-F4DP7WON.cjs → chunk-NRZJV5SV.cjs} +93 -160
- package/dist/lib/node/chunk-NRZJV5SV.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 +46 -45
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/{intent-resolver-J4NBDNFH.cjs → intent-resolver-7SF26VGC.cjs} +21 -21
- package/dist/lib/node/intent-resolver-7SF26VGC.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/{react-surface-27KTUBIZ.cjs → react-surface-L6RS7BT2.cjs} +38 -38
- package/dist/lib/node/react-surface-L6RS7BT2.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-6RCZ43TI.mjs +273 -0
- package/dist/lib/node-esm/ScriptContainer-6RCZ43TI.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-KOO76P2Y.mjs +531 -0
- package/dist/lib/node-esm/chunk-KOO76P2Y.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/{chunk-PBGVTGL2.mjs → chunk-WD7OFSM3.mjs} +87 -156
- package/dist/lib/node-esm/chunk-WD7OFSM3.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-Z44O2YIK.mjs +89 -0
- package/dist/lib/node-esm/chunk-Z44O2YIK.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 +17 -16
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-PDZ2A26X.mjs → intent-resolver-3APO7YDF.mjs} +14 -14
- package/dist/lib/node-esm/intent-resolver-3APO7YDF.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-UCUVDVSH.mjs → react-surface-S5LHD3IA.mjs} +12 -12
- package/dist/lib/node-esm/react-surface-S5LHD3IA.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/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/TestPanel.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 +5 -5
- 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/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.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.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.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
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { createTool, ToolResult } from '@dxos/ai';
|
|
5
8
|
import { Capabilities, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
|
|
6
|
-
import {
|
|
9
|
+
import { ArtifactId, defineArtifact } from '@dxos/artifact';
|
|
7
10
|
import { createArtifactElement } from '@dxos/assistant';
|
|
8
|
-
import {
|
|
9
|
-
import { ScriptType } from '@dxos/functions/types';
|
|
11
|
+
import { ScriptType } from '@dxos/functions';
|
|
10
12
|
import { invariant } from '@dxos/invariant';
|
|
11
13
|
import { SpaceAction } from '@dxos/plugin-space/types';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
+
import { Filter, live, makeRef, type Space } from '@dxos/react-client/echo';
|
|
15
|
+
import { DataType } from '@dxos/schema';
|
|
14
16
|
|
|
15
17
|
import { meta } from '../meta';
|
|
16
18
|
// TODO(burdon): Factor out.
|
|
@@ -71,28 +73,28 @@ export default () => {
|
|
|
71
73
|
<apis>
|
|
72
74
|
export function defineFunction(params: {
|
|
73
75
|
description: string,
|
|
74
|
-
inputSchema:
|
|
75
|
-
outputSchema:
|
|
76
|
+
inputSchema: Schema.Schema,
|
|
77
|
+
outputSchema: Schema.Schema,
|
|
76
78
|
handler: (params: { event: { data: TInput } }) => Promise<TOutput>
|
|
77
79
|
}): FunctionDefinition
|
|
78
80
|
/**
|
|
79
81
|
* Effect Schema
|
|
80
82
|
*/
|
|
81
|
-
export const
|
|
83
|
+
export const Schema;
|
|
82
84
|
|
|
83
85
|
// Examples:
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
from:
|
|
90
|
-
to:
|
|
87
|
+
Schema.String
|
|
88
|
+
Schema.Number
|
|
89
|
+
Schema.Boolean
|
|
90
|
+
Schema.Struct({
|
|
91
|
+
from: Schema.String.annotations({ description: 'The source currency' }),
|
|
92
|
+
to: Schema.String.annotations({ description: 'The target currency' }),
|
|
91
93
|
})
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
Schema.Array(Schema.String)
|
|
95
|
+
Schema.Union(Schema.String, Schema.Number)
|
|
96
|
+
Schema.optional(Schema.String)
|
|
97
|
+
Schema.String.annotations({ description: 'The source currency' })
|
|
96
98
|
</apis>
|
|
97
99
|
|
|
98
100
|
<handler_function>
|
|
@@ -113,13 +115,13 @@ export default () => {
|
|
|
113
115
|
export default defineFunction({
|
|
114
116
|
description: 'Returns the exchange rate between two currencies.',
|
|
115
117
|
|
|
116
|
-
inputSchema:
|
|
117
|
-
from:
|
|
118
|
-
to:
|
|
118
|
+
inputSchema: Schema.Struct({
|
|
119
|
+
from: Schema.String.annotations({ description: 'The source currency' }),
|
|
120
|
+
to: Schema.String.annotations({ description: 'The target currency' }),
|
|
119
121
|
}),
|
|
120
122
|
|
|
121
|
-
outputSchema:
|
|
122
|
-
rate:
|
|
123
|
+
outputSchema: Schema.Struct({
|
|
124
|
+
rate: Schema.String.annotations({ description: 'The exchange rate' }),
|
|
123
125
|
}),
|
|
124
126
|
|
|
125
127
|
handler: async ({
|
|
@@ -139,23 +141,23 @@ export default () => {
|
|
|
139
141
|
`,
|
|
140
142
|
schema: ScriptType,
|
|
141
143
|
tools: [
|
|
142
|
-
|
|
144
|
+
createTool(meta.id, {
|
|
143
145
|
name: 'create',
|
|
144
146
|
description: 'Create a new script. Returns the artifact definition for the script',
|
|
145
147
|
caption: 'Creating script...',
|
|
146
|
-
schema:
|
|
147
|
-
name:
|
|
148
|
-
code:
|
|
148
|
+
schema: Schema.Struct({
|
|
149
|
+
name: Schema.String.annotations({ description: 'The name of the script' }),
|
|
150
|
+
code: Schema.String.annotations({
|
|
149
151
|
description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',
|
|
150
152
|
}),
|
|
151
153
|
}),
|
|
152
154
|
execute: async ({ name, code }, { extensions }) => {
|
|
153
155
|
invariant(extensions?.space, 'No space');
|
|
154
156
|
invariant(extensions?.dispatch, 'No intent dispatcher');
|
|
155
|
-
const script =
|
|
157
|
+
const script = live(ScriptType, {
|
|
156
158
|
name,
|
|
157
159
|
source: makeRef(
|
|
158
|
-
|
|
160
|
+
live(DataType.Text, {
|
|
159
161
|
content: code,
|
|
160
162
|
}),
|
|
161
163
|
),
|
|
@@ -172,17 +174,17 @@ export default () => {
|
|
|
172
174
|
return ToolResult.Success(createArtifactElement(script.id));
|
|
173
175
|
},
|
|
174
176
|
}),
|
|
175
|
-
|
|
177
|
+
createTool(meta.id, {
|
|
176
178
|
name: 'inspect',
|
|
177
179
|
description: 'Inspect a script. Returns the artifact definition for the script',
|
|
178
180
|
caption: 'Inspecting script...',
|
|
179
|
-
schema:
|
|
180
|
-
id:
|
|
181
|
+
schema: Schema.Struct({
|
|
182
|
+
id: ArtifactId,
|
|
181
183
|
}),
|
|
182
184
|
execute: async ({ id }, { extensions }) => {
|
|
183
185
|
invariant(extensions?.space, 'No space');
|
|
184
186
|
|
|
185
|
-
const script = (await extensions.space.db.query(
|
|
187
|
+
const script = (await extensions.space.db.query(Filter.ids(id)).first()) as ScriptType;
|
|
186
188
|
const { content } = await script.source.load();
|
|
187
189
|
|
|
188
190
|
return ToolResult.Success({
|
|
@@ -191,20 +193,20 @@ export default () => {
|
|
|
191
193
|
});
|
|
192
194
|
},
|
|
193
195
|
}),
|
|
194
|
-
|
|
196
|
+
createTool(meta.id, {
|
|
195
197
|
name: 'update',
|
|
196
198
|
description: 'Update a script. Returns the artifact definition for the script',
|
|
197
199
|
caption: 'Updating script...',
|
|
198
|
-
schema:
|
|
199
|
-
id:
|
|
200
|
-
code:
|
|
200
|
+
schema: Schema.Struct({
|
|
201
|
+
id: ArtifactId,
|
|
202
|
+
code: Schema.String.annotations({
|
|
201
203
|
description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',
|
|
202
204
|
}),
|
|
203
205
|
}),
|
|
204
206
|
execute: async ({ id, code }, { extensions }) => {
|
|
205
207
|
invariant(extensions?.space, 'No space');
|
|
206
208
|
|
|
207
|
-
const script = (await extensions.space.db.query(
|
|
209
|
+
const script = (await extensions.space.db.query(Filter.ids(id)).first()) as ScriptType;
|
|
208
210
|
const source = await script.source.load();
|
|
209
211
|
if (!source) {
|
|
210
212
|
return ToolResult.Error('Script not found');
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Octokit } from '@octokit/core';
|
|
6
|
-
import {
|
|
6
|
+
import { Predicate } from 'effect';
|
|
7
7
|
|
|
8
8
|
import { contributes, Capabilities, createResolver, createIntent, LayoutAction } from '@dxos/app-framework';
|
|
9
|
-
import { ScriptType } from '@dxos/functions
|
|
10
|
-
import {
|
|
9
|
+
import { ScriptType } from '@dxos/functions';
|
|
10
|
+
import { live, makeRef } from '@dxos/live-object';
|
|
11
11
|
import { TokenManagerAction } from '@dxos/plugin-token-manager/types';
|
|
12
|
-
import {
|
|
12
|
+
import { DataType } from '@dxos/schema';
|
|
13
13
|
|
|
14
14
|
import { DEPLOYMENT_DIALOG } from '../components';
|
|
15
15
|
import { defaultScriptsForIntegration } from '../meta';
|
|
@@ -47,9 +47,9 @@ export default () =>
|
|
|
47
47
|
|
|
48
48
|
return {
|
|
49
49
|
data: {
|
|
50
|
-
object:
|
|
50
|
+
object: live(ScriptType, {
|
|
51
51
|
name,
|
|
52
|
-
source: makeRef(
|
|
52
|
+
source: makeRef(live(DataType.Text, { content })),
|
|
53
53
|
}),
|
|
54
54
|
},
|
|
55
55
|
};
|
|
@@ -60,7 +60,7 @@ export default () =>
|
|
|
60
60
|
resolve: async ({ accessToken }) => {
|
|
61
61
|
const scriptTemplates = (defaultScriptsForIntegration[accessToken.source] ?? [])
|
|
62
62
|
.map((id) => templates.find((t) => t.id === id))
|
|
63
|
-
.filter(isNotNullable);
|
|
63
|
+
.filter(Predicate.isNotNullable);
|
|
64
64
|
|
|
65
65
|
if (scriptTemplates.length > 0) {
|
|
66
66
|
return {
|
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
7
|
import { Capabilities, contributes, createSurface, useCapability } from '@dxos/app-framework';
|
|
8
|
-
import {
|
|
8
|
+
import { InvocationTraceContainer } from '@dxos/devtools';
|
|
9
9
|
import { isInstanceOf } from '@dxos/echo-schema';
|
|
10
|
-
import { ScriptType } from '@dxos/functions
|
|
10
|
+
import { ScriptType } from '@dxos/functions';
|
|
11
11
|
import { SettingsStore } from '@dxos/local-storage';
|
|
12
12
|
import { getSpace } from '@dxos/react-client/echo';
|
|
13
13
|
import { StackItem } from '@dxos/react-ui-stack';
|
|
14
|
-
import { type
|
|
14
|
+
import { type DataType } from '@dxos/schema';
|
|
15
15
|
|
|
16
16
|
import { ScriptCapabilities } from './capabilities';
|
|
17
17
|
import {
|
|
@@ -84,7 +84,7 @@ export default () =>
|
|
|
84
84
|
const space = getSpace(data.companionTo);
|
|
85
85
|
return (
|
|
86
86
|
<StackItem.Content role={role}>
|
|
87
|
-
<
|
|
87
|
+
<InvocationTraceContainer space={space} script={data.companionTo} detailAxis='block' />
|
|
88
88
|
</StackItem.Content>
|
|
89
89
|
);
|
|
90
90
|
},
|
|
@@ -92,7 +92,7 @@ export default () =>
|
|
|
92
92
|
createSurface({
|
|
93
93
|
id: DEPLOYMENT_DIALOG,
|
|
94
94
|
role: 'dialog',
|
|
95
|
-
filter: (data): data is { props: { accessToken:
|
|
95
|
+
filter: (data): data is { props: { accessToken: DataType.AccessToken; scriptTemplates: any } } =>
|
|
96
96
|
data.component === DEPLOYMENT_DIALOG,
|
|
97
97
|
component: ({ data }) => <DeploymentDialog {...data.props} />,
|
|
98
98
|
}),
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Capabilities, contributes } from '@dxos/app-framework';
|
|
6
|
-
import {
|
|
6
|
+
import { live } from '@dxos/live-object';
|
|
7
7
|
|
|
8
8
|
import { meta } from '../meta';
|
|
9
9
|
import { ScriptSettingsSchema } from '../types';
|
|
10
10
|
|
|
11
11
|
export default () => {
|
|
12
|
-
const settings =
|
|
12
|
+
const settings = live(ScriptSettingsSchema, { editorInputMode: 'vscode' });
|
|
13
13
|
return contributes(Capabilities.Settings, { schema: ScriptSettingsSchema, prefix: meta.id, value: settings });
|
|
14
14
|
};
|
package/src/compiler/compiler.ts
CHANGED
|
@@ -23,7 +23,7 @@ export class Compiler {
|
|
|
23
23
|
|
|
24
24
|
constructor(private readonly _options: ts.CompilerOptions = defaultOptions) {}
|
|
25
25
|
|
|
26
|
-
async initialize() {
|
|
26
|
+
async initialize(): Promise<void> {
|
|
27
27
|
if (this._env) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
@@ -40,12 +40,12 @@ export class Compiler {
|
|
|
40
40
|
return this._env;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
setFile(fileName: string, content: string) {
|
|
43
|
+
setFile(fileName: string, content: string): void {
|
|
44
44
|
invariant(this._fsMap, 'File system map not initialized.');
|
|
45
45
|
this.environment.createFile(fileName, content);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
compile(fileName: string) {
|
|
48
|
+
compile(fileName: string): ts.EmitOutput {
|
|
49
49
|
return this.environment.languageService.getEmitOutput(fileName);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -33,7 +33,7 @@ const meta: Meta = {
|
|
|
33
33
|
title: 'plugins/plugin-script/DeploymentDialog',
|
|
34
34
|
component: DeploymentDialog,
|
|
35
35
|
parameters: { translations },
|
|
36
|
-
decorators: [withTheme, withLayout(
|
|
36
|
+
decorators: [withTheme, withLayout()],
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export default meta;
|
|
@@ -7,7 +7,7 @@ import React, { useEffect, useMemo } from 'react';
|
|
|
7
7
|
import { createIntent, LayoutAction, useIntentDispatcher } from '@dxos/app-framework';
|
|
8
8
|
import { getSpace } from '@dxos/react-client/echo';
|
|
9
9
|
import { Button, Dialog, Icon, useTranslation } from '@dxos/react-ui';
|
|
10
|
-
import { type
|
|
10
|
+
import { type DataType } from '@dxos/schema';
|
|
11
11
|
|
|
12
12
|
import { useCreateAndDeployScriptTemplates } from '../../hooks/useCreateAndDeployScriptTemplates';
|
|
13
13
|
import { SCRIPT_PLUGIN } from '../../meta';
|
|
@@ -21,7 +21,7 @@ export const DEPLOYMENT_DIALOG = `${SCRIPT_PLUGIN}/deployment/dialog`;
|
|
|
21
21
|
// - Pending / onError states.
|
|
22
22
|
|
|
23
23
|
type DeploymentDialogProps = {
|
|
24
|
-
accessToken:
|
|
24
|
+
accessToken: DataType.AccessToken;
|
|
25
25
|
scriptTemplates: Template[];
|
|
26
26
|
};
|
|
27
27
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type ScriptType } from '@dxos/functions
|
|
7
|
+
import { type ScriptType } from '@dxos/functions';
|
|
8
8
|
import { createDocAccessor, getSpace } from '@dxos/react-client/echo';
|
|
9
9
|
import { useIdentity } from '@dxos/react-client/halo';
|
|
10
10
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
@@ -57,7 +57,7 @@ export const ScriptContainer = ({
|
|
|
57
57
|
);
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
|
-
<StackItem.Content toolbar
|
|
60
|
+
<StackItem.Content toolbar>
|
|
61
61
|
<ScriptToolbar state={state} role={role} script={script} />
|
|
62
62
|
<TypescriptEditor
|
|
63
63
|
id={script.id}
|
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { Rx } from '@effect-rx/rx-react';
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
6
7
|
|
|
7
|
-
import { type ScriptType } from '@dxos/functions
|
|
8
|
+
import { type ScriptType } from '@dxos/functions';
|
|
8
9
|
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
9
|
-
import { ElevationProvider, type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
+
import { ElevationProvider, useTranslation, type ThemedClassName } from '@dxos/react-ui';
|
|
10
11
|
import { stackItemContentToolbarClassNames } from '@dxos/react-ui-editor';
|
|
11
|
-
import { createGapSeparator, MenuProvider, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';
|
|
12
|
+
import { createGapSeparator, MenuProvider, rxFromSignal, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';
|
|
12
13
|
|
|
13
14
|
import {
|
|
15
|
+
type CreateDeployOptions,
|
|
14
16
|
type ScriptToolbarState,
|
|
15
17
|
createDeploy,
|
|
16
18
|
createFormat,
|
|
17
19
|
createTemplateSelect,
|
|
18
|
-
|
|
20
|
+
useDeployDeps,
|
|
19
21
|
} from '../../hooks';
|
|
22
|
+
import { SCRIPT_PLUGIN } from '../../meta';
|
|
20
23
|
|
|
21
24
|
export type ScriptToolbarProps = ThemedClassName<{
|
|
22
25
|
role?: string;
|
|
@@ -24,26 +27,32 @@ export type ScriptToolbarProps = ThemedClassName<{
|
|
|
24
27
|
state: ScriptToolbarState;
|
|
25
28
|
}>;
|
|
26
29
|
|
|
27
|
-
const createToolbar = (state:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
const createToolbar = ({ state, script, ...options }: CreateDeployOptions) =>
|
|
31
|
+
Rx.make((get) =>
|
|
32
|
+
get(
|
|
33
|
+
rxFromSignal(() => {
|
|
34
|
+
const templateSelect = createTemplateSelect(script);
|
|
35
|
+
const format = createFormat(script);
|
|
36
|
+
const gap = createGapSeparator();
|
|
37
|
+
const deploy = createDeploy({ state, script, ...options });
|
|
38
|
+
return {
|
|
39
|
+
nodes: [...templateSelect.nodes, ...format.nodes, ...gap.nodes, ...deploy.nodes],
|
|
40
|
+
edges: [...templateSelect.edges, ...format.edges, ...gap.edges, ...deploy.edges],
|
|
41
|
+
};
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
37
45
|
|
|
38
46
|
export const ScriptToolbar = ({ script, role, state, classNames }: ScriptToolbarProps) => {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
47
|
+
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
48
|
+
const options = useDeployDeps({ script });
|
|
49
|
+
const toolbarCreator = useMemo(() => createToolbar({ state, script, t, ...options }), [state, script, options, t]);
|
|
41
50
|
const menu = useMenuActions(toolbarCreator);
|
|
42
51
|
|
|
43
52
|
return (
|
|
44
53
|
<div role='none' className={stackItemContentToolbarClassNames(role)}>
|
|
45
54
|
<ElevationProvider elevation={role === 'section' ? 'positioned' : 'base'}>
|
|
46
|
-
<MenuProvider {...menu}
|
|
55
|
+
<MenuProvider {...menu} attendableId={fullyQualifiedId(script)}>
|
|
47
56
|
<ToolbarMenu classNames={classNames} />
|
|
48
57
|
</MenuProvider>
|
|
49
58
|
</ElevationProvider>
|
|
@@ -6,12 +6,12 @@ import { Octokit } from '@octokit/core';
|
|
|
6
6
|
import React, { type ChangeEvent, useCallback, useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { createIntent, SettingsAction, useIntentDispatcher } from '@dxos/app-framework';
|
|
9
|
-
import { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions
|
|
9
|
+
import { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
11
11
|
import { useClient } from '@dxos/react-client';
|
|
12
|
-
import { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
12
|
+
import { Filter, getMeta, getSpace, Ref, useQuery } from '@dxos/react-client/echo';
|
|
13
13
|
import { Button, Clipboard, Input, useControlledState, useTranslation } from '@dxos/react-ui';
|
|
14
|
-
import {
|
|
14
|
+
import { DataType } from '@dxos/schema';
|
|
15
15
|
|
|
16
16
|
import { SCRIPT_PLUGIN } from '../../meta';
|
|
17
17
|
|
|
@@ -48,7 +48,7 @@ const Binding = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
48
48
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
49
49
|
const client = useClient();
|
|
50
50
|
const space = getSpace(object);
|
|
51
|
-
const [fn] = useQuery(space, Filter.
|
|
51
|
+
const [fn] = useQuery(space, Filter.type(FunctionType, { source: Ref.make(object) }));
|
|
52
52
|
|
|
53
53
|
const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));
|
|
54
54
|
const functionUrl =
|
|
@@ -112,7 +112,7 @@ const Publishing = ({ object }: ScriptObjectSettingsProps) => {
|
|
|
112
112
|
const { t } = useTranslation(SCRIPT_PLUGIN);
|
|
113
113
|
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
114
114
|
const space = getSpace(object);
|
|
115
|
-
const [githubToken] = useQuery(space, Filter.
|
|
115
|
+
const [githubToken] = useQuery(space, Filter.type(DataType.AccessToken, { source: 'github.com' }));
|
|
116
116
|
const gistKey = getMeta(object).keys.find(({ source }) => source === 'github.com');
|
|
117
117
|
const [gistUrl, setGistUrl] = useState<string | undefined>();
|
|
118
118
|
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
autocomplete,
|
|
19
19
|
createBasicExtensions,
|
|
20
20
|
createThemeExtensions,
|
|
21
|
-
editorFullWidth,
|
|
22
21
|
type EditorInputMode,
|
|
23
22
|
editorMonospace,
|
|
24
23
|
EditorView,
|
|
@@ -64,15 +63,10 @@ export const TypescriptEditor = ({
|
|
|
64
63
|
createThemeExtensions({
|
|
65
64
|
themeMode,
|
|
66
65
|
syntaxHighlighting: true,
|
|
67
|
-
slots: {
|
|
68
|
-
content: { className: editorFullWidth },
|
|
69
|
-
},
|
|
70
66
|
}),
|
|
71
67
|
// NOTE: Not using default editor gutter because folding for code works best right beside text.
|
|
72
68
|
EditorView.theme({
|
|
73
69
|
'.cm-gutters': {
|
|
74
|
-
// Match margin from content.
|
|
75
|
-
marginTop: '16px',
|
|
76
70
|
background: 'var(--dx-baseSurface)',
|
|
77
71
|
},
|
|
78
72
|
}),
|
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]);
|