@dxos/plugin-automation 0.7.1 → 0.7.2-main.f1adc9f
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/AssistantPanel-622FK3DP.mjs +341 -0
- package/dist/lib/browser/AssistantPanel-622FK3DP.mjs.map +7 -0
- package/dist/lib/browser/AutomationPanel-PVI2EJNE.mjs +125 -0
- package/dist/lib/browser/AutomationPanel-PVI2EJNE.mjs.map +7 -0
- package/dist/lib/browser/{chunk-B3Z4NQC2.mjs → chunk-R6GS7UA7.mjs} +2 -8
- package/dist/lib/browser/{chunk-B3Z4NQC2.mjs.map → chunk-R6GS7UA7.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-PQLGYMNY.mjs → chunk-X5KMOH3I.mjs} +2 -2
- package/dist/lib/browser/{chunk-PQLGYMNY.mjs.map → chunk-X5KMOH3I.mjs.map} +1 -1
- package/dist/lib/browser/index.mjs +277 -1011
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types/index.mjs +1 -2
- package/dist/lib/node/AssistantPanel-HRJRVOZD.cjs +361 -0
- package/dist/lib/node/AssistantPanel-HRJRVOZD.cjs.map +7 -0
- package/dist/lib/node/AutomationPanel-Z2XW24BN.cjs +145 -0
- package/dist/lib/node/AutomationPanel-Z2XW24BN.cjs.map +7 -0
- package/dist/lib/node/{chunk-JSZ6PAYL.cjs → chunk-DTJ7XVO2.cjs} +5 -5
- package/dist/lib/node/{chunk-JSZ6PAYL.cjs.map → chunk-DTJ7XVO2.cjs.map} +1 -1
- package/dist/lib/node/{chunk-SUMUWFZA.cjs → chunk-JHKEVE65.cjs} +5 -8
- package/dist/lib/node/{chunk-SUMUWFZA.cjs.map → chunk-JHKEVE65.cjs.map} +3 -3
- package/dist/lib/node/index.cjs +298 -1008
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +6 -7
- package/dist/lib/node/types/index.cjs.map +2 -2
- package/dist/lib/node-esm/AssistantPanel-QIIX7S4V.mjs +342 -0
- package/dist/lib/node-esm/AssistantPanel-QIIX7S4V.mjs.map +7 -0
- package/dist/lib/node-esm/AutomationPanel-5L5NFVKU.mjs +126 -0
- package/dist/lib/node-esm/AutomationPanel-5L5NFVKU.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-B35UD3D7.mjs → chunk-HNOBZHWK.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-B35UD3D7.mjs.map → chunk-HNOBZHWK.mjs.map} +1 -1
- package/dist/lib/node-esm/{chunk-PYT2WY4B.mjs → chunk-ISJZVA2J.mjs} +2 -7
- package/dist/lib/node-esm/{chunk-PYT2WY4B.mjs.map → chunk-ISJZVA2J.mjs.map} +3 -3
- package/dist/lib/node-esm/index.mjs +277 -1011
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/meta.mjs +1 -1
- package/dist/lib/node-esm/types/index.mjs +1 -2
- package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
- package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts +8 -0
- package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts.map +1 -0
- package/dist/types/src/components/AssistantPanel/index.d.ts +3 -0
- package/dist/types/src/components/AssistantPanel/index.d.ts.map +1 -0
- package/dist/types/src/components/AssistantPanel/system-instructions.d.ts +6 -0
- package/dist/types/src/components/AssistantPanel/system-instructions.d.ts.map +1 -0
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +9 -0
- package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +1 -0
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts +6 -0
- package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts.map +1 -0
- package/dist/types/src/components/AutomationPanel/index.d.ts +3 -0
- package/dist/types/src/components/AutomationPanel/index.d.ts.map +1 -0
- package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +5 -3
- 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 +2 -5
- 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/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/testing.d.ts +12 -0
- package/dist/types/src/testing/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +3 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +3 -3
- package/dist/types/src/types/types.d.ts +0 -1
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/package.json +37 -34
- package/src/AutomationPlugin.tsx +90 -37
- package/src/components/AssistantPanel/AssistantPanel.tsx +230 -0
- package/src/components/AssistantPanel/index.ts +7 -0
- package/src/components/AssistantPanel/system-instructions.ts +166 -0
- package/src/components/AutomationPanel/AutomationPanel.stories.tsx +57 -0
- package/src/components/AutomationPanel/AutomationPanel.tsx +96 -0
- package/src/components/AutomationPanel/index.ts +7 -0
- package/src/components/TriggerEditor/TriggerEditor.stories.tsx +15 -27
- package/src/components/TriggerEditor/TriggerEditor.tsx +39 -324
- package/src/components/index.ts +2 -6
- package/src/hooks/invocation-handler.ts +6 -9
- package/src/hooks/useLocalTriggerManager.ts +2 -4
- package/src/meta.ts +1 -1
- package/src/testing/index.ts +5 -0
- package/src/testing/testing.ts +34 -0
- package/src/translations.ts +4 -1
- package/src/types/types.ts +3 -5
- 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/AutomationPanel.d.ts +0 -3
- package/dist/types/src/components/AutomationPanel.d.ts.map +0 -1
- 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/AutomationPanel.tsx +0 -23
- 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
|
@@ -2,343 +2,58 @@
|
|
|
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
|
-
trigger: FunctionTrigger
|
|
17
|
+
trigger: Omit<FunctionTrigger, 'id'>;
|
|
18
|
+
onSave?: (trigger: Omit<FunctionTrigger, 'id'>) => void;
|
|
19
|
+
onCancel?: () => void;
|
|
35
20
|
};
|
|
36
21
|
|
|
37
|
-
export const TriggerEditor = ({ space, trigger }: TriggerEditorProps) => {
|
|
22
|
+
export const TriggerEditor = ({ space, trigger, onSave, onCancel }: TriggerEditorProps) => {
|
|
38
23
|
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
39
|
-
const
|
|
40
|
-
const script = useMemo(() => scripts.find((script) => script.id === trigger.function), [trigger.function, scripts]);
|
|
41
|
-
useLocalTriggerManager(space);
|
|
24
|
+
const functions = useQuery(space, Filter.schema(FunctionType));
|
|
42
25
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
timer: t('trigger type timer'),
|
|
46
|
-
webhook: t('trigger type webhook'),
|
|
47
|
-
websocket: t('trigger type websocket'),
|
|
26
|
+
const handleSave = (values: FunctionTriggerType) => {
|
|
27
|
+
onSave?.(values);
|
|
48
28
|
};
|
|
49
29
|
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
void space.db.schemaRegistry
|
|
52
|
-
.query()
|
|
53
|
-
.then((schemas) => {
|
|
54
|
-
// TODO(zan): We should solve double adding of stored schemas in the schema registry.
|
|
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]);
|
|
61
|
-
|
|
62
|
-
// Keen an enriched version of the schema in memory so we can share it with prompt editor.
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
const spec = trigger.spec;
|
|
65
|
-
invariant(spec);
|
|
66
|
-
if (spec.type === 'subscription') {
|
|
67
|
-
if (spec.filter) {
|
|
68
|
-
const type = spec.filter.type;
|
|
69
|
-
const foundSchema = state.schemas.find((schema) => schema.typename === type);
|
|
70
|
-
if (foundSchema) {
|
|
71
|
-
state.selectedSchema[trigger.id] = foundSchema;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// TODO(burdon): API issue.
|
|
76
|
-
}, [JSON.stringify(trigger.spec), state.schemas]);
|
|
77
|
-
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (!trigger.meta) {
|
|
80
|
-
const extension = getFunctionMetaExtension(trigger, script);
|
|
81
|
-
trigger.meta = extension?.initialValue?.();
|
|
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
30
|
return (
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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>
|
|
31
|
+
<Form<FunctionTriggerType>
|
|
32
|
+
schema={FunctionTriggerSchema}
|
|
33
|
+
values={trigger}
|
|
34
|
+
filter={(props) => props.filter((p) => p.name !== 'meta')}
|
|
35
|
+
onSave={handleSave}
|
|
36
|
+
onCancel={onCancel}
|
|
37
|
+
Custom={{
|
|
38
|
+
['function' satisfies keyof FunctionTriggerType]: (props) => (
|
|
39
|
+
<SelectInput<FunctionTriggerType>
|
|
40
|
+
{...props}
|
|
41
|
+
options={functions.map(({ name }) => ({
|
|
42
|
+
value: name,
|
|
43
|
+
label: name,
|
|
44
|
+
}))}
|
|
45
|
+
/>
|
|
46
|
+
),
|
|
47
|
+
['spec.type' as const]: (props) => (
|
|
48
|
+
<SelectInput<FunctionTriggerType>
|
|
49
|
+
{...props}
|
|
50
|
+
options={Object.values(TriggerKind).map((kind) => ({
|
|
51
|
+
value: kind,
|
|
52
|
+
label: t(`trigger type ${kind}`),
|
|
53
|
+
}))}
|
|
54
|
+
/>
|
|
55
|
+
),
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
223
58
|
);
|
|
224
59
|
};
|
|
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
|
-
};
|
|
272
|
-
|
|
273
|
-
const methods = ['GET', 'POST'];
|
|
274
|
-
|
|
275
|
-
const TriggerSpecWebhook = ({ spec }: TriggerSpecProps<WebhookTrigger>) => {
|
|
276
|
-
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
277
|
-
return (
|
|
278
|
-
<>
|
|
279
|
-
<InputRow label={t('trigger method')}>
|
|
280
|
-
<Select.Root value={spec.method} onValueChange={(value) => (spec.method = value)}>
|
|
281
|
-
<Select.TriggerButton placeholder={'type'} />
|
|
282
|
-
<Select.Portal>
|
|
283
|
-
<Select.Content>
|
|
284
|
-
<Select.Viewport>
|
|
285
|
-
{methods.map((method) => (
|
|
286
|
-
<Select.Option key={method} value={method}>
|
|
287
|
-
{method}
|
|
288
|
-
</Select.Option>
|
|
289
|
-
))}
|
|
290
|
-
</Select.Viewport>
|
|
291
|
-
</Select.Content>
|
|
292
|
-
</Select.Portal>
|
|
293
|
-
</Select.Root>
|
|
294
|
-
</InputRow>
|
|
295
|
-
</>
|
|
296
|
-
);
|
|
297
|
-
};
|
|
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
|
@@ -4,9 +4,5 @@
|
|
|
4
4
|
|
|
5
5
|
import { lazy } from 'react';
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
export * from './AutomationPanel';
|
|
10
|
-
export * from './Chain';
|
|
11
|
-
export * from './PromptEditor';
|
|
12
|
-
export * from './TriggerEditor';
|
|
7
|
+
export const AssistantPanel = lazy(() => import('./AssistantPanel'));
|
|
8
|
+
export const AutomationPanel = lazy(() => import('./AutomationPanel'));
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { sleep } from '@dxos/async';
|
|
6
|
-
import { getObjectCore } from '@dxos/echo-db';
|
|
7
|
-
import {
|
|
6
|
+
import { getObjectCore, ResultFormat } from '@dxos/echo-db';
|
|
7
|
+
import type { AnyObjectData } from '@dxos/echo-schema';
|
|
8
8
|
import { type FunctionTrigger } from '@dxos/functions';
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
10
|
import { DXN, LOCAL_SPACE_TAG } from '@dxos/keys';
|
|
@@ -13,8 +13,6 @@ import { FunctionType } from '@dxos/plugin-script';
|
|
|
13
13
|
import { type Client, type Config } from '@dxos/react-client';
|
|
14
14
|
import { type Space } from '@dxos/react-client/echo';
|
|
15
15
|
|
|
16
|
-
import { handleEmail } from './email';
|
|
17
|
-
|
|
18
16
|
const MAX_RETRIES = 3;
|
|
19
17
|
const RETRY_DELAY = 1_000;
|
|
20
18
|
|
|
@@ -49,12 +47,11 @@ export const invokeFunction = async (client: Client, space: Space, trigger: Func
|
|
|
49
47
|
try {
|
|
50
48
|
invariant(trigger.spec);
|
|
51
49
|
invariant(trigger.function);
|
|
52
|
-
if (trigger.spec.type === 'websocket') {
|
|
53
|
-
return handleEmail(space, data.data);
|
|
54
|
-
}
|
|
55
50
|
|
|
56
|
-
const script = await space.
|
|
57
|
-
const { objects: functions } = await space.
|
|
51
|
+
const script = await space.db.query({ id: trigger.function }, { format: ResultFormat.Plain }).first();
|
|
52
|
+
const { objects: functions } = await space.db
|
|
53
|
+
.query({ __typename: FunctionType.typename }, { format: ResultFormat.Plain })
|
|
54
|
+
.run();
|
|
58
55
|
const func = functions.find((fn) => referenceEquals(fn.source, trigger.function!)) as AnyObjectData | undefined;
|
|
59
56
|
const funcSlug = func?.__meta.keys.find((key) => key.source === USERFUNCTIONS_META_KEY)?.id;
|
|
60
57
|
if (!funcSlug) {
|
|
@@ -6,8 +6,8 @@ import { useEffect, useState } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { Mutex } from '@dxos/async';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
|
-
import { createSubscriptionTrigger,
|
|
10
|
-
import { FunctionTrigger } from '@dxos/functions
|
|
9
|
+
import { createSubscriptionTrigger, type TriggerFactory } from '@dxos/functions';
|
|
10
|
+
import { FunctionTrigger } from '@dxos/functions';
|
|
11
11
|
import { invariant } from '@dxos/invariant';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { useClient } from '@dxos/react-client';
|
|
@@ -50,8 +50,6 @@ export const useLocalTriggerManager = (space: Space) => {
|
|
|
50
50
|
let triggerFactory: TriggerFactory<any>;
|
|
51
51
|
if (triggerSpec.type === 'subscription') {
|
|
52
52
|
triggerFactory = createSubscriptionTrigger;
|
|
53
|
-
} else if (triggerSpec.type === 'websocket') {
|
|
54
|
-
triggerFactory = createWebsocketTrigger;
|
|
55
53
|
} else {
|
|
56
54
|
log.info('unsupported trigger', { type: triggerSpec.type });
|
|
57
55
|
continue;
|
package/src/meta.ts
CHANGED
|
@@ -10,7 +10,7 @@ export default {
|
|
|
10
10
|
id: AUTOMATION_PLUGIN,
|
|
11
11
|
name: 'Automation',
|
|
12
12
|
description: 'Automation workflows.',
|
|
13
|
-
icon: 'ph--
|
|
13
|
+
icon: 'ph--magic-wand--regular',
|
|
14
14
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-automation',
|
|
15
15
|
tags: ['experimental'],
|
|
16
16
|
} satisfies PluginMeta;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { AST, S, toJsonSchema } from '@dxos/echo-schema';
|
|
6
|
+
|
|
7
|
+
export const functions = [
|
|
8
|
+
{
|
|
9
|
+
name: 'example.com/function/chess',
|
|
10
|
+
version: 1,
|
|
11
|
+
inputSchema: toJsonSchema(
|
|
12
|
+
S.Struct({
|
|
13
|
+
level: S.Number.annotations({
|
|
14
|
+
[AST.TitleAnnotationId]: 'Level',
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'example.com/function/forex',
|
|
21
|
+
version: 1,
|
|
22
|
+
binding: 'FOREX',
|
|
23
|
+
inputSchema: toJsonSchema(
|
|
24
|
+
S.Struct({
|
|
25
|
+
from: S.String.annotations({
|
|
26
|
+
[AST.TitleAnnotationId]: 'Currency from',
|
|
27
|
+
}),
|
|
28
|
+
to: S.String.annotations({
|
|
29
|
+
[AST.TitleAnnotationId]: 'Currency to',
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
),
|
|
33
|
+
},
|
|
34
|
+
];
|
package/src/translations.ts
CHANGED
|
@@ -25,15 +25,18 @@ export default [
|
|
|
25
25
|
'trigger select label': 'Trigger',
|
|
26
26
|
'trigger select placeholder': 'Trigger type',
|
|
27
27
|
|
|
28
|
-
'trigger type subscription': 'Subscription',
|
|
29
28
|
'trigger type timer': 'Timer',
|
|
30
29
|
'trigger type webhook': 'Webhook',
|
|
31
30
|
'trigger type websocket': 'Websocket',
|
|
31
|
+
'trigger type subscription': 'Subscription',
|
|
32
32
|
|
|
33
33
|
'trigger filter': 'Filter',
|
|
34
34
|
'trigger cron': 'Cron',
|
|
35
35
|
'trigger method': 'Method',
|
|
36
36
|
'trigger endpoint': 'Endpoint',
|
|
37
|
+
|
|
38
|
+
'open assistant panel label': 'Show Assistant',
|
|
39
|
+
'assistant panel label': 'Assistant',
|
|
37
40
|
},
|
|
38
41
|
},
|
|
39
42
|
},
|
package/src/types/types.ts
CHANGED
|
@@ -12,13 +12,11 @@ import type {
|
|
|
12
12
|
import { type SchemaProvides } from '@dxos/plugin-client';
|
|
13
13
|
import { type PanelProvides } from '@dxos/plugin-deck/types';
|
|
14
14
|
|
|
15
|
-
import { AUTOMATION_PLUGIN } from '../meta';
|
|
15
|
+
// import { AUTOMATION_PLUGIN } from '../meta';
|
|
16
16
|
|
|
17
|
-
const AUTOMATION_ACTION = `${AUTOMATION_PLUGIN}/action`;
|
|
17
|
+
// const AUTOMATION_ACTION = `${AUTOMATION_PLUGIN}/action`;
|
|
18
18
|
|
|
19
|
-
export enum AutomationAction {
|
|
20
|
-
CREATE = `${AUTOMATION_ACTION}/create`,
|
|
21
|
-
}
|
|
19
|
+
export enum AutomationAction {}
|
|
22
20
|
|
|
23
21
|
export type AutomationPluginProvides = SurfaceProvides &
|
|
24
22
|
IntentResolverProvides &
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PromptEditor
|
|
3
|
-
} from "./chunk-CJMV64XO.mjs";
|
|
4
|
-
import "./chunk-B3Z4NQC2.mjs";
|
|
5
|
-
import "./chunk-PQLGYMNY.mjs";
|
|
6
|
-
|
|
7
|
-
// packages/plugins/experimental/plugin-automation/src/components/PromptContainer.tsx
|
|
8
|
-
import React from "react";
|
|
9
|
-
var PromptContainer = (props) => {
|
|
10
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
11
|
-
role: "none",
|
|
12
|
-
className: "row-span-2 pli-2"
|
|
13
|
-
}, /* @__PURE__ */ React.createElement(PromptEditor, props));
|
|
14
|
-
};
|
|
15
|
-
var PromptContainer_default = PromptContainer;
|
|
16
|
-
export {
|
|
17
|
-
PromptContainer_default as default
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=PromptContainer-6CBNCUKQ.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/PromptContainer.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { PromptEditor, type PromptEditorProps } from './PromptEditor';\n\ntype PromptContainerProps = PromptEditorProps;\n\nconst PromptContainer = (props: PromptContainerProps) => {\n return (\n <div role='none' className='row-span-2 pli-2'>\n <PromptEditor {...props} />\n </div>\n );\n};\n\nexport default PromptContainer;\n"],
|
|
5
|
-
"mappings": ";;;;;;;AAIA,OAAOA,WAAW;AAMlB,IAAMC,kBAAkB,CAACC,UAAAA;AACvB,SACE,sBAAA,cAACC,OAAAA;IAAIC,MAAK;IAAOC,WAAU;KACzB,sBAAA,cAACC,cAAiBJ,KAAAA,CAAAA;AAGxB;AAEA,IAAA,0BAAeD;",
|
|
6
|
-
"names": ["React", "PromptContainer", "props", "div", "role", "className", "PromptEditor"]
|
|
7
|
-
}
|