@dxos/plugin-automation 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b
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/AutomationPanel-WVLTR65T.mjs +11 -0
- package/dist/lib/browser/AutomationSettings-LOCSJ4XL.mjs +68 -0
- package/dist/lib/browser/AutomationSettings-LOCSJ4XL.mjs.map +7 -0
- package/dist/lib/browser/FunctionsContainer-CQRS5IQN.mjs +145 -0
- package/dist/lib/browser/FunctionsContainer-CQRS5IQN.mjs.map +7 -0
- package/dist/lib/browser/{FunctionsPanel-56ZKRVM5.mjs → FunctionsPanel-CRW6SJUN.mjs} +3 -3
- package/dist/lib/browser/{app-graph-builder-ZTAUTFI4.mjs → app-graph-builder-W7LLC6XW.mjs} +13 -12
- package/dist/lib/browser/app-graph-builder-W7LLC6XW.mjs.map +7 -0
- package/dist/lib/browser/chunk-5Q2XVI36.mjs +100 -0
- package/dist/lib/browser/chunk-5Q2XVI36.mjs.map +7 -0
- package/dist/lib/browser/chunk-6FCNJOBO.mjs +15 -0
- package/dist/lib/browser/chunk-6FCNJOBO.mjs.map +7 -0
- package/dist/lib/browser/chunk-ABZVRMU7.mjs +14 -0
- package/dist/lib/browser/chunk-ABZVRMU7.mjs.map +7 -0
- package/dist/lib/browser/chunk-BPRH3NBB.mjs +204 -0
- package/dist/lib/browser/chunk-BPRH3NBB.mjs.map +7 -0
- package/dist/lib/browser/chunk-LZQFZO3B.mjs +17 -0
- package/dist/lib/browser/chunk-LZQFZO3B.mjs.map +7 -0
- package/dist/lib/browser/{chunk-LYJVTIVD.mjs → chunk-TWWFNOIR.mjs} +30 -15
- package/dist/lib/browser/chunk-TWWFNOIR.mjs.map +7 -0
- package/dist/lib/browser/chunk-WAZEZHJI.mjs +270 -0
- package/dist/lib/browser/chunk-WAZEZHJI.mjs.map +7 -0
- package/dist/lib/browser/{chunk-HN7OHFCB.mjs → chunk-YBPJCY3F.mjs} +3 -3
- package/dist/lib/browser/chunk-YBPJCY3F.mjs.map +7 -0
- package/dist/lib/browser/compute-runtime-GPT45IDG.mjs +115 -0
- package/dist/lib/browser/compute-runtime-GPT45IDG.mjs.map +7 -0
- package/dist/lib/browser/hooks/index.mjs +13 -0
- package/dist/lib/browser/index.mjs +49 -19
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/{intent-resolver-U3ZAQEFW.mjs → intent-resolver-MJ7IDWCD.mjs} +17 -14
- package/dist/lib/browser/intent-resolver-MJ7IDWCD.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-4DFSM7OX.mjs → react-surface-FF5YP324.mjs} +20 -20
- package/dist/lib/browser/react-surface-FF5YP324.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +2 -2
- package/dist/lib/node-esm/{AutomationPanel-YYUMSK2W.mjs → AutomationPanel-PKWGKR7X.mjs} +4 -4
- package/dist/lib/node-esm/AutomationSettings-V5GZEOOQ.mjs +69 -0
- package/dist/lib/node-esm/AutomationSettings-V5GZEOOQ.mjs.map +7 -0
- package/dist/lib/node-esm/FunctionsContainer-5BBSN6IG.mjs +146 -0
- package/dist/lib/node-esm/FunctionsContainer-5BBSN6IG.mjs.map +7 -0
- package/dist/lib/node-esm/{FunctionsPanel-KGIOZSPZ.mjs → FunctionsPanel-RVVCS6VH.mjs} +3 -3
- package/dist/lib/node-esm/FunctionsPanel-RVVCS6VH.mjs.map +7 -0
- package/dist/lib/node-esm/{app-graph-builder-3FP63ZSG.mjs → app-graph-builder-SLQOO7GH.mjs} +13 -12
- package/dist/lib/node-esm/app-graph-builder-SLQOO7GH.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-267XBACB.mjs +101 -0
- package/dist/lib/node-esm/chunk-267XBACB.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-6RH5OXPG.mjs +16 -0
- package/dist/lib/node-esm/chunk-6RH5OXPG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CEVIVRTY.mjs +19 -0
- package/dist/lib/node-esm/chunk-CEVIVRTY.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-OEZNHUL2.mjs → chunk-ECJKIUBO.mjs} +3 -3
- package/dist/lib/node-esm/chunk-ECJKIUBO.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-FOK5AUNF.mjs +16 -0
- package/dist/lib/node-esm/chunk-FOK5AUNF.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-JVPWGVIV.mjs +205 -0
- package/dist/lib/node-esm/chunk-JVPWGVIV.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-AZH66CED.mjs → chunk-Q7KY3LVQ.mjs} +104 -64
- package/dist/lib/node-esm/chunk-Q7KY3LVQ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-ZGPUV5VS.mjs → chunk-RVK52XGK.mjs} +30 -15
- package/dist/lib/node-esm/chunk-RVK52XGK.mjs.map +7 -0
- package/dist/lib/node-esm/compute-runtime-SODV3TDU.mjs +116 -0
- package/dist/lib/node-esm/compute-runtime-SODV3TDU.mjs.map +7 -0
- package/dist/lib/node-esm/hooks/index.mjs +14 -0
- package/dist/lib/node-esm/hooks/index.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +49 -19
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/{intent-resolver-3QWXEBPX.mjs → intent-resolver-NOBCKCF6.mjs} +17 -14
- package/dist/lib/node-esm/intent-resolver-NOBCKCF6.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-3PNW7NDW.mjs → react-surface-OQIMKKTP.mjs} +20 -20
- package/dist/lib/node-esm/react-surface-OQIMKKTP.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +2 -2
- package/dist/types/src/AutomationPlugin.d.ts +1 -1
- package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/capabilities.d.ts +21 -0
- package/dist/types/src/capabilities/capabilities.d.ts.map +1 -0
- package/dist/types/src/capabilities/compute-runtime.d.ts +5 -0
- package/dist/types/src/capabilities/compute-runtime.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +5 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +6 -5
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -1
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts +49 -4
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts.map +1 -1
- package/dist/types/src/components/AutomationSettings.d.ts +5 -0
- package/dist/types/src/components/AutomationSettings.d.ts.map +1 -0
- package/dist/types/src/components/FunctionsContainer.d.ts.map +1 -1
- package/dist/types/src/components/FunctionsPanel/FunctionsPanel.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 +2 -0
- package/dist/types/src/components/FunctionsRegistry/index.d.ts.map +1 -0
- package/dist/types/src/components/TriggerEditor/FunctionInputEditor.d.ts +10 -8
- 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 +9 -6
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts +117 -4
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TriggerSettings.d.ts +6 -0
- package/dist/types/src/components/TriggerSettings.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/events.d.ts +4 -0
- package/dist/types/src/events.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +3 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts +13 -0
- package/dist/types/src/hooks/useComputeRuntimeCallback.d.ts.map +1 -0
- package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts +11 -0
- package/dist/types/src/hooks/useTriggerRuntimeControls.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/testing/test-functions.d.ts +2 -3
- package/dist/types/src/testing/test-functions.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +6 -0
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +1 -1
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +63 -38
- package/src/AutomationPlugin.tsx +37 -31
- package/src/capabilities/app-graph-builder.ts +16 -15
- package/src/capabilities/capabilities.ts +42 -0
- package/src/capabilities/compute-runtime.ts +129 -0
- package/src/capabilities/index.ts +3 -0
- package/src/capabilities/intent-resolver.ts +20 -15
- package/src/capabilities/react-surface.tsx +15 -15
- package/src/components/AutomationPanel/AutomationPanel.stories.tsx +16 -17
- package/src/components/AutomationPanel/AutomationPanel.tsx +127 -54
- package/src/components/AutomationSettings.tsx +30 -0
- package/src/components/FunctionsContainer.tsx +18 -13
- package/src/components/FunctionsPanel/FunctionsPanel.tsx +35 -16
- package/src/components/FunctionsRegistry/FunctionsRegistry.tsx +126 -0
- package/src/components/FunctionsRegistry/index.ts +5 -0
- package/src/components/TriggerEditor/FunctionInputEditor.tsx +40 -24
- package/src/components/TriggerEditor/SpecSelector.tsx +29 -21
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +78 -32
- package/src/components/TriggerEditor/TriggerEditor.tsx +86 -41
- package/src/components/TriggerSettings.tsx +25 -0
- package/src/components/index.ts +1 -1
- package/src/events.ts +11 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useComputeRuntimeCallback.ts +68 -0
- package/src/hooks/useTriggerRuntimeControls.ts +53 -0
- package/src/index.ts +3 -0
- package/src/meta.ts +6 -5
- package/src/testing/test-functions.ts +3 -3
- package/src/translations.ts +9 -0
- package/src/types/schema.ts +1 -1
- package/dist/lib/browser/AutomationContainer-VZNV2ZQF.mjs +0 -38
- package/dist/lib/browser/AutomationContainer-VZNV2ZQF.mjs.map +0 -7
- package/dist/lib/browser/AutomationPanel-ZWA6GOFY.mjs +0 -11
- package/dist/lib/browser/FunctionsContainer-IOB333TX.mjs +0 -39
- package/dist/lib/browser/FunctionsContainer-IOB333TX.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-ZTAUTFI4.mjs.map +0 -7
- package/dist/lib/browser/chunk-ECSTS2UI.mjs +0 -14
- package/dist/lib/browser/chunk-ECSTS2UI.mjs.map +0 -7
- package/dist/lib/browser/chunk-ERTIGJYE.mjs +0 -147
- package/dist/lib/browser/chunk-ERTIGJYE.mjs.map +0 -7
- package/dist/lib/browser/chunk-FSJZXTS2.mjs +0 -230
- package/dist/lib/browser/chunk-FSJZXTS2.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.map +0 -7
- package/dist/lib/browser/chunk-LYJVTIVD.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-U3ZAQEFW.mjs.map +0 -7
- package/dist/lib/browser/react-surface-4DFSM7OX.mjs.map +0 -7
- package/dist/lib/node-esm/AutomationContainer-WMIH3F4V.mjs +0 -39
- package/dist/lib/node-esm/AutomationContainer-WMIH3F4V.mjs.map +0 -7
- package/dist/lib/node-esm/FunctionsContainer-DJWB6WFH.mjs +0 -40
- package/dist/lib/node-esm/FunctionsContainer-DJWB6WFH.mjs.map +0 -7
- package/dist/lib/node-esm/app-graph-builder-3FP63ZSG.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AZH66CED.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HIMYPGHF.mjs +0 -148
- package/dist/lib/node-esm/chunk-HIMYPGHF.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.map +0 -7
- package/dist/lib/node-esm/chunk-SGZPTJ47.mjs +0 -16
- package/dist/lib/node-esm/chunk-SGZPTJ47.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ZGPUV5VS.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-3QWXEBPX.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-3PNW7NDW.mjs.map +0 -7
- package/dist/types/src/components/AutomationContainer.d.ts +0 -5
- package/dist/types/src/components/AutomationContainer.d.ts.map +0 -1
- package/src/components/AutomationContainer.tsx +0 -30
- /package/dist/lib/browser/{AutomationPanel-ZWA6GOFY.mjs.map → AutomationPanel-WVLTR65T.mjs.map} +0 -0
- /package/dist/lib/browser/{FunctionsPanel-56ZKRVM5.mjs.map → FunctionsPanel-CRW6SJUN.mjs.map} +0 -0
- /package/dist/lib/{node-esm/AutomationPanel-YYUMSK2W.mjs.map → browser/hooks/index.mjs.map} +0 -0
- /package/dist/lib/node-esm/{FunctionsPanel-KGIOZSPZ.mjs.map → AutomationPanel-PKWGKR7X.mjs.map} +0 -0
|
@@ -2,29 +2,39 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import type * as SchemaAST from 'effect/SchemaAST';
|
|
5
6
|
import React, { useCallback, useMemo } from 'react';
|
|
6
7
|
|
|
7
8
|
import { Ref, Type } from '@dxos/echo';
|
|
8
|
-
import { type JsonPath } from '@dxos/echo
|
|
9
|
-
import { type
|
|
10
|
-
import { useOnTransition } from '@dxos/react-ui';
|
|
11
|
-
import {
|
|
9
|
+
import { type JsonPath } from '@dxos/echo/internal';
|
|
10
|
+
import { type Function } from '@dxos/functions';
|
|
11
|
+
import { useOnTransition, useTranslation } from '@dxos/react-ui';
|
|
12
|
+
import {
|
|
13
|
+
Form,
|
|
14
|
+
type FormFieldStateProps,
|
|
15
|
+
type FormRootProps,
|
|
16
|
+
type QueryRefOptions,
|
|
17
|
+
omitId,
|
|
18
|
+
useFormValues,
|
|
19
|
+
} from '@dxos/react-ui-form';
|
|
20
|
+
|
|
21
|
+
import { meta } from '../../meta';
|
|
12
22
|
|
|
13
23
|
export type FunctionInputEditorProps = {
|
|
14
|
-
|
|
24
|
+
type: SchemaAST.AST;
|
|
25
|
+
functions: Function.Function[];
|
|
15
26
|
onQueryRefOptions: QueryRefOptions;
|
|
16
|
-
} &
|
|
27
|
+
} & FormFieldStateProps;
|
|
17
28
|
|
|
18
|
-
/**
|
|
19
|
-
* Editor component for function input parameters.
|
|
20
|
-
*/
|
|
21
29
|
export const FunctionInputEditor = ({
|
|
30
|
+
type,
|
|
22
31
|
functions,
|
|
23
32
|
getValue,
|
|
24
33
|
onValueChange,
|
|
25
34
|
onQueryRefOptions,
|
|
26
35
|
}: FunctionInputEditorProps) => {
|
|
27
|
-
const
|
|
36
|
+
const { t } = useTranslation(meta.id);
|
|
37
|
+
const selectedFunctionValue = useFormValues(FunctionInputEditor.displayName, ['function' as JsonPath]);
|
|
28
38
|
const selectedFunctionId = useMemo(() => {
|
|
29
39
|
if (Ref.isRef(selectedFunctionValue)) {
|
|
30
40
|
return selectedFunctionValue.dxn.toString().split('dxn:echo:@:').at(1);
|
|
@@ -39,22 +49,27 @@ export const FunctionInputEditor = ({
|
|
|
39
49
|
useOnTransition(
|
|
40
50
|
// Clear function parameter input when the function changes.
|
|
41
51
|
selectedFunctionValue,
|
|
42
|
-
(prevValue) =>
|
|
52
|
+
(prevValue) => {
|
|
53
|
+
if (!Ref.isRef(prevValue) || !Ref.isRef(selectedFunctionValue)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return prevValue.dxn.toString() !== selectedFunctionValue.dxn.toString();
|
|
58
|
+
},
|
|
43
59
|
(currValue) => currValue !== undefined,
|
|
44
|
-
() => onValueChange(
|
|
60
|
+
() => onValueChange(type, {}),
|
|
45
61
|
);
|
|
46
62
|
|
|
47
63
|
const inputSchema = useMemo(() => selectedFunction?.inputSchema, [selectedFunction]);
|
|
48
64
|
const effectSchema = useMemo(() => (inputSchema ? Type.toEffectSchema(inputSchema) : undefined), [inputSchema]);
|
|
49
65
|
const propertyCount = inputSchema?.properties ? Object.keys(inputSchema.properties).length : 0;
|
|
50
|
-
|
|
51
66
|
const values = useMemo(() => getValue() ?? {}, [getValue]);
|
|
52
67
|
|
|
53
|
-
const handleValuesChanged = useCallback(
|
|
54
|
-
(values
|
|
55
|
-
onValueChange(
|
|
68
|
+
const handleValuesChanged = useCallback<NonNullable<FormRootProps['onValuesChanged']>>(
|
|
69
|
+
(values) => {
|
|
70
|
+
onValueChange(type, values);
|
|
56
71
|
},
|
|
57
|
-
[onValueChange],
|
|
72
|
+
[type, onValueChange],
|
|
58
73
|
);
|
|
59
74
|
|
|
60
75
|
if (selectedFunction === undefined || effectSchema === undefined || propertyCount === 0) {
|
|
@@ -63,16 +78,17 @@ export const FunctionInputEditor = ({
|
|
|
63
78
|
|
|
64
79
|
return (
|
|
65
80
|
<>
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<Form
|
|
70
|
-
schema={effectSchema}
|
|
81
|
+
<Form.Label label={t('function parameters label')} asChild />
|
|
82
|
+
<Form.Root
|
|
83
|
+
schema={omitId(effectSchema)}
|
|
71
84
|
values={values}
|
|
72
85
|
onValuesChanged={handleValuesChanged}
|
|
73
86
|
onQueryRefOptions={onQueryRefOptions}
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
>
|
|
88
|
+
<Form.FieldSet />
|
|
89
|
+
</Form.Root>
|
|
76
90
|
</>
|
|
77
91
|
);
|
|
78
92
|
};
|
|
93
|
+
|
|
94
|
+
FunctionInputEditor.displayName = 'AutomationTrigger.FunctionInputEditor';
|
|
@@ -4,32 +4,38 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useCallback, useMemo } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Filter, Query } from '@dxos/echo';
|
|
8
|
+
import { Trigger } from '@dxos/functions';
|
|
8
9
|
import { useTranslation } from '@dxos/react-ui';
|
|
9
|
-
import {
|
|
10
|
+
import { type FormFieldComponentProps, SelectField, useFormFieldState } from '@dxos/react-ui-form';
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
+
import { meta } from '../../meta';
|
|
12
13
|
|
|
13
|
-
export type SpecSelectorProps =
|
|
14
|
+
export type SpecSelectorProps = FormFieldComponentProps;
|
|
14
15
|
|
|
15
16
|
export const SpecSelector = (props: SpecSelectorProps) => {
|
|
16
|
-
const { t } = useTranslation(
|
|
17
|
-
const specProps =
|
|
17
|
+
const { t } = useTranslation(meta.id);
|
|
18
|
+
const specProps = useFormFieldState(SpecSelector.displayName, ['spec' satisfies keyof Trigger.Trigger]);
|
|
18
19
|
|
|
19
20
|
const handleTypeChange = useCallback(
|
|
20
|
-
(_type: any, value: string):
|
|
21
|
+
(_type: any, value: string): Trigger.Spec | undefined => {
|
|
21
22
|
const getDefaultTriggerSpec = (kind: string) => {
|
|
22
23
|
switch (kind) {
|
|
23
|
-
case
|
|
24
|
-
return { kind:
|
|
25
|
-
case
|
|
26
|
-
return {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
case 'timer':
|
|
25
|
+
return { kind: 'timer', cron: '' };
|
|
26
|
+
case 'subscription':
|
|
27
|
+
return {
|
|
28
|
+
kind: 'subscription',
|
|
29
|
+
query: {
|
|
30
|
+
ast: Query.select(Filter.nothing()).ast,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
case 'queue':
|
|
34
|
+
return { kind: 'queue', queue: 'dxn:' };
|
|
35
|
+
case 'email':
|
|
36
|
+
return { kind: 'email' };
|
|
37
|
+
case 'webhook':
|
|
38
|
+
return { kind: 'webhook' };
|
|
33
39
|
default:
|
|
34
40
|
return undefined;
|
|
35
41
|
}
|
|
@@ -41,19 +47,21 @@ export const SpecSelector = (props: SpecSelectorProps) => {
|
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
// Update the entire spec object, not just the `spec.kind`.
|
|
44
|
-
specProps.onValueChange(
|
|
50
|
+
specProps.onValueChange(props.type, defaultSpec);
|
|
45
51
|
},
|
|
46
|
-
[specProps],
|
|
52
|
+
[props.type, specProps],
|
|
47
53
|
);
|
|
48
54
|
|
|
49
55
|
const options = useMemo(
|
|
50
56
|
() =>
|
|
51
|
-
|
|
57
|
+
Trigger.Kinds.map((kind) => ({
|
|
52
58
|
value: kind,
|
|
53
59
|
label: t(`trigger type ${kind}`),
|
|
54
60
|
})),
|
|
55
61
|
[t],
|
|
56
62
|
);
|
|
57
63
|
|
|
58
|
-
return <
|
|
64
|
+
return <SelectField {...props} options={options} onValueChange={handleTypeChange} />;
|
|
59
65
|
};
|
|
66
|
+
|
|
67
|
+
SpecSelector.displayName = 'Form.SpecSelector';
|
|
@@ -2,32 +2,56 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React, { useState } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import { Obj } from '@dxos/echo';
|
|
11
|
-
import { FunctionType, FunctionTrigger, TriggerKind } from '@dxos/functions';
|
|
8
|
+
import { Filter, Obj, Ref, Tag, Type } from '@dxos/echo';
|
|
9
|
+
import { Function, Trigger } from '@dxos/functions';
|
|
10
|
+
import { invariant } from '@dxos/invariant';
|
|
12
11
|
import { faker } from '@dxos/random';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
12
|
+
import { useQuery } from '@dxos/react-client/echo';
|
|
13
|
+
import { TestSchema, useClientProvider, withClientProvider } from '@dxos/react-client/testing';
|
|
14
|
+
import { useAsyncEffect } from '@dxos/react-ui';
|
|
15
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
16
|
+
import { translations as formTranslations } from '@dxos/react-ui-form';
|
|
17
|
+
import { Employer, Organization, Person, Project } from '@dxos/types';
|
|
16
18
|
|
|
17
|
-
import { TriggerEditor } from './TriggerEditor';
|
|
18
19
|
import { functions } from '../../testing';
|
|
19
20
|
import { translations } from '../../translations';
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
import { TriggerEditor, type TriggerEditorProps } from './TriggerEditor';
|
|
23
|
+
|
|
24
|
+
const types = [
|
|
25
|
+
// TODO(burdon): Get label from annotation.
|
|
26
|
+
{ value: Organization.Organization.typename, label: 'Organization' },
|
|
27
|
+
{ value: Person.Person.typename, label: 'Person' },
|
|
28
|
+
{ value: Type.getTypename(Project.Project), label: 'Project' },
|
|
29
|
+
{ value: Employer.Employer.typename, label: 'Employer' },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const DefaultStory = (props: Partial<TriggerEditorProps>) => {
|
|
33
|
+
const { space } = useClientProvider();
|
|
34
|
+
const [trigger, setTrigger] = useState<Trigger.Trigger>();
|
|
35
|
+
const tags = useQuery(space, Filter.type(Tag.Tag));
|
|
36
|
+
|
|
37
|
+
useAsyncEffect(async () => {
|
|
26
38
|
if (!space) {
|
|
27
39
|
return;
|
|
28
40
|
}
|
|
29
41
|
|
|
30
|
-
const
|
|
42
|
+
const functions = await space.db.query(Filter.type(Function.Function)).run();
|
|
43
|
+
const fn = functions.find((fn) => fn.name === 'example.com/function/forex');
|
|
44
|
+
invariant(fn);
|
|
45
|
+
const trigger = space.db.add(
|
|
46
|
+
Trigger.make({
|
|
47
|
+
function: Ref.make(fn),
|
|
48
|
+
spec: { kind: 'webhook' },
|
|
49
|
+
input: {
|
|
50
|
+
from: 'USD',
|
|
51
|
+
to: 'JPY',
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
31
55
|
setTrigger(trigger);
|
|
32
56
|
}, [space]);
|
|
33
57
|
|
|
@@ -36,28 +60,43 @@ const DefaultStory = () => {
|
|
|
36
60
|
}
|
|
37
61
|
|
|
38
62
|
return (
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
|
|
63
|
+
<TriggerEditor
|
|
64
|
+
space={space}
|
|
65
|
+
trigger={trigger}
|
|
66
|
+
types={types}
|
|
67
|
+
tags={tags}
|
|
68
|
+
onSave={(values) => console.log('on save', values)}
|
|
69
|
+
{...props}
|
|
70
|
+
/>
|
|
42
71
|
);
|
|
43
72
|
};
|
|
44
73
|
|
|
45
|
-
const meta
|
|
74
|
+
const meta = {
|
|
46
75
|
title: 'plugins/plugin-automation/TriggerEditor',
|
|
47
|
-
component: TriggerEditor,
|
|
76
|
+
component: TriggerEditor as any,
|
|
48
77
|
render: DefaultStory,
|
|
49
78
|
decorators: [
|
|
79
|
+
withTheme,
|
|
80
|
+
withLayout({ container: 'column' }),
|
|
50
81
|
withClientProvider({
|
|
51
82
|
createIdentity: true,
|
|
52
83
|
createSpace: true,
|
|
53
|
-
types: [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
84
|
+
types: [Tag.Tag, Function.Function, Trigger.Trigger, TestSchema.ContactType],
|
|
85
|
+
onCreateSpace: ({ space }) => {
|
|
86
|
+
// Tags.
|
|
87
|
+
['Important', 'Investor', 'New'].forEach((label) => {
|
|
88
|
+
space.db.add(Tag.make({ label }));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Functions.
|
|
92
|
+
functions.forEach((fn) => {
|
|
93
|
+
space.db.add(Function.make(fn));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Objects.
|
|
58
97
|
Array.from({ length: 10 }).map(() => {
|
|
59
98
|
return space.db.add(
|
|
60
|
-
Obj.make(ContactType, {
|
|
99
|
+
Obj.make(TestSchema.ContactType, {
|
|
61
100
|
name: faker.person.fullName(),
|
|
62
101
|
identifiers: [],
|
|
63
102
|
}),
|
|
@@ -65,14 +104,21 @@ const meta: Meta = {
|
|
|
65
104
|
});
|
|
66
105
|
},
|
|
67
106
|
}),
|
|
68
|
-
withLayout({ fullscreen: true, classNames: 'flex justify-center m-2' }),
|
|
69
|
-
withTheme,
|
|
70
107
|
],
|
|
71
108
|
parameters: {
|
|
72
|
-
|
|
109
|
+
layout: 'fullscreen',
|
|
110
|
+
translations: [...formTranslations, ...translations],
|
|
73
111
|
},
|
|
74
|
-
}
|
|
112
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
75
113
|
|
|
76
114
|
export default meta;
|
|
77
115
|
|
|
78
|
-
|
|
116
|
+
type Story = StoryObj<typeof meta>;
|
|
117
|
+
|
|
118
|
+
export const Default: Story = {};
|
|
119
|
+
|
|
120
|
+
export const ReadonlySpec: Story = {
|
|
121
|
+
args: {
|
|
122
|
+
readonlySpec: true,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
@@ -5,57 +5,86 @@
|
|
|
5
5
|
import React, { useCallback, useMemo } from 'react';
|
|
6
6
|
|
|
7
7
|
import { ComputeGraph } from '@dxos/conductor';
|
|
8
|
-
import {
|
|
8
|
+
import { DXN, type Query } from '@dxos/echo';
|
|
9
|
+
import { Function, Script, Trigger } from '@dxos/functions';
|
|
10
|
+
import { Filter, Ref, type Space, useQuery } from '@dxos/react-client/echo';
|
|
11
|
+
import { Input } from '@dxos/react-ui';
|
|
12
|
+
import { QueryForm, type QueryFormProps } from '@dxos/react-ui-components';
|
|
9
13
|
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
type ExcludeId,
|
|
15
|
+
Form,
|
|
16
|
+
FormFieldLabel,
|
|
17
|
+
type FormFieldMap,
|
|
18
|
+
type FormRootProps,
|
|
19
|
+
SelectField,
|
|
20
|
+
omitId,
|
|
21
|
+
useRefQueryOptions,
|
|
22
|
+
} from '@dxos/react-ui-form';
|
|
18
23
|
|
|
19
24
|
import { FunctionInputEditor, type FunctionInputEditorProps } from './FunctionInputEditor';
|
|
20
25
|
import { SpecSelector } from './SpecSelector';
|
|
21
26
|
|
|
27
|
+
type TriggerFormSchema = ExcludeId<typeof Trigger.Trigger>;
|
|
28
|
+
|
|
22
29
|
export type TriggerEditorProps = {
|
|
23
30
|
space: Space;
|
|
24
|
-
trigger:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
onSave?.(values);
|
|
32
|
-
};
|
|
31
|
+
trigger: Trigger.Trigger;
|
|
32
|
+
// TODO(wittjosiah): This needs to apply to whole spec but currently only applies to spec.kind & spec.query.
|
|
33
|
+
readonlySpec?: boolean;
|
|
34
|
+
} &
|
|
35
|
+
// prettier-ignore
|
|
36
|
+
Pick<QueryFormProps, 'types' | 'tags'> &
|
|
37
|
+
Pick<FormRootProps<TriggerFormSchema>, 'onSave' | 'onCancel'>;
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
const
|
|
39
|
+
export const TriggerEditor = ({ space, types, tags, readonlySpec, trigger, ...formProps }: TriggerEditorProps) => {
|
|
40
|
+
const handleQueryRefOptions = useRefQueryOptions({ space });
|
|
41
|
+
const fieldMap = useCustomInputs({
|
|
42
|
+
space,
|
|
43
|
+
types,
|
|
44
|
+
tags,
|
|
45
|
+
readonlySpec,
|
|
46
|
+
onQueryRefOptions: handleQueryRefOptions,
|
|
47
|
+
});
|
|
36
48
|
|
|
37
49
|
return (
|
|
38
|
-
<Form
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
schema={FunctionTriggerSchema}
|
|
50
|
+
<Form.Root<TriggerFormSchema>
|
|
51
|
+
{...formProps}
|
|
52
|
+
schema={omitId(Trigger.Trigger)}
|
|
42
53
|
values={trigger}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
fieldMap={fieldMap}
|
|
55
|
+
onQueryRefOptions={handleQueryRefOptions}
|
|
56
|
+
>
|
|
57
|
+
<Form.Viewport>
|
|
58
|
+
<Form.Content>
|
|
59
|
+
<Form.FieldSet />
|
|
60
|
+
<Form.Actions />
|
|
61
|
+
</Form.Content>
|
|
62
|
+
</Form.Viewport>
|
|
63
|
+
</Form.Root>
|
|
47
64
|
);
|
|
48
65
|
};
|
|
49
66
|
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
type UseCustomInputsProps = {
|
|
68
|
+
space: Space;
|
|
69
|
+
readonlySpec?: boolean;
|
|
70
|
+
onQueryRefOptions: FunctionInputEditorProps['onQueryRefOptions'];
|
|
71
|
+
} & Pick<QueryFormProps, 'types' | 'tags'>;
|
|
72
|
+
|
|
73
|
+
const useCustomInputs = ({
|
|
74
|
+
space,
|
|
75
|
+
readonlySpec,
|
|
76
|
+
types,
|
|
77
|
+
tags,
|
|
78
|
+
onQueryRefOptions,
|
|
79
|
+
}: UseCustomInputsProps): FormFieldMap => {
|
|
80
|
+
const functions = useQuery(space, Filter.type(Function.Function));
|
|
52
81
|
const workflows = useQuery(space, Filter.type(ComputeGraph));
|
|
53
|
-
const scripts = useQuery(space, Filter.type(
|
|
82
|
+
const scripts = useQuery(space, Filter.type(Script.Script));
|
|
54
83
|
|
|
55
84
|
return useMemo(
|
|
56
|
-
():
|
|
85
|
+
(): FormFieldMap => ({
|
|
57
86
|
// Function selector.
|
|
58
|
-
['function' satisfies keyof
|
|
87
|
+
['function' satisfies keyof Trigger.Trigger]: (props) => {
|
|
59
88
|
const getValue = useCallback(() => {
|
|
60
89
|
const formValue = props.getValue();
|
|
61
90
|
if (Ref.isRef(formValue)) {
|
|
@@ -66,17 +95,17 @@ const useCustomInputs = (space: Space, onQueryRefOptions: FunctionInputEditorPro
|
|
|
66
95
|
|
|
67
96
|
const handleOnValueChange = useCallback(
|
|
68
97
|
(_type: any, dxnString: string) => {
|
|
69
|
-
const dxn =
|
|
98
|
+
const dxn = DXN.parse(dxnString);
|
|
70
99
|
if (dxn) {
|
|
71
100
|
const ref = Ref.fromDXN(dxn);
|
|
72
|
-
props.onValueChange(
|
|
101
|
+
props.onValueChange(props.type, ref);
|
|
73
102
|
}
|
|
74
103
|
},
|
|
75
|
-
[props.onValueChange],
|
|
104
|
+
[props.type, props.onValueChange],
|
|
76
105
|
);
|
|
77
106
|
|
|
78
107
|
return (
|
|
79
|
-
<
|
|
108
|
+
<SelectField
|
|
80
109
|
{...props}
|
|
81
110
|
getValue={getValue as any}
|
|
82
111
|
onValueChange={handleOnValueChange}
|
|
@@ -86,14 +115,30 @@ const useCustomInputs = (space: Space, onQueryRefOptions: FunctionInputEditorPro
|
|
|
86
115
|
},
|
|
87
116
|
|
|
88
117
|
// Spec selector.
|
|
89
|
-
['spec.kind' as const]: SpecSelector
|
|
118
|
+
['spec.kind' as const]: (props) => <SpecSelector {...props} readonly={readonlySpec} />,
|
|
119
|
+
|
|
120
|
+
// TODO(wittjosiah): Copied from ViewEditor.
|
|
121
|
+
// Query input editor.
|
|
122
|
+
['spec.query' as const]: (props) => {
|
|
123
|
+
const handleChange = useCallback(
|
|
124
|
+
(query: Query.Any) => props.onValueChange(props.type, { ast: query.ast }),
|
|
125
|
+
[props.type, props.onValueChange],
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<Input.Root>
|
|
130
|
+
<FormFieldLabel label={props.label} asChild />
|
|
131
|
+
<QueryForm initialQuery={(props.getValue() as any).ast} types={types} tags={tags} onChange={handleChange} />
|
|
132
|
+
</Input.Root>
|
|
133
|
+
);
|
|
134
|
+
},
|
|
90
135
|
|
|
91
136
|
// Function input editor.
|
|
92
137
|
['input' as const]: (props) => (
|
|
93
138
|
<FunctionInputEditor {...props} functions={functions} onQueryRefOptions={onQueryRefOptions} />
|
|
94
139
|
),
|
|
95
140
|
}),
|
|
96
|
-
[workflows, scripts, functions],
|
|
141
|
+
[workflows, scripts, functions, readonlySpec],
|
|
97
142
|
);
|
|
98
143
|
};
|
|
99
144
|
|
|
@@ -101,7 +146,7 @@ const getWorkflowOptions = (graphs: ComputeGraph[]) => {
|
|
|
101
146
|
return graphs.map((graph) => ({ label: `compute-${graph.id}`, value: `dxn:echo:@:${graph.id}` }));
|
|
102
147
|
};
|
|
103
148
|
|
|
104
|
-
const getFunctionOptions = (scripts:
|
|
105
|
-
const getLabel = (fn:
|
|
149
|
+
const getFunctionOptions = (scripts: Script.Script[], functions: Function.Function[]) => {
|
|
150
|
+
const getLabel = (fn: Function.Function) => scripts.find((s) => fn.source?.target?.id === s.id)?.name ?? fn.name;
|
|
106
151
|
return functions.map((fn) => ({ label: getLabel(fn), value: `dxn:echo:@:${fn.id}` }));
|
|
107
152
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Space } from '@dxos/react-client/echo';
|
|
8
|
+
import { Input, useTranslation } from '@dxos/react-ui';
|
|
9
|
+
import { ControlItemInput } from '@dxos/react-ui-form';
|
|
10
|
+
|
|
11
|
+
import { useTriggerRuntimeControls } from '../hooks';
|
|
12
|
+
import { meta } from '../meta';
|
|
13
|
+
|
|
14
|
+
export const TriggersSettings = ({ space }: { space: Space }) => {
|
|
15
|
+
const { triggers, isRunning, start, stop } = useTriggerRuntimeControls(space);
|
|
16
|
+
const { t } = useTranslation(meta.id);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className='container-max-width grid grid-cols-1 md:grid-cols-[1fr_min-content]'>
|
|
20
|
+
<ControlItemInput title={t('runtime label')} description={t('runtime description')}>
|
|
21
|
+
<Input.Switch classNames='justify-self-end' checked={isRunning} onCheckedChange={isRunning ? stop : start} />
|
|
22
|
+
</ControlItemInput>
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
};
|
package/src/components/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { lazy } from 'react';
|
|
|
6
6
|
|
|
7
7
|
export * from './TriggerEditor';
|
|
8
8
|
|
|
9
|
-
export const AutomationContainer = lazy(() => import('./AutomationContainer'));
|
|
10
9
|
export const AutomationPanel = lazy(() => import('./AutomationPanel'));
|
|
10
|
+
export const AutomationSettings = lazy(() => import('./AutomationSettings'));
|
|
11
11
|
export const FunctionsContainer = lazy(() => import('./FunctionsContainer'));
|
|
12
12
|
export const FunctionsPanel = lazy(() => import('./FunctionsPanel'));
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { defineEvent } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
import { meta } from './meta';
|
|
8
|
+
|
|
9
|
+
export namespace AutomationEvents {
|
|
10
|
+
export const ComputeRuntimeReady = defineEvent(`${meta.id}/event/compute-runtime-ready`);
|
|
11
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Cause from 'effect/Cause';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import * as Exit from 'effect/Exit';
|
|
8
|
+
import { type DependencyList, useCallback } from 'react';
|
|
9
|
+
|
|
10
|
+
import { useCapability } from '@dxos/app-framework/react';
|
|
11
|
+
import { type FunctionDefinition, FunctionInvocationService } from '@dxos/functions';
|
|
12
|
+
import { InvocationTracer, TracingServiceExt } from '@dxos/functions-runtime';
|
|
13
|
+
import { log } from '@dxos/log';
|
|
14
|
+
import type { Space } from '@dxos/react-client/echo';
|
|
15
|
+
|
|
16
|
+
import { AutomationCapabilities } from '../capabilities';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create an effectful function that has access to compute services
|
|
20
|
+
*/
|
|
21
|
+
// TODO(burdon): Factor out (figure out cross-plugin capabilities dependencies).
|
|
22
|
+
export const useComputeRuntimeCallback = <T>(
|
|
23
|
+
space: Space | undefined,
|
|
24
|
+
fn: () => Effect.Effect<T, any, AutomationCapabilities.ComputeServices>,
|
|
25
|
+
deps?: DependencyList,
|
|
26
|
+
): (() => Promise<T>) => {
|
|
27
|
+
const computeRuntime = useCapability(AutomationCapabilities.ComputeRuntime);
|
|
28
|
+
const runtime = space !== undefined ? computeRuntime.getRuntime(space.id) : undefined;
|
|
29
|
+
|
|
30
|
+
return useCallback(() => {
|
|
31
|
+
if (!runtime) {
|
|
32
|
+
throw new TypeError('Space not provided to useComputeRuntimeCallback');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return runtime.runPromise(fn());
|
|
36
|
+
}, [runtime, ...(deps ?? [])]);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// TODO(wittjosiah): Function invoking should automatically be traced (DX-647).
|
|
40
|
+
export const invokeFunctionWithTracing = <I, O>(functionDef: FunctionDefinition<I, O>, inputData: I) =>
|
|
41
|
+
Effect.gen(function* () {
|
|
42
|
+
const tracer = yield* InvocationTracer;
|
|
43
|
+
const trace = yield* tracer.traceInvocationStart({
|
|
44
|
+
target: undefined,
|
|
45
|
+
payload: {
|
|
46
|
+
data: {},
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Invoke the function.
|
|
51
|
+
const result = yield* FunctionInvocationService.invokeFunction(functionDef, inputData).pipe(
|
|
52
|
+
Effect.provide(TracingServiceExt.layerQueue(trace.invocationTraceQueue)),
|
|
53
|
+
Effect.exit,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
if (Exit.isFailure(result)) {
|
|
57
|
+
const error = Cause.prettyErrors(result.cause)[0];
|
|
58
|
+
log.error(error.message, error.cause ?? error.stack);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
yield* tracer.traceInvocationEnd({
|
|
62
|
+
trace,
|
|
63
|
+
// TODO(dmaretskyi): Might miss errors.
|
|
64
|
+
exception: Exit.isFailure(result) ? Cause.prettyErrors(result.cause)[0] : undefined,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return result;
|
|
68
|
+
});
|