@dxos/plugin-automation 0.7.1-staging.8709ba7 → 0.7.2-staging.6d26b2a
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/index.mjs +436 -993
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +425 -965
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +436 -993
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts +1 -1
- package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/hooks/invocation-handler.d.ts.map +1 -1
- package/dist/types/src/hooks/useLocalTriggerManager.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +1 -1
- package/package.json +34 -34
- package/src/AutomationPlugin.tsx +3 -3
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +40 -22
- package/src/components/TriggerEditor/TriggerEditor.tsx +71 -322
- package/src/components/index.ts +0 -5
- package/src/hooks/invocation-handler.ts +6 -9
- package/src/hooks/useLocalTriggerManager.ts +2 -4
- package/src/translations.ts +1 -1
- package/dist/lib/browser/PromptContainer-6CBNCUKQ.mjs +0 -19
- package/dist/lib/browser/PromptContainer-6CBNCUKQ.mjs.map +0 -7
- package/dist/lib/browser/chunk-CJMV64XO.mjs +0 -217
- package/dist/lib/browser/chunk-CJMV64XO.mjs.map +0 -7
- package/dist/lib/node/PromptContainer-7RCGCU3K.cjs +0 -45
- package/dist/lib/node/PromptContainer-7RCGCU3K.cjs.map +0 -7
- package/dist/lib/node/chunk-YGRHTCOX.cjs +0 -240
- package/dist/lib/node/chunk-YGRHTCOX.cjs.map +0 -7
- package/dist/lib/node-esm/PromptContainer-4SCHQV5C.mjs +0 -20
- package/dist/lib/node-esm/PromptContainer-4SCHQV5C.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-62AB5HXX.mjs +0 -218
- package/dist/lib/node-esm/chunk-62AB5HXX.mjs.map +0 -7
- package/dist/types/src/components/Chain.d.ts +0 -12
- package/dist/types/src/components/Chain.d.ts.map +0 -1
- package/dist/types/src/components/PromptContainer.d.ts +0 -6
- package/dist/types/src/components/PromptContainer.d.ts.map +0 -1
- package/dist/types/src/components/TriggerEditor/Form.d.ts +0 -5
- package/dist/types/src/components/TriggerEditor/Form.d.ts.map +0 -1
- package/dist/types/src/components/TriggerEditor/meta.d.ts +0 -25
- package/dist/types/src/components/TriggerEditor/meta.d.ts.map +0 -1
- package/src/components/Chain.tsx +0 -66
- package/src/components/PromptContainer.tsx +0 -19
- package/src/components/TriggerEditor/Form.tsx +0 -18
- package/src/components/TriggerEditor/meta.tsx +0 -226
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-automation",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2-staging.6d26b2a",
|
|
4
4
|
"description": "Prompt chain plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -47,32 +47,32 @@
|
|
|
47
47
|
"@effect/schema": "^0.75.5",
|
|
48
48
|
"@preact/signals-core": "^1.6.0",
|
|
49
49
|
"lodash.get": "^4.4.2",
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/chain": "0.7.
|
|
52
|
-
"@dxos/context": "0.7.
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/echo-
|
|
55
|
-
"@dxos/echo-
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/plugin-
|
|
61
|
-
"@dxos/plugin-
|
|
62
|
-
"@dxos/plugin-
|
|
63
|
-
"@dxos/plugin-graph": "0.7.
|
|
64
|
-
"@dxos/plugin-
|
|
65
|
-
"@dxos/plugin-
|
|
66
|
-
"@dxos/plugin-
|
|
67
|
-
"@dxos/plugin-script": "0.7.
|
|
68
|
-
"@dxos/plugin-
|
|
69
|
-
"@dxos/plugin-
|
|
70
|
-
"@dxos/plugin-stack": "0.7.
|
|
71
|
-
"@dxos/react-
|
|
72
|
-
"@dxos/react-
|
|
73
|
-
"@dxos/react-ui-form": "0.7.
|
|
74
|
-
"@dxos/
|
|
75
|
-
"@dxos/
|
|
50
|
+
"@dxos/async": "0.7.2-staging.6d26b2a",
|
|
51
|
+
"@dxos/chain": "0.7.2-staging.6d26b2a",
|
|
52
|
+
"@dxos/context": "0.7.2-staging.6d26b2a",
|
|
53
|
+
"@dxos/app-framework": "0.7.2-staging.6d26b2a",
|
|
54
|
+
"@dxos/echo-schema": "0.7.2-staging.6d26b2a",
|
|
55
|
+
"@dxos/echo-db": "0.7.2-staging.6d26b2a",
|
|
56
|
+
"@dxos/invariant": "0.7.2-staging.6d26b2a",
|
|
57
|
+
"@dxos/functions": "0.7.2-staging.6d26b2a",
|
|
58
|
+
"@dxos/keys": "0.7.2-staging.6d26b2a",
|
|
59
|
+
"@dxos/log": "0.7.2-staging.6d26b2a",
|
|
60
|
+
"@dxos/plugin-client": "0.7.2-staging.6d26b2a",
|
|
61
|
+
"@dxos/plugin-chess": "0.7.2-staging.6d26b2a",
|
|
62
|
+
"@dxos/plugin-deck": "0.7.2-staging.6d26b2a",
|
|
63
|
+
"@dxos/plugin-graph": "0.7.2-staging.6d26b2a",
|
|
64
|
+
"@dxos/plugin-ipfs": "0.7.2-staging.6d26b2a",
|
|
65
|
+
"@dxos/plugin-inbox": "0.7.2-staging.6d26b2a",
|
|
66
|
+
"@dxos/plugin-markdown": "0.7.2-staging.6d26b2a",
|
|
67
|
+
"@dxos/plugin-script": "0.7.2-staging.6d26b2a",
|
|
68
|
+
"@dxos/plugin-sketch": "0.7.2-staging.6d26b2a",
|
|
69
|
+
"@dxos/plugin-space": "0.7.2-staging.6d26b2a",
|
|
70
|
+
"@dxos/plugin-stack": "0.7.2-staging.6d26b2a",
|
|
71
|
+
"@dxos/react-ui-editor": "0.7.2-staging.6d26b2a",
|
|
72
|
+
"@dxos/react-client": "0.7.2-staging.6d26b2a",
|
|
73
|
+
"@dxos/react-ui-form": "0.7.2-staging.6d26b2a",
|
|
74
|
+
"@dxos/schema": "0.7.2-staging.6d26b2a",
|
|
75
|
+
"@dxos/util": "0.7.2-staging.6d26b2a"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@phosphor-icons/react": "^2.1.5",
|
|
@@ -82,18 +82,18 @@
|
|
|
82
82
|
"react": "~18.2.0",
|
|
83
83
|
"react-dom": "~18.2.0",
|
|
84
84
|
"vite": "5.4.7",
|
|
85
|
-
"@dxos/echo-db": "0.7.
|
|
86
|
-
"@dxos/random": "0.7.
|
|
87
|
-
"@dxos/react-ui": "0.7.
|
|
88
|
-
"@dxos/react-ui-theme": "0.7.
|
|
89
|
-
"@dxos/storybook-utils": "0.7.
|
|
85
|
+
"@dxos/echo-db": "0.7.2-staging.6d26b2a",
|
|
86
|
+
"@dxos/random": "0.7.2-staging.6d26b2a",
|
|
87
|
+
"@dxos/react-ui": "0.7.2-staging.6d26b2a",
|
|
88
|
+
"@dxos/react-ui-theme": "0.7.2-staging.6d26b2a",
|
|
89
|
+
"@dxos/storybook-utils": "0.7.2-staging.6d26b2a"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"@phosphor-icons/react": "^2.1.5",
|
|
93
93
|
"react": "~18.2.0",
|
|
94
94
|
"react-dom": "~18.2.0",
|
|
95
|
-
"@dxos/react-ui": "0.7.
|
|
96
|
-
"@dxos/react-ui-theme": "0.7.
|
|
95
|
+
"@dxos/react-ui": "0.7.2-staging.6d26b2a",
|
|
96
|
+
"@dxos/react-ui-theme": "0.7.2-staging.6d26b2a"
|
|
97
97
|
},
|
|
98
98
|
"publishConfig": {
|
|
99
99
|
"access": "public"
|
package/src/AutomationPlugin.tsx
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
7
|
import { type PluginDefinition, parseMetadataResolverPlugin, resolvePlugin } from '@dxos/app-framework';
|
|
8
|
-
import {
|
|
8
|
+
import { FunctionTrigger } from '@dxos/functions';
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
10
|
import { parseClientPlugin } from '@dxos/plugin-client';
|
|
11
11
|
import { createExtension, toSignal } from '@dxos/plugin-graph';
|
|
@@ -32,7 +32,7 @@ export const AutomationPlugin = (): PluginDefinition<AutomationPluginProvides> =
|
|
|
32
32
|
},
|
|
33
33
|
translations,
|
|
34
34
|
echo: {
|
|
35
|
-
schema: [ChainType, ChainPromptType,
|
|
35
|
+
schema: [ChainType, ChainPromptType, FunctionTrigger],
|
|
36
36
|
},
|
|
37
37
|
complementary: {
|
|
38
38
|
panels: [
|
|
@@ -92,7 +92,7 @@ export const AutomationPlugin = (): PluginDefinition<AutomationPluginProvides> =
|
|
|
92
92
|
const object = toSignal(
|
|
93
93
|
(onChange) => {
|
|
94
94
|
const timeout = setTimeout(async () => {
|
|
95
|
-
await space?.db.
|
|
95
|
+
await space?.db.query({ id: objectId }).first();
|
|
96
96
|
onChange();
|
|
97
97
|
});
|
|
98
98
|
|
|
@@ -7,9 +7,10 @@ import '@dxos-theme';
|
|
|
7
7
|
import { type Meta } from '@storybook/react';
|
|
8
8
|
import React, { useEffect, useState } from 'react';
|
|
9
9
|
|
|
10
|
-
import { create } from '@dxos/echo-schema';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { AST, S, create, toJsonSchema } from '@dxos/echo-schema';
|
|
11
|
+
import { FunctionTrigger, TriggerKind } from '@dxos/functions';
|
|
12
|
+
import { FunctionType } from '@dxos/plugin-script/types';
|
|
13
|
+
import { useSpaces } from '@dxos/react-client/echo';
|
|
13
14
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
14
15
|
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
15
16
|
|
|
@@ -17,33 +18,49 @@ import { TriggerEditor } from './TriggerEditor';
|
|
|
17
18
|
import translations from '../../translations';
|
|
18
19
|
import { ChainPromptType } from '../../types';
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
// TODO(burdon): Extract type?
|
|
22
|
+
const functions = [
|
|
21
23
|
{
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
name: 'example.com/function/chess',
|
|
25
|
+
version: 1,
|
|
26
|
+
inputSchema: toJsonSchema(
|
|
27
|
+
S.Struct({
|
|
28
|
+
level: S.Number.annotations({
|
|
29
|
+
[AST.TitleAnnotationId]: 'Level',
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
),
|
|
26
33
|
},
|
|
27
34
|
{
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
name: 'example.com/function/forex',
|
|
36
|
+
version: 1,
|
|
37
|
+
binding: 'FOREX',
|
|
38
|
+
inputSchema: toJsonSchema(
|
|
39
|
+
S.Struct({
|
|
40
|
+
from: S.String.annotations({
|
|
41
|
+
[AST.TitleAnnotationId]: 'Currency from',
|
|
42
|
+
}),
|
|
43
|
+
to: S.String.annotations({
|
|
44
|
+
[AST.TitleAnnotationId]: 'Currency to',
|
|
45
|
+
}),
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
32
48
|
},
|
|
33
49
|
];
|
|
34
50
|
|
|
35
|
-
const
|
|
51
|
+
const DefaultStory = () => {
|
|
52
|
+
const spaces = useSpaces();
|
|
53
|
+
const space = spaces[1];
|
|
36
54
|
const [trigger, setTrigger] = useState<FunctionTrigger>();
|
|
37
|
-
const client = useClient();
|
|
38
|
-
const space = client.spaces.default;
|
|
39
55
|
useEffect(() => {
|
|
40
56
|
if (!space) {
|
|
41
57
|
return;
|
|
42
58
|
}
|
|
43
59
|
|
|
44
|
-
const trigger = space.db.add(create(FunctionTrigger, {
|
|
60
|
+
const trigger = space.db.add(create(FunctionTrigger, { spec: { type: TriggerKind.Timer, cron: '' } }));
|
|
45
61
|
setTrigger(trigger);
|
|
46
|
-
}, [space
|
|
62
|
+
}, [space]);
|
|
63
|
+
|
|
47
64
|
if (!space || !trigger) {
|
|
48
65
|
return <div />;
|
|
49
66
|
}
|
|
@@ -55,20 +72,19 @@ const Story = () => {
|
|
|
55
72
|
);
|
|
56
73
|
};
|
|
57
74
|
|
|
58
|
-
export const Default = {};
|
|
59
|
-
|
|
60
75
|
const meta: Meta = {
|
|
61
76
|
title: 'plugins/plugin-automation/TriggerEditor',
|
|
62
77
|
component: TriggerEditor,
|
|
63
|
-
render:
|
|
78
|
+
render: DefaultStory,
|
|
64
79
|
decorators: [
|
|
65
80
|
withClientProvider({
|
|
66
81
|
createIdentity: true,
|
|
67
82
|
createSpace: true,
|
|
68
|
-
types: [
|
|
83
|
+
types: [FunctionType, FunctionTrigger, ChainPromptType],
|
|
69
84
|
onSpaceCreated: ({ space }) => {
|
|
85
|
+
console.log(space.id);
|
|
70
86
|
for (const fn of functions) {
|
|
71
|
-
space.db.add(create(
|
|
87
|
+
space.db.add(create(FunctionType, fn));
|
|
72
88
|
}
|
|
73
89
|
},
|
|
74
90
|
}),
|
|
@@ -81,3 +97,5 @@ const meta: Meta = {
|
|
|
81
97
|
};
|
|
82
98
|
|
|
83
99
|
export default meta;
|
|
100
|
+
|
|
101
|
+
export const Default = {};
|
|
@@ -2,343 +2,92 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React
|
|
5
|
+
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type SubscriptionTrigger,
|
|
12
|
-
type TimerTrigger,
|
|
13
|
-
type TriggerType,
|
|
14
|
-
type TriggerKind,
|
|
15
|
-
type WebhookTrigger,
|
|
16
|
-
type WebsocketTrigger,
|
|
17
|
-
} from '@dxos/functions/types';
|
|
18
|
-
import { invariant } from '@dxos/invariant';
|
|
19
|
-
import { ScriptType } from '@dxos/plugin-script/types';
|
|
20
|
-
import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
|
|
21
|
-
import { Input, Select, useTranslation } from '@dxos/react-ui';
|
|
7
|
+
import { FunctionTriggerSchema, type FunctionTriggerType, type FunctionTrigger, TriggerKind } from '@dxos/functions';
|
|
8
|
+
import { FunctionType } from '@dxos/plugin-script/types';
|
|
9
|
+
import { Filter, useQuery, type Space } from '@dxos/react-client/echo';
|
|
10
|
+
import { useTranslation } from '@dxos/react-ui';
|
|
22
11
|
import { Form, SelectInput } from '@dxos/react-ui-form';
|
|
23
|
-
import { distinctBy } from '@dxos/util';
|
|
24
12
|
|
|
25
|
-
import { InputRow } from './Form';
|
|
26
|
-
import { getFunctionMetaExtension, state } from './meta';
|
|
27
|
-
import { useLocalTriggerManager } from '../../hooks';
|
|
28
13
|
import { AUTOMATION_PLUGIN } from '../../meta';
|
|
29
14
|
|
|
30
|
-
const triggerTypes: TriggerKind[] = ['timer', 'webhook', 'websocket', 'subscription'];
|
|
31
|
-
|
|
32
15
|
export type TriggerEditorProps = {
|
|
33
16
|
space: Space;
|
|
34
17
|
trigger: FunctionTrigger;
|
|
35
18
|
};
|
|
36
19
|
|
|
20
|
+
// TODO(burdon): Functions (new def).
|
|
21
|
+
// TODO(burdon): Function meta (remove meta from existing trigger def).
|
|
22
|
+
// TODO(burdon): Actual integration.
|
|
23
|
+
|
|
37
24
|
export const TriggerEditor = ({ space, trigger }: TriggerEditorProps) => {
|
|
38
25
|
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
state.schemas = distinctBy([...state.schemas, ...schemas], (schema) => schema.typename).sort((a, b) =>
|
|
56
|
-
a.typename < b.typename ? -1 : 1,
|
|
57
|
-
);
|
|
58
|
-
})
|
|
59
|
-
.catch(() => {});
|
|
60
|
-
}, [space]);
|
|
26
|
+
const functions = useQuery(space, Filter.schema(FunctionType));
|
|
27
|
+
|
|
28
|
+
// const script = useMemo(() => scripts.find((script) => script.id === trigger.function), [trigger.function, scripts]);
|
|
29
|
+
// useLocalTriggerManager(space);
|
|
30
|
+
|
|
31
|
+
// useEffect(() => {
|
|
32
|
+
// void space.db.schemaRegistry
|
|
33
|
+
// .query()
|
|
34
|
+
// .then((schemas) => {
|
|
35
|
+
// // TODO(zan): We should solve double adding of stored schemas in the schema registry.
|
|
36
|
+
// state.schemas = distinctBy([...state.schemas, ...schemas], (schema) => schema.typename).sort((a, b) =>
|
|
37
|
+
// a.typename < b.typename ? -1 : 1,
|
|
38
|
+
// );
|
|
39
|
+
// })
|
|
40
|
+
// .catch(() => {});
|
|
41
|
+
// }, [space]);
|
|
61
42
|
|
|
62
43
|
// Keen an enriched version of the schema in memory so we can share it with prompt editor.
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}, [JSON.stringify(trigger.spec), state.schemas]);
|
|
77
|
-
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}, [trigger.function, trigger.meta]);
|
|
84
|
-
|
|
85
|
-
const handleSelectFunction = (value: string) => {
|
|
86
|
-
const match = scripts.find((fn) => fn.id === value);
|
|
87
|
-
if (match) {
|
|
88
|
-
trigger.function = match.id;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const handleSelectTriggerType = (triggerType: string) => {
|
|
93
|
-
switch (triggerType as TriggerKind) {
|
|
94
|
-
case 'subscription': {
|
|
95
|
-
trigger.spec = { type: 'subscription', filter: {} };
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case 'timer': {
|
|
99
|
-
trigger.spec = { type: 'timer', cron: '0 0 * * *' };
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
case 'webhook': {
|
|
103
|
-
trigger.spec = { type: 'webhook', method: 'GET' };
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
case 'websocket': {
|
|
107
|
-
// TODO(burdon): The `init` property is currently mail worker specific.
|
|
108
|
-
trigger.spec = { type: 'websocket', url: '', init: { type: 'sync' } };
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const TriggerMeta = getFunctionMetaExtension(trigger, script)?.component;
|
|
115
|
-
|
|
116
|
-
const test = true;
|
|
117
|
-
if (test) {
|
|
118
|
-
const object: FunctionTriggerType = {
|
|
119
|
-
spec: {
|
|
120
|
-
// type: 'timer',
|
|
121
|
-
type: 'subscription',
|
|
122
|
-
// cron: '0 0 * * *'
|
|
123
|
-
filter: { type: 'dxos.org/type/Event' },
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
<Form<FunctionTriggerType>
|
|
129
|
-
schema={FunctionTriggerSchema}
|
|
130
|
-
values={object}
|
|
131
|
-
filter={(props) => props.filter((p) => p.name !== 'meta')}
|
|
132
|
-
Custom={{
|
|
133
|
-
['function' satisfies keyof FunctionTriggerType]: (props) => (
|
|
134
|
-
<SelectInput<FunctionTriggerType>
|
|
135
|
-
{...props}
|
|
136
|
-
// TODO(burdon): Query for functions.
|
|
137
|
-
options={[].map((value) => ({
|
|
138
|
-
value,
|
|
139
|
-
label: value,
|
|
140
|
-
}))}
|
|
141
|
-
/>
|
|
142
|
-
),
|
|
143
|
-
['spec.type' as const]: (props) => (
|
|
144
|
-
<SelectInput<FunctionTriggerType>
|
|
145
|
-
{...props}
|
|
146
|
-
options={['timer', 'subscription'].map((value) => ({
|
|
147
|
-
value,
|
|
148
|
-
label: value,
|
|
149
|
-
}))}
|
|
150
|
-
/>
|
|
151
|
-
),
|
|
152
|
-
}}
|
|
153
|
-
/>
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return (
|
|
158
|
-
<div className='flex flex-col py-1'>
|
|
159
|
-
<table className='is-full table-fixed'>
|
|
160
|
-
<tbody>
|
|
161
|
-
<InputRow label={t('function select label')}>
|
|
162
|
-
<Select.Root value={script?.id} onValueChange={handleSelectFunction}>
|
|
163
|
-
<Select.TriggerButton classNames='w-full' placeholder={t('function select placeholder')} />
|
|
164
|
-
<Select.Portal>
|
|
165
|
-
<Select.Content>
|
|
166
|
-
<Select.Viewport>
|
|
167
|
-
{scripts.map(({ id, name }) => (
|
|
168
|
-
<Select.Option key={id} value={id}>
|
|
169
|
-
{name ?? id}
|
|
170
|
-
</Select.Option>
|
|
171
|
-
))}
|
|
172
|
-
</Select.Viewport>
|
|
173
|
-
</Select.Content>
|
|
174
|
-
</Select.Portal>
|
|
175
|
-
</Select.Root>
|
|
176
|
-
</InputRow>
|
|
177
|
-
{script?.description?.length && (
|
|
178
|
-
<InputRow>
|
|
179
|
-
<div className='px-2'>
|
|
180
|
-
<p className='text-sm text-description'>{script?.description?.length}</p>
|
|
181
|
-
</div>
|
|
182
|
-
</InputRow>
|
|
183
|
-
)}
|
|
184
|
-
<InputRow label={t('trigger select label')}>
|
|
185
|
-
<Select.Root value={trigger.spec?.type} onValueChange={handleSelectTriggerType}>
|
|
186
|
-
<Select.TriggerButton placeholder={t('trigger select placeholder')} />
|
|
187
|
-
<Select.Portal>
|
|
188
|
-
<Select.Content>
|
|
189
|
-
<Select.Viewport>
|
|
190
|
-
{triggerTypes.map((trigger) => (
|
|
191
|
-
<Select.Option key={trigger} value={trigger}>
|
|
192
|
-
{triggerLabels[trigger]}
|
|
193
|
-
</Select.Option>
|
|
194
|
-
))}
|
|
195
|
-
</Select.Viewport>
|
|
196
|
-
</Select.Content>
|
|
197
|
-
</Select.Portal>
|
|
198
|
-
</Select.Root>
|
|
199
|
-
</InputRow>
|
|
200
|
-
</tbody>
|
|
201
|
-
<tbody>
|
|
202
|
-
{trigger.spec && <TriggerType space={space} spec={trigger.spec} />}
|
|
203
|
-
<InputRow label={t('function enabled')}>
|
|
204
|
-
{/* TODO(burdon): Hack to make the switch the same height as other controls. */}
|
|
205
|
-
<div className='flex items-center h-8'>
|
|
206
|
-
<Input.Switch checked={trigger.enabled} onCheckedChange={(checked) => (trigger.enabled = !!checked)} />
|
|
207
|
-
</div>
|
|
208
|
-
</InputRow>
|
|
209
|
-
</tbody>
|
|
210
|
-
{TriggerMeta && trigger.meta && (
|
|
211
|
-
<tbody>
|
|
212
|
-
<tr>
|
|
213
|
-
<td />
|
|
214
|
-
<td className='py-2'>
|
|
215
|
-
<div className='border-b border-separator' />
|
|
216
|
-
</td>
|
|
217
|
-
</tr>
|
|
218
|
-
<TriggerMeta meta={trigger.meta} />
|
|
219
|
-
</tbody>
|
|
220
|
-
)}
|
|
221
|
-
</table>
|
|
222
|
-
</div>
|
|
223
|
-
);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
//
|
|
227
|
-
// Trigger specs
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
const TriggerSpecSubscription = ({ spec }: TriggerSpecProps<SubscriptionTrigger>) => {
|
|
231
|
-
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
232
|
-
if (!spec.filter) {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const handleValueChange = (typename: string) => {
|
|
237
|
-
spec.filter = { type: typename };
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
return (
|
|
241
|
-
<>
|
|
242
|
-
<InputRow label={t('trigger filter')}>
|
|
243
|
-
<Select.Root value={spec.filter?.type} onValueChange={handleValueChange}>
|
|
244
|
-
<Select.TriggerButton classNames='w-full' placeholder={'Select type'} />
|
|
245
|
-
<Select.Portal>
|
|
246
|
-
<Select.Content>
|
|
247
|
-
<Select.Viewport>
|
|
248
|
-
{state.schemas.map(({ typename }: any) => (
|
|
249
|
-
<Select.Option key={typename} value={typename}>
|
|
250
|
-
{typename}
|
|
251
|
-
</Select.Option>
|
|
252
|
-
))}
|
|
253
|
-
</Select.Viewport>
|
|
254
|
-
</Select.Content>
|
|
255
|
-
</Select.Portal>
|
|
256
|
-
</Select.Root>
|
|
257
|
-
</InputRow>
|
|
258
|
-
</>
|
|
259
|
-
);
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
const TriggerSpecTimer = ({ spec }: TriggerSpecProps<TimerTrigger>) => {
|
|
263
|
-
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
264
|
-
return (
|
|
265
|
-
<>
|
|
266
|
-
<InputRow label={t('trigger cron')}>
|
|
267
|
-
<Input.TextInput value={spec.cron} onChange={(event) => (spec.cron = event.target.value)} />
|
|
268
|
-
</InputRow>
|
|
269
|
-
</>
|
|
270
|
-
);
|
|
271
|
-
};
|
|
44
|
+
// useEffect(() => {
|
|
45
|
+
// const spec = trigger.spec;
|
|
46
|
+
// invariant(spec);
|
|
47
|
+
// if (spec.type === 'subscription') {
|
|
48
|
+
// if (spec.filter) {
|
|
49
|
+
// const type = spec.filter.type;
|
|
50
|
+
// const foundSchema = state.schemas.find((schema) => schema.typename === type);
|
|
51
|
+
// if (foundSchema) {
|
|
52
|
+
// state.selectedSchema[trigger.id] = foundSchema;
|
|
53
|
+
// }
|
|
54
|
+
// }
|
|
55
|
+
// }
|
|
56
|
+
// // TODO(burdon): API issue.
|
|
57
|
+
// }, [JSON.stringify(trigger.spec), state.schemas]);
|
|
58
|
+
|
|
59
|
+
// useEffect(() => {
|
|
60
|
+
// if (!trigger.meta) {
|
|
61
|
+
// const extension = getFunctionMetaExtension(trigger, script);
|
|
62
|
+
// trigger.meta = extension?.initialValue?.();
|
|
63
|
+
// }
|
|
64
|
+
// }, [trigger.function, trigger.meta]);
|
|
272
65
|
|
|
273
|
-
const methods = ['GET', 'POST'];
|
|
274
|
-
|
|
275
|
-
const TriggerSpecWebhook = ({ spec }: TriggerSpecProps<WebhookTrigger>) => {
|
|
276
|
-
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
277
66
|
return (
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
67
|
+
<Form<FunctionTriggerType>
|
|
68
|
+
schema={FunctionTriggerSchema}
|
|
69
|
+
values={trigger}
|
|
70
|
+
filter={(props) => props.filter((p) => p.name !== 'meta')}
|
|
71
|
+
Custom={{
|
|
72
|
+
['function' satisfies keyof FunctionTriggerType]: (props) => (
|
|
73
|
+
<SelectInput<FunctionTriggerType>
|
|
74
|
+
{...props}
|
|
75
|
+
options={functions.map(({ name }) => ({
|
|
76
|
+
value: name,
|
|
77
|
+
label: name,
|
|
78
|
+
}))}
|
|
79
|
+
/>
|
|
80
|
+
),
|
|
81
|
+
['spec.type' as const]: (props) => (
|
|
82
|
+
<SelectInput<FunctionTriggerType>
|
|
83
|
+
{...props}
|
|
84
|
+
options={Object.values(TriggerKind).map((kind) => ({
|
|
85
|
+
value: kind,
|
|
86
|
+
label: t(`trigger type ${kind}`),
|
|
87
|
+
}))}
|
|
88
|
+
/>
|
|
89
|
+
),
|
|
90
|
+
}}
|
|
91
|
+
/>
|
|
296
92
|
);
|
|
297
93
|
};
|
|
298
|
-
|
|
299
|
-
const TriggerSpecWebsocket = ({ spec }: TriggerSpecProps<WebsocketTrigger>) => {
|
|
300
|
-
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
301
|
-
|
|
302
|
-
const handleChangeInit: ChangeEventHandler<HTMLInputElement> = (event) => {
|
|
303
|
-
try {
|
|
304
|
-
spec.init = JSON.parse(event.target.value);
|
|
305
|
-
} catch (err) {
|
|
306
|
-
// Ignore.
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
return (
|
|
311
|
-
<>
|
|
312
|
-
<InputRow label={t('trigger method')}>
|
|
313
|
-
<Input.TextInput
|
|
314
|
-
value={spec.url}
|
|
315
|
-
onChange={(event) => (spec.url = event.target.value)}
|
|
316
|
-
placeholder='https://'
|
|
317
|
-
/>
|
|
318
|
-
</InputRow>
|
|
319
|
-
<InputRow label='Init'>
|
|
320
|
-
<Input.TextInput value={JSON.stringify(spec.init)} onChange={handleChangeInit} placeholder='Initial message.' />
|
|
321
|
-
</InputRow>
|
|
322
|
-
</>
|
|
323
|
-
);
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
//
|
|
327
|
-
// Trigger spec.
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
type TriggerSpecProps<T = TriggerType> = { space: Space; spec: T };
|
|
331
|
-
|
|
332
|
-
const triggerRenderers: {
|
|
333
|
-
[key in TriggerKind]: FC<TriggerSpecProps<any>>;
|
|
334
|
-
} = {
|
|
335
|
-
subscription: TriggerSpecSubscription,
|
|
336
|
-
timer: TriggerSpecTimer,
|
|
337
|
-
webhook: TriggerSpecWebhook,
|
|
338
|
-
websocket: TriggerSpecWebsocket,
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
const TriggerType = ({ space, spec }: TriggerSpecProps) => {
|
|
342
|
-
const Component = triggerRenderers[spec.type];
|
|
343
|
-
return Component ? <Component space={space} spec={spec} /> : null;
|
|
344
|
-
};
|
package/src/components/index.ts
CHANGED
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { lazy } from 'react';
|
|
6
|
-
|
|
7
|
-
export const PromptContainer = lazy(() => import('./PromptContainer'));
|
|
8
|
-
|
|
9
5
|
export * from './AutomationPanel';
|
|
10
|
-
export * from './Chain';
|
|
11
6
|
export * from './PromptEditor';
|
|
12
7
|
export * from './TriggerEditor';
|