@dxos/plugin-automation 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29
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/neutral/AutomationPanel-64U7W3SJ.mjs +11 -0
- package/dist/lib/neutral/AutomationPlugin.mjs +38 -0
- package/dist/lib/neutral/AutomationPlugin.mjs.map +7 -0
- package/dist/lib/neutral/AutomationPlugin.node.mjs +1113 -0
- package/dist/lib/neutral/AutomationPlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/AutomationSettings-NNL2AVNT.mjs +31 -0
- package/dist/lib/neutral/AutomationSettings-NNL2AVNT.mjs.map +7 -0
- package/dist/lib/neutral/FunctionsContainer-CU2FVKZF.mjs +38 -0
- package/dist/lib/neutral/FunctionsContainer-CU2FVKZF.mjs.map +7 -0
- package/dist/lib/neutral/FunctionsPanel-GLCUBEDT.mjs +96 -0
- package/dist/lib/neutral/FunctionsPanel-GLCUBEDT.mjs.map +7 -0
- package/dist/lib/neutral/FunctionsRegistry-VRU4FBVH.mjs +94 -0
- package/dist/lib/neutral/FunctionsRegistry-VRU4FBVH.mjs.map +7 -0
- package/dist/lib/neutral/TriggerSettings-XCHIZPOR.mjs +9 -0
- package/dist/lib/neutral/app-graph-builder-GDCGRYEP.mjs +75 -0
- package/dist/lib/neutral/app-graph-builder-GDCGRYEP.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +15 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/node.mjs +13 -0
- package/dist/lib/neutral/capabilities/node.mjs.map +7 -0
- package/dist/lib/neutral/chunk-2JP77CMN.mjs +42 -0
- package/dist/lib/neutral/chunk-2JP77CMN.mjs.map +7 -0
- package/dist/lib/neutral/chunk-ATECY555.mjs +20 -0
- package/dist/lib/neutral/chunk-ATECY555.mjs.map +7 -0
- package/dist/lib/neutral/chunk-DSCOLDT5.mjs +93 -0
- package/dist/lib/neutral/chunk-DSCOLDT5.mjs.map +7 -0
- package/dist/lib/neutral/chunk-FKFFU54G.mjs +270 -0
- package/dist/lib/neutral/chunk-FKFFU54G.mjs.map +7 -0
- package/dist/lib/neutral/chunk-GDNOJOAR.mjs +8 -0
- package/dist/lib/neutral/chunk-GDNOJOAR.mjs.map +7 -0
- package/dist/lib/neutral/chunk-IGGNE2XI.mjs +12 -0
- package/dist/lib/neutral/chunk-IGGNE2XI.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-N735CP33.mjs +285 -0
- package/dist/lib/neutral/chunk-N735CP33.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +16 -0
- package/dist/lib/neutral/compute-runtime-2Q5MGOR6.mjs +220 -0
- package/dist/lib/neutral/compute-runtime-2Q5MGOR6.mjs.map +7 -0
- package/dist/lib/neutral/containers/index.mjs +13 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/neutral/create-trigger-from-template-5FT7O7OU.mjs +69 -0
- package/dist/lib/neutral/create-trigger-from-template-5FT7O7OU.mjs.map +7 -0
- package/dist/lib/neutral/hooks/index.mjs +129 -0
- package/dist/lib/neutral/hooks/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +20 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +8 -0
- package/dist/lib/neutral/operation-handler-YXGYH5W5.mjs +13 -0
- package/dist/lib/neutral/operation-handler-YXGYH5W5.mjs.map +7 -0
- package/dist/lib/neutral/operations/index.mjs +8 -0
- package/dist/lib/neutral/operations/index.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +16 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-3OGMAMKV.mjs +57 -0
- package/dist/lib/neutral/react-surface-3OGMAMKV.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +47 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +16 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/types/src/AutomationPlugin.d.ts +3 -1
- package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
- package/dist/types/src/AutomationPlugin.node.d.ts +4 -0
- package/dist/types/src/AutomationPlugin.node.d.ts.map +1 -0
- package/dist/types/src/AutomationPlugin.test.d.ts +2 -0
- package/dist/types/src/AutomationPlugin.test.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts +4 -2
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/compute-runtime.d.ts +14 -0
- package/dist/types/src/capabilities/compute-runtime.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +6 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/node.d.ts +6 -0
- package/dist/types/src/capabilities/node.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/commands/index.d.ts +2 -0
- package/dist/types/src/commands/index.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/create/index.d.ts +25 -0
- package/dist/types/src/commands/trigger/create/index.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/create/queue.d.ts +13 -0
- package/dist/types/src/commands/trigger/create/queue.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/create/subscription.d.ts +15 -0
- package/dist/types/src/commands/trigger/create/subscription.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/create/timer.d.ts +13 -0
- package/dist/types/src/commands/trigger/create/timer.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/index.d.ts +57 -0
- package/dist/types/src/commands/trigger/index.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/list.d.ts +7 -0
- package/dist/types/src/commands/trigger/list.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/options.d.ts +11 -0
- package/dist/types/src/commands/trigger/options.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/remove.d.ts +8 -0
- package/dist/types/src/commands/trigger/remove.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/update/index.d.ts +28 -0
- package/dist/types/src/commands/trigger/update/index.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/update/queue.d.ts +12 -0
- package/dist/types/src/commands/trigger/update/queue.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/update/subscription.d.ts +13 -0
- package/dist/types/src/commands/trigger/update/subscription.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/update/timer.d.ts +11 -0
- package/dist/types/src/commands/trigger/update/timer.d.ts.map +1 -0
- package/dist/types/src/commands/trigger/util.d.ts +46 -0
- package/dist/types/src/commands/trigger/util.d.ts.map +1 -0
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +6 -7
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts +32 -26
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/index.d.ts.map +1 -1
- package/dist/types/src/components/FunctionsPanel/FunctionsPanel.d.ts.map +1 -1
- package/dist/types/src/components/FunctionsPanel/index.d.ts.map +1 -1
- package/dist/types/src/components/FunctionsRegistry/FunctionsRegistry.d.ts +8 -0
- package/dist/types/src/components/FunctionsRegistry/FunctionsRegistry.d.ts.map +1 -0
- package/dist/types/src/components/FunctionsRegistry/index.d.ts +4 -0
- package/dist/types/src/components/FunctionsRegistry/index.d.ts.map +1 -0
- package/dist/types/src/components/TriggerEditor/FunctionInputEditor.d.ts +12 -9
- package/dist/types/src/components/TriggerEditor/FunctionInputEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/SpecSelector.d.ts +6 -3
- package/dist/types/src/components/TriggerEditor/SpecSelector.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +11 -8
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts +107 -30
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +3 -4
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/containers/AutomationSettings/AutomationSettings.d.ts +6 -0
- package/dist/types/src/containers/AutomationSettings/AutomationSettings.d.ts.map +1 -0
- package/dist/types/src/containers/AutomationSettings/index.d.ts +2 -0
- package/dist/types/src/containers/AutomationSettings/index.d.ts.map +1 -0
- package/dist/types/src/containers/FunctionsContainer/FunctionsContainer.d.ts +4 -0
- package/dist/types/src/containers/FunctionsContainer/FunctionsContainer.d.ts.map +1 -0
- package/dist/types/src/containers/FunctionsContainer/index.d.ts +2 -0
- package/dist/types/src/containers/FunctionsContainer/index.d.ts.map +1 -0
- package/dist/types/src/containers/TriggerSettings/TriggerSettings.d.ts +6 -0
- package/dist/types/src/containers/TriggerSettings/TriggerSettings.d.ts.map +1 -0
- package/dist/types/src/containers/TriggerSettings/index.d.ts +3 -0
- package/dist/types/src/containers/TriggerSettings/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +5 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +5 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeRuntime.d.ts +8 -0
- package/dist/types/src/hooks/useComputeRuntime.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts +9 -0
- package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeRuntimeService.d.ts +17 -0
- package/dist/types/src/hooks/useComputeRuntimeService.d.ts.map +1 -0
- package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts +12 -0
- package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/create-trigger-from-template.d.ts +5 -0
- package/dist/types/src/operations/create-trigger-from-template.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/plugin.d.ts +4 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/testing/test-functions.d.ts +204 -3
- package/dist/types/src/testing/test-functions.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +32 -26
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/AutomationCapabilities.d.ts +22 -0
- package/dist/types/src/types/AutomationCapabilities.d.ts.map +1 -0
- package/dist/types/src/types/AutomationEvents.d.ts +3 -0
- package/dist/types/src/types/AutomationEvents.d.ts.map +1 -0
- package/dist/types/src/types/AutomationOperation.d.ts +19 -0
- package/dist/types/src/types/AutomationOperation.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +3 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +12 -4
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +138 -50
- package/src/AutomationPlugin.node.ts +29 -0
- package/src/AutomationPlugin.test.ts +27 -0
- package/src/AutomationPlugin.tsx +23 -34
- package/src/capabilities/app-graph-builder.ts +59 -79
- package/src/capabilities/compute-runtime.ts +325 -0
- package/src/capabilities/index.ts +9 -4
- package/src/capabilities/node.ts +13 -0
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/react-surface.tsx +49 -46
- package/src/commands/index.ts +5 -0
- package/src/commands/trigger/create/index.ts +14 -0
- package/src/commands/trigger/create/queue.ts +86 -0
- package/src/commands/trigger/create/subscription.ts +125 -0
- package/src/commands/trigger/create/timer.ts +90 -0
- package/src/commands/trigger/index.ts +16 -0
- package/src/commands/trigger/list.ts +70 -0
- package/src/commands/trigger/options.ts +59 -0
- package/src/commands/trigger/remove.ts +45 -0
- package/src/commands/trigger/update/index.ts +14 -0
- package/src/commands/trigger/update/queue.ts +194 -0
- package/src/commands/trigger/update/subscription.ts +278 -0
- package/src/commands/trigger/update/timer.ts +193 -0
- package/src/commands/trigger/util.ts +410 -0
- package/src/components/AutomationPanel/AutomationPanel.stories.tsx +9 -12
- package/src/components/AutomationPanel/AutomationPanel.tsx +250 -82
- package/src/components/FunctionsPanel/FunctionsPanel.tsx +51 -32
- package/src/components/FunctionsRegistry/FunctionsRegistry.tsx +114 -0
- package/src/components/FunctionsRegistry/index.ts +8 -0
- package/src/components/TriggerEditor/FunctionInputEditor.tsx +42 -35
- package/src/components/TriggerEditor/SpecSelector.tsx +29 -17
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +117 -32
- package/src/components/TriggerEditor/TriggerEditor.tsx +109 -42
- package/src/components/index.ts +1 -2
- package/src/containers/AutomationSettings/AutomationSettings.tsx +31 -0
- package/src/containers/AutomationSettings/index.ts +5 -0
- package/src/containers/FunctionsContainer/FunctionsContainer.tsx +33 -0
- package/src/containers/FunctionsContainer/index.ts +5 -0
- package/src/containers/TriggerSettings/TriggerSettings.tsx +48 -0
- package/src/containers/TriggerSettings/index.ts +6 -0
- package/src/containers/index.ts +9 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/useComputeRuntime.ts +30 -0
- package/src/hooks/useComputeRuntimeCallback.ts +32 -0
- package/src/hooks/useComputeRuntimeService.ts +64 -0
- package/src/hooks/useTriggerRuntimeControls.ts +70 -0
- package/src/index.ts +1 -3
- package/src/meta.ts +10 -8
- package/src/operations/create-trigger-from-template.ts +72 -0
- package/src/operations/index.ts +7 -0
- package/src/plugin.ts +11 -0
- package/src/testing/test-functions.ts +13 -10
- package/src/translations.ts +39 -29
- package/src/types/AutomationCapabilities.ts +48 -0
- package/src/types/AutomationEvents.ts +11 -0
- package/src/types/AutomationOperation.ts +30 -0
- package/src/types/index.ts +4 -0
- package/src/types/schema.ts +6 -6
- package/dist/lib/browser/AutomationContainer-BRV5AJZ3.mjs +0 -35
- package/dist/lib/browser/AutomationContainer-BRV5AJZ3.mjs.map +0 -7
- package/dist/lib/browser/AutomationPanel-N5HFJJXW.mjs +0 -11
- package/dist/lib/browser/FunctionsContainer-U4HASI4P.mjs +0 -36
- package/dist/lib/browser/FunctionsContainer-U4HASI4P.mjs.map +0 -7
- package/dist/lib/browser/FunctionsPanel-I443Y6KB.mjs +0 -10
- package/dist/lib/browser/app-graph-builder-4OFKIRAI.mjs +0 -80
- package/dist/lib/browser/app-graph-builder-4OFKIRAI.mjs.map +0 -7
- package/dist/lib/browser/chunk-4TWQV33E.mjs +0 -143
- package/dist/lib/browser/chunk-4TWQV33E.mjs.map +0 -7
- package/dist/lib/browser/chunk-EIY2EUWC.mjs +0 -14
- package/dist/lib/browser/chunk-EIY2EUWC.mjs.map +0 -7
- package/dist/lib/browser/chunk-GW5U2DGT.mjs +0 -15
- package/dist/lib/browser/chunk-GW5U2DGT.mjs.map +0 -7
- package/dist/lib/browser/chunk-HN7OHFCB.mjs +0 -38
- package/dist/lib/browser/chunk-HN7OHFCB.mjs.map +0 -7
- package/dist/lib/browser/chunk-S4SM663I.mjs +0 -230
- package/dist/lib/browser/chunk-S4SM663I.mjs.map +0 -7
- package/dist/lib/browser/chunk-Z5DT4MHW.mjs +0 -94
- package/dist/lib/browser/chunk-Z5DT4MHW.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -101
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-4PSYSQQG.mjs +0 -77
- package/dist/lib/browser/intent-resolver-4PSYSQQG.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-M52XGLXY.mjs +0 -64
- package/dist/lib/browser/react-surface-M52XGLXY.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -8
- package/dist/lib/node-esm/AutomationContainer-FYRDTERM.mjs +0 -36
- package/dist/lib/node-esm/AutomationContainer-FYRDTERM.mjs.map +0 -7
- package/dist/lib/node-esm/AutomationPanel-MKOLA2FE.mjs +0 -12
- package/dist/lib/node-esm/FunctionsContainer-VZIVURH6.mjs +0 -37
- package/dist/lib/node-esm/FunctionsContainer-VZIVURH6.mjs.map +0 -7
- package/dist/lib/node-esm/FunctionsPanel-ELINCXPW.mjs +0 -11
- package/dist/lib/node-esm/app-graph-builder-555IHYOB.mjs +0 -81
- package/dist/lib/node-esm/app-graph-builder-555IHYOB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AONUBWBE.mjs +0 -144
- package/dist/lib/node-esm/chunk-AONUBWBE.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CICQ73ZT.mjs +0 -16
- package/dist/lib/node-esm/chunk-CICQ73ZT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CX2AILIS.mjs +0 -95
- package/dist/lib/node-esm/chunk-CX2AILIS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NK5N3QKD.mjs +0 -17
- package/dist/lib/node-esm/chunk-NK5N3QKD.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OEZNHUL2.mjs +0 -39
- package/dist/lib/node-esm/chunk-OEZNHUL2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZOJVKPCA.mjs +0 -231
- package/dist/lib/node-esm/chunk-ZOJVKPCA.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -102
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-6ZGBUILG.mjs +0 -78
- package/dist/lib/node-esm/intent-resolver-6ZGBUILG.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/react-surface-Y6AOXM75.mjs +0 -65
- package/dist/lib/node-esm/react-surface-Y6AOXM75.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -9
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/components/AutomationContainer.d.ts +0 -5
- package/dist/types/src/components/AutomationContainer.d.ts.map +0 -1
- package/dist/types/src/components/FunctionsContainer.d.ts +0 -7
- package/dist/types/src/components/FunctionsContainer.d.ts.map +0 -1
- package/src/capabilities/intent-resolver.ts +0 -72
- package/src/components/AutomationContainer.tsx +0 -28
- package/src/components/FunctionsContainer.tsx +0 -29
- /package/dist/lib/{browser/AutomationPanel-N5HFJJXW.mjs.map → neutral/AutomationPanel-64U7W3SJ.mjs.map} +0 -0
- /package/dist/lib/{browser/FunctionsPanel-I443Y6KB.mjs.map → neutral/TriggerSettings-XCHIZPOR.mjs.map} +0 -0
- /package/dist/lib/{browser/types/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
- /package/dist/lib/{node-esm/types → neutral/components}/index.mjs.map +0 -0
- /package/dist/lib/{node-esm/AutomationPanel-MKOLA2FE.mjs.map → neutral/index.mjs.map} +0 -0
- /package/dist/lib/{node-esm/FunctionsPanel-ELINCXPW.mjs.map → neutral/meta.mjs.map} +0 -0
|
@@ -2,52 +2,77 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
5
|
+
import * as Array from 'effect/Array';
|
|
6
|
+
import * as EFn from 'effect/Function';
|
|
7
|
+
import * as Match from 'effect/Match';
|
|
8
|
+
import * as Schema from 'effect/Schema';
|
|
9
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
7
10
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
11
|
+
import { useTypeOptions } from '@dxos/app-toolkit/ui';
|
|
12
|
+
import { Script, Trigger } from '@dxos/compute';
|
|
13
|
+
import { Operation } from '@dxos/compute';
|
|
14
|
+
import { Context } from '@dxos/context';
|
|
15
|
+
import { Filter, Obj, Query, Tag } from '@dxos/echo';
|
|
16
|
+
import { KEY_QUEUE_CURSOR } from '@dxos/functions-runtime';
|
|
17
|
+
import { FunctionsServiceClient } from '@dxos/functions-runtime/edge';
|
|
10
18
|
import { type Client, useClient } from '@dxos/react-client';
|
|
11
|
-
import { type Space,
|
|
12
|
-
import { Clipboard, IconButton, Input, Separator,
|
|
13
|
-
import {
|
|
19
|
+
import { type Space, useObject, useQuery } from '@dxos/react-client/echo';
|
|
20
|
+
import { Clipboard, IconButton, type IconButtonProps, Input, Separator, useTranslation } from '@dxos/react-ui';
|
|
21
|
+
import { Settings } from '@dxos/react-ui-form';
|
|
14
22
|
import { List } from '@dxos/react-ui-list';
|
|
15
|
-
import {
|
|
23
|
+
import { Pipeline } from '@dxos/types';
|
|
24
|
+
import { ghostHover, mx } from '@dxos/ui-theme';
|
|
25
|
+
import { isNonNullable } from '@dxos/util';
|
|
26
|
+
|
|
27
|
+
import { meta } from '#meta';
|
|
16
28
|
|
|
17
|
-
import { AUTOMATION_PLUGIN } from '../../meta';
|
|
18
29
|
import { TriggerEditor, type TriggerEditorProps } from '../TriggerEditor';
|
|
19
30
|
|
|
20
|
-
const grid = 'grid grid-cols-[
|
|
31
|
+
const grid = 'grid grid-cols-[40px_1fr_32px_32px] min-h-[2.5rem]';
|
|
21
32
|
|
|
22
|
-
export type AutomationPanelProps =
|
|
33
|
+
export type AutomationPanelProps = {
|
|
23
34
|
space: Space;
|
|
24
|
-
object?: Obj.
|
|
25
|
-
initialTrigger?:
|
|
35
|
+
object?: Obj.Unknown;
|
|
36
|
+
initialTrigger?: Trigger.Trigger;
|
|
26
37
|
onDone?: () => void;
|
|
27
|
-
}
|
|
38
|
+
};
|
|
28
39
|
|
|
29
40
|
// TODO(burdon): Factor out common layout with ViewEditor.
|
|
30
|
-
export const AutomationPanel = ({
|
|
31
|
-
const { t } = useTranslation(
|
|
41
|
+
export const AutomationPanel = ({ space, object, initialTrigger, onDone }: AutomationPanelProps) => {
|
|
42
|
+
const { t } = useTranslation(meta.id);
|
|
32
43
|
const client = useClient();
|
|
33
|
-
const
|
|
34
|
-
const functions = useQuery(space, Filter.type(
|
|
35
|
-
const
|
|
44
|
+
const functionsServiceClient = useMemo(() => FunctionsServiceClient.fromClient(client), [client]);
|
|
45
|
+
const functions = useQuery(space.db, Filter.type(Operation.PersistentOperation));
|
|
46
|
+
const triggers = useQuery(
|
|
47
|
+
space.db,
|
|
48
|
+
Query.select(Filter.type(Trigger.Trigger)).debugLabel('plugin-automation.AutomationPanel'),
|
|
49
|
+
);
|
|
50
|
+
const filteredTriggers = useMemo(() => {
|
|
51
|
+
return object ? triggers.filter(triggerMatch(object)) : triggers;
|
|
52
|
+
}, [object, triggers]);
|
|
53
|
+
const tags = useQuery(space.db, Filter.type(Tag.Tag));
|
|
54
|
+
const types = useTypeOptions({
|
|
55
|
+
space,
|
|
56
|
+
annotation: {
|
|
57
|
+
location: ['database', 'runtime'],
|
|
58
|
+
kind: ['user'],
|
|
59
|
+
},
|
|
60
|
+
});
|
|
36
61
|
|
|
37
|
-
const [trigger, setTrigger] = useState<
|
|
38
|
-
const [selected, setSelected] = useState<
|
|
62
|
+
const [trigger, setTrigger] = useState<Trigger.Trigger | undefined>(initialTrigger);
|
|
63
|
+
const [selected, setSelected] = useState<Trigger.Trigger>();
|
|
39
64
|
|
|
40
|
-
const handleSelect = (trigger:
|
|
65
|
+
const handleSelect = (trigger: Trigger.Trigger) => {
|
|
41
66
|
setTrigger(trigger);
|
|
42
67
|
setSelected(trigger);
|
|
43
68
|
};
|
|
44
69
|
|
|
45
70
|
const handleAdd = () => {
|
|
46
|
-
setTrigger(
|
|
71
|
+
setTrigger(Trigger.make({}));
|
|
47
72
|
setSelected(undefined);
|
|
48
73
|
};
|
|
49
74
|
|
|
50
|
-
const handleDelete = (trigger:
|
|
75
|
+
const handleDelete = (trigger: Trigger.Trigger) => {
|
|
51
76
|
space.db.remove(trigger);
|
|
52
77
|
setTrigger(undefined);
|
|
53
78
|
setSelected(undefined);
|
|
@@ -55,9 +80,11 @@ export const AutomationPanel = ({ classNames, space, object, initialTrigger, onD
|
|
|
55
80
|
|
|
56
81
|
const handleSave: TriggerEditorProps['onSave'] = (trigger) => {
|
|
57
82
|
if (selected) {
|
|
58
|
-
|
|
83
|
+
Obj.update(selected, (selected) => {
|
|
84
|
+
Object.assign(selected, trigger);
|
|
85
|
+
});
|
|
59
86
|
} else {
|
|
60
|
-
space.db.add(
|
|
87
|
+
space.db.add(Trigger.make(trigger));
|
|
61
88
|
}
|
|
62
89
|
|
|
63
90
|
setTrigger(undefined);
|
|
@@ -70,90 +97,231 @@ export const AutomationPanel = ({ classNames, space, object, initialTrigger, onD
|
|
|
70
97
|
onDone?.();
|
|
71
98
|
};
|
|
72
99
|
|
|
100
|
+
const handleForceRunTrigger = async (trigger: Trigger.Trigger) => {
|
|
101
|
+
await functionsServiceClient.forceRunCronTrigger(Context.default(), space.id, trigger.id);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const handleResetCursor = async (trigger: Trigger.Trigger) => {
|
|
105
|
+
Obj.update(trigger, (trigger) => {
|
|
106
|
+
Obj.deleteKeys(trigger, KEY_QUEUE_CURSOR);
|
|
107
|
+
});
|
|
108
|
+
await space.db.flush({ indexes: true });
|
|
109
|
+
};
|
|
110
|
+
|
|
73
111
|
if (trigger) {
|
|
74
112
|
return (
|
|
75
|
-
<
|
|
76
|
-
<TriggerEditor
|
|
77
|
-
|
|
113
|
+
<Settings.Item title={t('trigger-editor.title')} description={t('trigger-editor.description')}>
|
|
114
|
+
<TriggerEditor
|
|
115
|
+
db={space.db}
|
|
116
|
+
trigger={trigger}
|
|
117
|
+
readonlySpec={Boolean(object)}
|
|
118
|
+
tags={tags}
|
|
119
|
+
types={types}
|
|
120
|
+
onSave={handleSave}
|
|
121
|
+
onCancel={handleCancel}
|
|
122
|
+
/>
|
|
123
|
+
</Settings.Item>
|
|
78
124
|
);
|
|
79
125
|
}
|
|
80
126
|
|
|
81
127
|
return (
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
128
|
+
<Settings.Panel>
|
|
129
|
+
<Clipboard.Provider>
|
|
130
|
+
{filteredTriggers.length > 0 && (
|
|
131
|
+
<List.Root<Trigger.Trigger>
|
|
132
|
+
items={filteredTriggers}
|
|
133
|
+
isItem={Schema.is(Trigger.Trigger)}
|
|
134
|
+
getId={(field) => field.id}
|
|
135
|
+
>
|
|
136
|
+
{({ items: filteredTriggers }) => (
|
|
137
|
+
<div role='list' className='flex flex-col w-full'>
|
|
138
|
+
{filteredTriggers?.map((trigger) => (
|
|
139
|
+
<TriggerListItem
|
|
91
140
|
key={trigger.id}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
141
|
+
trigger={trigger}
|
|
142
|
+
functions={functions}
|
|
143
|
+
onSelect={handleSelect}
|
|
144
|
+
onDelete={handleDelete}
|
|
145
|
+
onResetCursor={handleResetCursor}
|
|
146
|
+
onForceRun={handleForceRunTrigger}
|
|
147
|
+
/>
|
|
148
|
+
))}
|
|
149
|
+
</div>
|
|
150
|
+
)}
|
|
151
|
+
</List.Root>
|
|
152
|
+
)}
|
|
153
|
+
|
|
154
|
+
{filteredTriggers.length > 0 && <Separator classNames='my-4' />}
|
|
155
|
+
<IconButton icon='ph--plus--regular' label={t('new-trigger.label')} onClick={handleAdd} />
|
|
156
|
+
</Clipboard.Provider>
|
|
157
|
+
</Settings.Panel>
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const TriggerListItem = ({
|
|
162
|
+
trigger,
|
|
163
|
+
functions,
|
|
164
|
+
onSelect,
|
|
165
|
+
onDelete,
|
|
166
|
+
onResetCursor,
|
|
167
|
+
onForceRun,
|
|
168
|
+
}: {
|
|
169
|
+
trigger: Trigger.Trigger;
|
|
170
|
+
functions: Operation.PersistentOperation[];
|
|
171
|
+
onSelect?: (trigger: Trigger.Trigger) => void;
|
|
172
|
+
onDelete?: (trigger: Trigger.Trigger) => void;
|
|
173
|
+
onResetCursor?: (trigger: Trigger.Trigger) => void;
|
|
174
|
+
onForceRun?: (trigger: Trigger.Trigger) => void;
|
|
175
|
+
}) => {
|
|
176
|
+
const client = useClient();
|
|
177
|
+
const copyAction = getCopyAction(client, trigger);
|
|
178
|
+
const { t } = useTranslation(meta.id);
|
|
179
|
+
const cursor = Obj.getKeys(trigger, KEY_QUEUE_CURSOR).at(0)?.id;
|
|
180
|
+
const [snapshot, updateTrigger] = useObject(trigger);
|
|
181
|
+
|
|
182
|
+
const enabled = snapshot.enabled ?? false;
|
|
183
|
+
const onEnabledChange = (checked: boolean) => {
|
|
184
|
+
updateTrigger((trigger) => {
|
|
185
|
+
trigger.enabled = checked;
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const handleSelect = useCallback(() => {
|
|
190
|
+
onSelect?.(trigger);
|
|
191
|
+
}, [onSelect, trigger]);
|
|
192
|
+
|
|
193
|
+
const handleDelete = useCallback(() => {
|
|
194
|
+
onDelete?.(trigger);
|
|
195
|
+
}, [onDelete, trigger]);
|
|
196
|
+
|
|
197
|
+
const handleResetCursor = useCallback(() => {
|
|
198
|
+
onResetCursor?.(trigger);
|
|
199
|
+
}, [onResetCursor, trigger]);
|
|
200
|
+
|
|
201
|
+
const handleForceRun = useCallback(() => {
|
|
202
|
+
onForceRun?.(trigger);
|
|
203
|
+
}, [onForceRun, trigger]);
|
|
204
|
+
|
|
205
|
+
const actionProps = useMemo<IconButtonProps | undefined>(() => {
|
|
206
|
+
if (trigger.spec?.kind === 'timer' && onForceRun) {
|
|
207
|
+
return {
|
|
208
|
+
disabled: !enabled || trigger.spec?.kind !== 'timer',
|
|
209
|
+
icon: 'ph--play--regular',
|
|
210
|
+
label: 'Force run',
|
|
211
|
+
onClick: handleForceRun,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (trigger.spec?.kind === 'queue' && onResetCursor) {
|
|
216
|
+
return {
|
|
217
|
+
disabled: !cursor,
|
|
218
|
+
icon: 'ph--arrow-clockwise--regular',
|
|
219
|
+
label: 'Reset cursor',
|
|
220
|
+
onClick: handleResetCursor,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}, [enabled, trigger.spec?.kind, handleForceRun]);
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<List.Item<Obj.Snapshot<Trigger.Trigger>>
|
|
227
|
+
key={trigger.id}
|
|
228
|
+
item={snapshot}
|
|
229
|
+
classNames={mx(grid, ghostHover, 'items-center', 'px-2')}
|
|
230
|
+
>
|
|
231
|
+
<Input.Root>
|
|
232
|
+
<Input.Switch checked={enabled} onCheckedChange={onEnabledChange} />
|
|
233
|
+
</Input.Root>
|
|
234
|
+
|
|
235
|
+
<div className={'flex'}>
|
|
236
|
+
<List.ItemTitle classNames='px-1 cursor-pointer w-0 shrink truncate' onClick={handleSelect}>
|
|
237
|
+
{getFunctionName(functions, trigger) ?? '∅'}
|
|
238
|
+
{cursor && <div className='text-xs text-description truncate ml-4'>Position: {cursor}</div>}
|
|
239
|
+
</List.ItemTitle>
|
|
240
|
+
|
|
241
|
+
{copyAction && (
|
|
242
|
+
<Clipboard.IconButton label={t(copyAction.translationKey)} value={copyAction.contentProvider()} />
|
|
243
|
+
)}
|
|
244
|
+
</div>
|
|
245
|
+
|
|
246
|
+
{actionProps ? <List.ItemIconButton {...actionProps} autoHide={false} /> : <div />}
|
|
247
|
+
|
|
248
|
+
{onDelete && <List.ItemDeleteButton onClick={handleDelete} />}
|
|
249
|
+
</List.Item>
|
|
130
250
|
);
|
|
131
251
|
};
|
|
132
252
|
|
|
133
|
-
const getCopyAction = (client: Client, trigger:
|
|
253
|
+
const getCopyAction = (client: Client, trigger: Trigger.Trigger | undefined) => {
|
|
134
254
|
if (trigger?.spec?.kind === 'email') {
|
|
135
|
-
return {
|
|
255
|
+
return {
|
|
256
|
+
translationKey: 'trigger copy email' as const,
|
|
257
|
+
contentProvider: () => `${Obj.getDatabase(trigger)!.spaceId}@dxos.network`,
|
|
258
|
+
};
|
|
136
259
|
}
|
|
137
260
|
|
|
138
261
|
if (trigger?.spec?.kind === 'webhook') {
|
|
139
|
-
return {
|
|
262
|
+
return {
|
|
263
|
+
translationKey: 'trigger copy url' as const,
|
|
264
|
+
contentProvider: () => getWebhookUrl(client, trigger!),
|
|
265
|
+
};
|
|
140
266
|
}
|
|
141
267
|
|
|
142
268
|
return undefined;
|
|
143
269
|
};
|
|
144
270
|
|
|
145
|
-
const getWebhookUrl = (client: Client, trigger:
|
|
146
|
-
const spaceId =
|
|
271
|
+
const getWebhookUrl = (client: Client, trigger: Trigger.Trigger) => {
|
|
272
|
+
const spaceId = Obj.getDatabase(trigger)!.spaceId;
|
|
147
273
|
const edgeUrl = new URL(client.config.values.runtime!.services!.edge!.url!);
|
|
148
274
|
const isSecure = edgeUrl.protocol.startsWith('https') || edgeUrl.protocol.startsWith('wss');
|
|
149
275
|
edgeUrl.protocol = isSecure ? 'https' : 'http';
|
|
150
276
|
return new URL(`/webhook/${spaceId}:${trigger.id}`, edgeUrl).toString();
|
|
151
277
|
};
|
|
152
278
|
|
|
153
|
-
const getFunctionName = (
|
|
279
|
+
const getFunctionName = (functions: Operation.PersistentOperation[], trigger: Trigger.Trigger) => {
|
|
154
280
|
// TODO(wittjosiah): Truncation should be done in the UI.
|
|
155
281
|
// Warning that the List component is currently a can of worms.
|
|
156
282
|
const shortId = trigger.function && `${trigger.function.dxn.toString().slice(0, 16)}…`;
|
|
157
283
|
const functionObject = functions.find((fn) => fn === trigger.function?.target);
|
|
158
284
|
return functionObject?.name ?? shortId;
|
|
159
285
|
};
|
|
286
|
+
|
|
287
|
+
const scriptMatch = (script: Script.Script) => (trigger: Trigger.Trigger) => {
|
|
288
|
+
const fn = trigger.function?.target;
|
|
289
|
+
if (!Obj.instanceOf(Operation.PersistentOperation, fn)) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return fn.source?.target === script;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const projectMatch = (project: Pipeline.Pipeline) => {
|
|
297
|
+
const viewQueries = EFn.pipe(
|
|
298
|
+
project.columns,
|
|
299
|
+
Array.map((column) => column.view.target),
|
|
300
|
+
Array.filter(isNonNullable),
|
|
301
|
+
Array.map((view) => Obj.getSnapshot(view).query.ast),
|
|
302
|
+
Array.map((ast) => JSON.stringify(ast)),
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
return (trigger: Trigger.Trigger) => {
|
|
306
|
+
const spec = Obj.getSnapshot(trigger).spec;
|
|
307
|
+
if (spec?.kind !== 'subscription') {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// TODO(wittjosiah): Implement better way of comparing query ASTs.
|
|
312
|
+
return viewQueries.some((query) => JSON.stringify(spec.query) === query);
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const triggerMatch = Match.type<Obj.Unknown>().pipe(
|
|
317
|
+
Match.withReturnType<(trigger: Trigger.Trigger) => boolean>(),
|
|
318
|
+
Match.when(
|
|
319
|
+
(obj) => Obj.instanceOf(Script.Script, obj),
|
|
320
|
+
(obj) => scriptMatch(obj),
|
|
321
|
+
),
|
|
322
|
+
Match.when(
|
|
323
|
+
(obj) => Obj.instanceOf(Pipeline.Pipeline, obj),
|
|
324
|
+
(obj) => projectMatch(obj),
|
|
325
|
+
),
|
|
326
|
+
Match.orElse((_obj) => () => true),
|
|
327
|
+
);
|
|
@@ -2,30 +2,30 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
import React, { useCallback, useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { useOperationInvoker } from '@dxos/app-framework/ui';
|
|
9
|
+
import { LayoutOperation, getObjectPathFromObject } from '@dxos/app-toolkit';
|
|
10
|
+
import { Operation, Script } from '@dxos/compute';
|
|
11
|
+
import { SpaceOperation } from '@dxos/plugin-space';
|
|
12
|
+
import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
|
|
13
|
+
import { IconButton, useTranslation } from '@dxos/react-ui';
|
|
14
|
+
import { Settings } from '@dxos/react-ui-form';
|
|
13
15
|
import { List } from '@dxos/react-ui-list';
|
|
14
|
-
import { ghostHover, mx } from '@dxos/
|
|
16
|
+
import { ghostHover, mx } from '@dxos/ui-theme';
|
|
15
17
|
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
const grid = 'grid grid-cols-[1fr_auto] min-bs-[2.5rem]';
|
|
18
|
+
import { meta } from '#meta';
|
|
19
19
|
|
|
20
20
|
export type FunctionsPanelProps = {
|
|
21
21
|
space: Space;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
25
|
-
const { t } = useTranslation(
|
|
26
|
-
const functions = useQuery(space, Filter.type(
|
|
27
|
-
const scripts = useQuery(space, Filter.type(
|
|
28
|
-
const {
|
|
25
|
+
const { t } = useTranslation(meta.id);
|
|
26
|
+
const functions = useQuery(space.db, Filter.type(Operation.PersistentOperation));
|
|
27
|
+
const scripts = useQuery(space.db, Filter.type(Script.Script));
|
|
28
|
+
const { invokePromise } = useOperationInvoker();
|
|
29
29
|
|
|
30
30
|
const functionToScriptMap = useMemo(
|
|
31
31
|
() =>
|
|
@@ -40,13 +40,13 @@ export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
|
40
40
|
}
|
|
41
41
|
return map;
|
|
42
42
|
},
|
|
43
|
-
{} as Record<string,
|
|
43
|
+
{} as Record<string, Script.Script>,
|
|
44
44
|
),
|
|
45
45
|
[functions, scripts],
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
const getScriptName = useCallback(
|
|
49
|
-
(func:
|
|
49
|
+
(func: Operation.PersistentOperation) => {
|
|
50
50
|
const script = functionToScriptMap[func.id];
|
|
51
51
|
return script?.name;
|
|
52
52
|
},
|
|
@@ -54,44 +54,63 @@ export const FunctionsPanel = ({ space }: FunctionsPanelProps) => {
|
|
|
54
54
|
);
|
|
55
55
|
|
|
56
56
|
const handleGoToScript = useCallback(
|
|
57
|
-
(func:
|
|
57
|
+
(func: Operation.PersistentOperation) => {
|
|
58
58
|
const script = functionToScriptMap[func.id];
|
|
59
59
|
if (script) {
|
|
60
|
-
void
|
|
60
|
+
void invokePromise(LayoutOperation.Open, { subject: [getObjectPathFromObject(script)] });
|
|
61
61
|
}
|
|
62
62
|
},
|
|
63
|
-
[functionToScriptMap,
|
|
63
|
+
[functionToScriptMap, invokePromise],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const handleDelete = useCallback(
|
|
67
|
+
(func: Operation.PersistentOperation) => invokePromise(SpaceOperation.RemoveObjects, { objects: [func] }),
|
|
68
|
+
[invokePromise],
|
|
64
69
|
);
|
|
65
70
|
|
|
66
71
|
return (
|
|
67
|
-
<
|
|
72
|
+
<Settings.Panel>
|
|
68
73
|
{functions.length > 0 && (
|
|
69
|
-
<List.Root<
|
|
74
|
+
<List.Root<Operation.PersistentOperation>
|
|
75
|
+
items={functions}
|
|
76
|
+
isItem={Schema.is(Operation.PersistentOperation)}
|
|
77
|
+
getId={(func) => func.id}
|
|
78
|
+
>
|
|
70
79
|
{({ items }) => (
|
|
71
80
|
<div role='list' className='flex flex-col w-full'>
|
|
72
81
|
{items?.map((func) => (
|
|
73
|
-
<List.Item<
|
|
82
|
+
<List.Item<Operation.PersistentOperation>
|
|
74
83
|
key={func.id}
|
|
75
84
|
item={func}
|
|
76
|
-
classNames={mx(
|
|
85
|
+
classNames={mx(
|
|
86
|
+
'grid grid-cols-[1fr_min-content_auto] min-h-[2.5rem] min-h-[3rem] px-2 items-center',
|
|
87
|
+
ghostHover,
|
|
88
|
+
)}
|
|
77
89
|
>
|
|
78
90
|
<div className='flex flex-col truncate'>
|
|
79
91
|
<List.ItemTitle classNames='truncate'>{func.name}</List.ItemTitle>
|
|
80
|
-
{getScriptName(func) && (
|
|
81
|
-
<div className='text-xs text-description truncate'>{getScriptName(func)}</div>
|
|
82
|
-
)}
|
|
92
|
+
{getScriptName(func) && <p className='text-xs text-description truncate'>{getScriptName(func)}</p>}
|
|
83
93
|
</div>
|
|
84
|
-
{functionToScriptMap[func.id] && (
|
|
85
|
-
<
|
|
86
|
-
|
|
94
|
+
{(functionToScriptMap[func.id] && (
|
|
95
|
+
<IconButton
|
|
96
|
+
icon='ph--arrow-square-out--regular'
|
|
97
|
+
iconOnly
|
|
98
|
+
label={t('show-source-button.label')}
|
|
99
|
+
onClick={() => handleGoToScript(func)}
|
|
100
|
+
/>
|
|
101
|
+
)) || <div />}
|
|
102
|
+
<IconButton
|
|
103
|
+
icon='ph--trash--regular'
|
|
104
|
+
iconOnly
|
|
105
|
+
label={t('delete-function-button.label')}
|
|
106
|
+
onClick={() => handleDelete(func)}
|
|
107
|
+
/>
|
|
87
108
|
</List.Item>
|
|
88
109
|
))}
|
|
89
110
|
</div>
|
|
90
111
|
)}
|
|
91
112
|
</List.Root>
|
|
92
113
|
)}
|
|
93
|
-
|
|
94
|
-
{functions.length === 0 && <div className='text-center plb-4 text-gray-500'>{t('no functions found')}</div>}
|
|
95
|
-
</div>
|
|
114
|
+
</Settings.Panel>
|
|
96
115
|
);
|
|
97
116
|
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
import React, { useCallback } from 'react';
|
|
8
|
+
|
|
9
|
+
import * as OperationModule from '@dxos/compute';
|
|
10
|
+
import { Context } from '@dxos/context';
|
|
11
|
+
import { getDeployedFunctions } from '@dxos/functions-runtime/edge';
|
|
12
|
+
import { useClient } from '@dxos/react-client';
|
|
13
|
+
import { Filter, Query, type Space, useQuery } from '@dxos/react-client/echo';
|
|
14
|
+
import { IconButton, useAsyncEffect, useTranslation } from '@dxos/react-ui';
|
|
15
|
+
import { Settings } from '@dxos/react-ui-form';
|
|
16
|
+
import { List } from '@dxos/react-ui-list';
|
|
17
|
+
import { ghostHover, mx } from '@dxos/ui-theme';
|
|
18
|
+
|
|
19
|
+
import { meta } from '#meta';
|
|
20
|
+
|
|
21
|
+
const grid = 'grid grid-cols-[1fr_1fr_auto] min-h-[2.5rem]';
|
|
22
|
+
|
|
23
|
+
type FunctionsRegistryProps = {
|
|
24
|
+
space: Space;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const FunctionsRegistry = ({ space }: FunctionsRegistryProps) => {
|
|
28
|
+
const client = useClient();
|
|
29
|
+
const [loading, setLoading] = useState(true);
|
|
30
|
+
const [functions, setFunctions] = useState<OperationModule.Operation.PersistentOperation[]>([]);
|
|
31
|
+
const { t } = useTranslation(meta.id);
|
|
32
|
+
|
|
33
|
+
const dbFunctions = useQuery(space.db, Filter.type(OperationModule.Operation.PersistentOperation));
|
|
34
|
+
|
|
35
|
+
const state = (func: OperationModule.Operation.PersistentOperation) => {
|
|
36
|
+
const dbFunction = dbFunctions.find((f) => f.key === func.key);
|
|
37
|
+
if (!dbFunction) {
|
|
38
|
+
return 'import';
|
|
39
|
+
}
|
|
40
|
+
if (dbFunction.version === func.version && dbFunction.updated === func.updated) {
|
|
41
|
+
return 'none';
|
|
42
|
+
}
|
|
43
|
+
return 'update';
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
useAsyncEffect(async () => {
|
|
47
|
+
setLoading(true);
|
|
48
|
+
const functions = await getDeployedFunctions(Context.default(), client, true);
|
|
49
|
+
setFunctions(functions);
|
|
50
|
+
setLoading(false);
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
const hanleImportOrUpdate = useCallback(
|
|
54
|
+
async (func: OperationModule.Operation.PersistentOperation) => {
|
|
55
|
+
const functions = await space.db
|
|
56
|
+
.query(Query.type(OperationModule.Operation.PersistentOperation, { key: func.key }))
|
|
57
|
+
.run();
|
|
58
|
+
const [existingFunc] = functions;
|
|
59
|
+
if (!existingFunc) {
|
|
60
|
+
space.db.add(func);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
OperationModule.Operation.setFrom(existingFunc, func);
|
|
64
|
+
},
|
|
65
|
+
[space],
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Settings.Panel>
|
|
70
|
+
{functions.length > 0 && (
|
|
71
|
+
<List.Root<OperationModule.Operation.PersistentOperation>
|
|
72
|
+
items={functions}
|
|
73
|
+
isItem={Schema.is(OperationModule.Operation.PersistentOperation)}
|
|
74
|
+
getId={(func) => func.id}
|
|
75
|
+
>
|
|
76
|
+
{({ items }) => (
|
|
77
|
+
<div role='list' className='flex flex-col w-full'>
|
|
78
|
+
{items?.map((func) => (
|
|
79
|
+
<List.Item<OperationModule.Operation.PersistentOperation>
|
|
80
|
+
key={func.id}
|
|
81
|
+
item={func}
|
|
82
|
+
classNames={mx(grid, ghostHover, 'items-center', 'px-2', 'min-h-[3rem]')}
|
|
83
|
+
>
|
|
84
|
+
<div className='flex flex-col truncate'>
|
|
85
|
+
<List.ItemTitle classNames='truncate'>{func.name}</List.ItemTitle>
|
|
86
|
+
<div className='text-xs text-description truncate'>{func.key}</div>
|
|
87
|
+
</div>
|
|
88
|
+
<div className='flex flex-col truncate'>
|
|
89
|
+
<div className='text-xs text-description truncate'>{func.version}</div>
|
|
90
|
+
<div className='text-xs text-description truncate'>
|
|
91
|
+
{func.updated ? `Uploaded ${new Date(func.updated).toLocaleString()}` : ''}
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<IconButton
|
|
96
|
+
iconOnly
|
|
97
|
+
icon={state(func) === 'update' ? 'ph--arrows-clockwise--regular' : 'ph--download--regular'}
|
|
98
|
+
label={
|
|
99
|
+
state(func) === 'update' ? t('update-function-button.label') : t('import-function-button.label')
|
|
100
|
+
}
|
|
101
|
+
disabled={state(func) === 'none'}
|
|
102
|
+
onClick={() => hanleImportOrUpdate(func)}
|
|
103
|
+
/>
|
|
104
|
+
</List.Item>
|
|
105
|
+
))}
|
|
106
|
+
</div>
|
|
107
|
+
)}
|
|
108
|
+
</List.Root>
|
|
109
|
+
)}
|
|
110
|
+
|
|
111
|
+
{loading && <div className='text-center py-4 text-gray-500'>{t('loading-functions.message')}</div>}
|
|
112
|
+
</Settings.Panel>
|
|
113
|
+
);
|
|
114
|
+
};
|