@dxos/plugin-automation 0.7.2-main.f1adc9f → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/lib/browser/{chunk-R6GS7UA7.mjs → chunk-B3Z4NQC2.mjs} +8 -2
  2. package/dist/lib/browser/{chunk-R6GS7UA7.mjs.map → chunk-B3Z4NQC2.mjs.map} +3 -3
  3. package/dist/lib/browser/{chunk-X5KMOH3I.mjs → chunk-PQLGYMNY.mjs} +2 -2
  4. package/dist/lib/browser/{chunk-X5KMOH3I.mjs.map → chunk-PQLGYMNY.mjs.map} +1 -1
  5. package/dist/lib/browser/index.mjs +286 -109
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/meta.mjs +1 -1
  9. package/dist/lib/browser/types/index.mjs +2 -1
  10. package/dist/lib/node/{chunk-DTJ7XVO2.cjs → chunk-JSZ6PAYL.cjs} +5 -5
  11. package/dist/lib/node/{chunk-DTJ7XVO2.cjs.map → chunk-JSZ6PAYL.cjs.map} +1 -1
  12. package/dist/lib/node/{chunk-JHKEVE65.cjs → chunk-SUMUWFZA.cjs} +8 -5
  13. package/dist/lib/node/{chunk-JHKEVE65.cjs.map → chunk-SUMUWFZA.cjs.map} +3 -3
  14. package/dist/lib/node/index.cjs +313 -143
  15. package/dist/lib/node/index.cjs.map +4 -4
  16. package/dist/lib/node/meta.cjs +3 -3
  17. package/dist/lib/node/meta.cjs.map +1 -1
  18. package/dist/lib/node/meta.json +1 -1
  19. package/dist/lib/node/types/index.cjs +7 -6
  20. package/dist/lib/node/types/index.cjs.map +2 -2
  21. package/dist/lib/node-esm/{chunk-HNOBZHWK.mjs → chunk-B35UD3D7.mjs} +2 -2
  22. package/dist/lib/node-esm/{chunk-HNOBZHWK.mjs.map → chunk-B35UD3D7.mjs.map} +1 -1
  23. package/dist/lib/node-esm/{chunk-ISJZVA2J.mjs → chunk-PYT2WY4B.mjs} +7 -2
  24. package/dist/lib/node-esm/{chunk-ISJZVA2J.mjs.map → chunk-PYT2WY4B.mjs.map} +3 -3
  25. package/dist/lib/node-esm/index.mjs +286 -109
  26. package/dist/lib/node-esm/index.mjs.map +4 -4
  27. package/dist/lib/node-esm/meta.json +1 -1
  28. package/dist/lib/node-esm/meta.mjs +1 -1
  29. package/dist/lib/node-esm/types/index.mjs +2 -1
  30. package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
  31. package/dist/types/src/components/AutomationPanel.d.ts +3 -0
  32. package/dist/types/src/components/AutomationPanel.d.ts.map +1 -0
  33. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +2 -4
  34. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
  35. package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
  36. package/dist/types/src/components/index.d.ts +3 -2
  37. package/dist/types/src/components/index.d.ts.map +1 -1
  38. package/dist/types/src/translations.d.ts +0 -2
  39. package/dist/types/src/translations.d.ts.map +1 -1
  40. package/dist/types/src/types/schema.d.ts +3 -3
  41. package/dist/types/src/types/types.d.ts +1 -0
  42. package/dist/types/src/types/types.d.ts.map +1 -1
  43. package/package.json +34 -37
  44. package/src/AutomationPlugin.tsx +35 -88
  45. package/src/components/AutomationPanel.tsx +23 -0
  46. package/src/components/TriggerEditor/TriggerEditor.stories.tsx +32 -2
  47. package/src/components/TriggerEditor/TriggerEditor.tsx +43 -9
  48. package/src/components/index.ts +3 -4
  49. package/src/meta.ts +1 -1
  50. package/src/translations.ts +0 -3
  51. package/src/types/types.ts +5 -3
  52. package/dist/lib/browser/AssistantPanel-622FK3DP.mjs +0 -341
  53. package/dist/lib/browser/AssistantPanel-622FK3DP.mjs.map +0 -7
  54. package/dist/lib/browser/AutomationPanel-PVI2EJNE.mjs +0 -125
  55. package/dist/lib/browser/AutomationPanel-PVI2EJNE.mjs.map +0 -7
  56. package/dist/lib/node/AssistantPanel-HRJRVOZD.cjs +0 -361
  57. package/dist/lib/node/AssistantPanel-HRJRVOZD.cjs.map +0 -7
  58. package/dist/lib/node/AutomationPanel-Z2XW24BN.cjs +0 -145
  59. package/dist/lib/node/AutomationPanel-Z2XW24BN.cjs.map +0 -7
  60. package/dist/lib/node-esm/AssistantPanel-QIIX7S4V.mjs +0 -342
  61. package/dist/lib/node-esm/AssistantPanel-QIIX7S4V.mjs.map +0 -7
  62. package/dist/lib/node-esm/AutomationPanel-5L5NFVKU.mjs +0 -126
  63. package/dist/lib/node-esm/AutomationPanel-5L5NFVKU.mjs.map +0 -7
  64. package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts +0 -8
  65. package/dist/types/src/components/AssistantPanel/AssistantPanel.d.ts.map +0 -1
  66. package/dist/types/src/components/AssistantPanel/index.d.ts +0 -3
  67. package/dist/types/src/components/AssistantPanel/index.d.ts.map +0 -1
  68. package/dist/types/src/components/AssistantPanel/system-instructions.d.ts +0 -6
  69. package/dist/types/src/components/AssistantPanel/system-instructions.d.ts.map +0 -1
  70. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts +0 -9
  71. package/dist/types/src/components/AutomationPanel/AutomationPanel.d.ts.map +0 -1
  72. package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts +0 -6
  73. package/dist/types/src/components/AutomationPanel/AutomationPanel.stories.d.ts.map +0 -1
  74. package/dist/types/src/components/AutomationPanel/index.d.ts +0 -3
  75. package/dist/types/src/components/AutomationPanel/index.d.ts.map +0 -1
  76. package/dist/types/src/testing/index.d.ts +0 -2
  77. package/dist/types/src/testing/index.d.ts.map +0 -1
  78. package/dist/types/src/testing/testing.d.ts +0 -12
  79. package/dist/types/src/testing/testing.d.ts.map +0 -1
  80. package/src/components/AssistantPanel/AssistantPanel.tsx +0 -230
  81. package/src/components/AssistantPanel/index.ts +0 -7
  82. package/src/components/AssistantPanel/system-instructions.ts +0 -166
  83. package/src/components/AutomationPanel/AutomationPanel.stories.tsx +0 -57
  84. package/src/components/AutomationPanel/AutomationPanel.tsx +0 -96
  85. package/src/components/AutomationPanel/index.ts +0 -7
  86. package/src/testing/index.ts +0 -5
  87. package/src/testing/testing.ts +0 -34
@@ -4,26 +4,17 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { parseMetadataResolverPlugin, type PluginDefinition, resolvePlugin } from '@dxos/app-framework';
7
+ import { type PluginDefinition, parseMetadataResolverPlugin, resolvePlugin } from '@dxos/app-framework';
8
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';
12
- import { memoizeQuery } from '@dxos/plugin-space';
13
- import {
14
- getSpace,
15
- getTypename,
16
- isEchoObject,
17
- loadObjectReferences,
18
- parseId,
19
- SpaceState,
20
- } from '@dxos/react-client/echo';
21
- import { translations as formTranslations } from '@dxos/react-ui-form';
12
+ import { getTypename, loadObjectReferences, parseId } from '@dxos/react-client/echo';
22
13
 
23
- import { AssistantPanel, AutomationPanel } from './components';
14
+ import { AutomationPanel } from './components';
24
15
  import meta, { AUTOMATION_PLUGIN } from './meta';
25
16
  import translations from './translations';
26
- import { type AutomationPluginProvides, ChainPromptType, ChainType } from './types';
17
+ import { AutomationAction, type AutomationPluginProvides, ChainPromptType, ChainType } from './types';
27
18
 
28
19
  export const AutomationPlugin = (): PluginDefinition<AutomationPluginProvides> => {
29
20
  return {
@@ -39,7 +30,7 @@ export const AutomationPlugin = (): PluginDefinition<AutomationPluginProvides> =
39
30
  },
40
31
  },
41
32
  },
42
- translations: [...translations, ...formTranslations],
33
+ translations,
43
34
  echo: {
44
35
  schema: [ChainType, ChainPromptType, FunctionTrigger],
45
36
  },
@@ -48,12 +39,7 @@ export const AutomationPlugin = (): PluginDefinition<AutomationPluginProvides> =
48
39
  {
49
40
  id: 'automation',
50
41
  label: ['open automation panel label', { ns: AUTOMATION_PLUGIN }],
51
- icon: 'ph--magic-wand--regular',
52
- },
53
- {
54
- id: 'assistant',
55
- label: ['open assistant panel label', { ns: AUTOMATION_PLUGIN }],
56
- icon: 'ph--atom--regular',
42
+ icon: 'ph--flow-arrow--regular',
57
43
  },
58
44
  ],
59
45
  },
@@ -76,17 +62,11 @@ export const AutomationPlugin = (): PluginDefinition<AutomationPluginProvides> =
76
62
  }
77
63
 
78
64
  const type = 'orphan-settings-for-subject';
79
- const icon = 'ph--magic-wand--regular';
65
+ const icon = 'ph--flow-arrow--regular';
80
66
 
81
67
  const [subjectId] = id.split('~');
82
68
  const { spaceId, objectId } = parseId(subjectId);
83
- const spaces = toSignal(
84
- (onChange) => client.spaces.subscribe(() => onChange()).unsubscribe,
85
- () => client.spaces.get(),
86
- );
87
- const space = spaces?.find(
88
- (space) => space.id === spaceId && space.state.get() === SpaceState.SPACE_READY,
89
- );
69
+ const space = client.spaces.get().find((space) => space.id === spaceId);
90
70
  if (!objectId) {
91
71
  // TODO(burdon): Ref SPACE_PLUGIN ns.
92
72
  const label = space
@@ -109,7 +89,18 @@ export const AutomationPlugin = (): PluginDefinition<AutomationPluginProvides> =
109
89
  };
110
90
  }
111
91
 
112
- const [object] = memoizeQuery(space, { id: objectId });
92
+ const object = toSignal(
93
+ (onChange) => {
94
+ const timeout = setTimeout(async () => {
95
+ await space?.db.query({ id: objectId }).first();
96
+ onChange();
97
+ });
98
+
99
+ return () => clearTimeout(timeout);
100
+ },
101
+ () => space?.db.getObjectById(objectId),
102
+ subjectId,
103
+ );
113
104
  if (!object || !subjectId) {
114
105
  return;
115
106
  }
@@ -131,77 +122,33 @@ export const AutomationPlugin = (): PluginDefinition<AutomationPluginProvides> =
131
122
  };
132
123
  },
133
124
  }),
134
- createExtension({
135
- id: `${AUTOMATION_PLUGIN}/assistant-for-subject`,
136
- resolver: ({ id }) => {
137
- // TODO(Zan): Find util (or make one). Effect schema!!
138
- if (!id.endsWith('~assistant')) {
139
- return;
140
- }
141
-
142
- const [subjectId] = id.split('~');
143
- const { spaceId, objectId } = parseId(subjectId);
144
- const spaces = toSignal(
145
- (onChange) => client.spaces.subscribe(() => onChange()).unsubscribe,
146
- () => client.spaces.get(),
147
- );
148
- const space = spaces?.find(
149
- (space) => space.id === spaceId && space.state.get() === SpaceState.SPACE_READY,
150
- );
151
- if (!objectId) {
152
- // TODO(wittjosiah): Support assistant for arbitrary subjects.
153
- // This is to ensure that the assistant panel is not stuck on an old object.
154
- return {
155
- id,
156
- type: 'orphan-automation-for-subject',
157
- data: null,
158
- properties: {
159
- icon: 'ph--atom--regular',
160
- label: ['assistant panel label', { ns: AUTOMATION_PLUGIN }],
161
- object: null,
162
- space,
163
- },
164
- };
165
- }
166
-
167
- const [object] = memoizeQuery(space, { id: objectId });
168
-
169
- return {
170
- id,
171
- type: 'orphan-automation-for-subject',
172
- data: null,
173
- properties: {
174
- icon: 'ph--atom--regular',
175
- label: ['assistant panel label', { ns: AUTOMATION_PLUGIN }],
176
- object,
177
- },
178
- };
179
- },
180
- }),
181
125
  ];
182
126
  },
183
127
  },
184
128
  surface: {
185
129
  component: ({ data, role }) => {
186
130
  switch (role) {
187
- case 'complementary--assistant':
188
- return <AssistantPanel subject={data.subject as any} />;
189
- case 'complementary--automation': {
190
- const object = data.subject;
191
- const space = isEchoObject(object) ? getSpace(object) : undefined;
192
- if (space) {
193
- invariant(isEchoObject(object));
194
- return <AutomationPanel space={space} object={object} />;
195
- }
196
- break;
197
- }
131
+ // case 'article':
132
+ // return data.object instanceof ChainType ? <ChainArticle chain={data.object} /> : null;
133
+
134
+ case 'complementary--automation':
135
+ return <AutomationPanel />;
198
136
  }
199
137
 
200
138
  return null;
201
139
  },
202
140
  },
203
141
  intent: {
204
- resolver: (intent) => {},
142
+ resolver: (intent) => {
143
+ switch (intent.action) {
144
+ case AutomationAction.CREATE: {
145
+ return {
146
+ // data: create(ChainType, { prompts: [] }),
147
+ // data: create(FunctionTrigger, { function: '', spec: { type: 'timer', cron: '' } }),
148
+ };
149
+ }
150
+ }
151
+ },
205
152
  },
206
153
  },
207
154
  };
@@ -0,0 +1,23 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React from 'react';
6
+
7
+ import { Button, Icon, Toolbar } from '@dxos/react-ui';
8
+
9
+ // TODO(burdon): Form components.
10
+
11
+ export const AutomationPanel = () => {
12
+ const handleCreate = () => {};
13
+
14
+ return (
15
+ <div className='flex flex-col'>
16
+ <Toolbar.Root classNames='p-2'>
17
+ <Button onClick={handleCreate}>
18
+ <Icon icon='ph--plus--regular' />
19
+ </Button>
20
+ </Toolbar.Root>
21
+ </div>
22
+ );
23
+ };
@@ -7,7 +7,7 @@ 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';
10
+ import { AST, S, create, toJsonSchema } from '@dxos/echo-schema';
11
11
  import { FunctionTrigger, TriggerKind } from '@dxos/functions';
12
12
  import { FunctionType } from '@dxos/plugin-script/types';
13
13
  import { useSpaces } from '@dxos/react-client/echo';
@@ -15,10 +15,39 @@ import { withClientProvider } from '@dxos/react-client/testing';
15
15
  import { withLayout, withTheme } from '@dxos/storybook-utils';
16
16
 
17
17
  import { TriggerEditor } from './TriggerEditor';
18
- import { functions } from '../../testing';
19
18
  import translations from '../../translations';
20
19
  import { ChainPromptType } from '../../types';
21
20
 
21
+ // TODO(burdon): Extract type?
22
+ const functions = [
23
+ {
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
+ ),
33
+ },
34
+ {
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
+ ),
48
+ },
49
+ ];
50
+
22
51
  const DefaultStory = () => {
23
52
  const spaces = useSpaces();
24
53
  const space = spaces[1];
@@ -53,6 +82,7 @@ const meta: Meta = {
53
82
  createSpace: true,
54
83
  types: [FunctionType, FunctionTrigger, ChainPromptType],
55
84
  onSpaceCreated: ({ space }) => {
85
+ console.log(space.id);
56
86
  for (const fn of functions) {
57
87
  space.db.add(create(FunctionType, fn));
58
88
  }
@@ -14,26 +14,60 @@ import { AUTOMATION_PLUGIN } from '../../meta';
14
14
 
15
15
  export type TriggerEditorProps = {
16
16
  space: Space;
17
- trigger: Omit<FunctionTrigger, 'id'>;
18
- onSave?: (trigger: Omit<FunctionTrigger, 'id'>) => void;
19
- onCancel?: () => void;
17
+ trigger: FunctionTrigger;
20
18
  };
21
19
 
22
- export const TriggerEditor = ({ space, trigger, onSave, onCancel }: TriggerEditorProps) => {
20
+ // TODO(burdon): Functions (new def).
21
+ // TODO(burdon): Function meta (remove meta from existing trigger def).
22
+ // TODO(burdon): Actual integration.
23
+
24
+ export const TriggerEditor = ({ space, trigger }: TriggerEditorProps) => {
23
25
  const { t } = useTranslation(AUTOMATION_PLUGIN);
24
26
  const functions = useQuery(space, Filter.schema(FunctionType));
25
27
 
26
- const handleSave = (values: FunctionTriggerType) => {
27
- onSave?.(values);
28
- };
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]);
42
+
43
+ // Keen an enriched version of the schema in memory so we can share it with prompt editor.
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]);
29
65
 
30
66
  return (
31
67
  <Form<FunctionTriggerType>
32
68
  schema={FunctionTriggerSchema}
33
69
  values={trigger}
34
70
  filter={(props) => props.filter((p) => p.name !== 'meta')}
35
- onSave={handleSave}
36
- onCancel={onCancel}
37
71
  Custom={{
38
72
  ['function' satisfies keyof FunctionTriggerType]: (props) => (
39
73
  <SelectInput<FunctionTriggerType>
@@ -2,7 +2,6 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { lazy } from 'react';
6
-
7
- export const AssistantPanel = lazy(() => import('./AssistantPanel'));
8
- export const AutomationPanel = lazy(() => import('./AutomationPanel'));
5
+ export * from './AutomationPanel';
6
+ export * from './PromptEditor';
7
+ export * from './TriggerEditor';
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--magic-wand--regular',
13
+ icon: 'ph--flow-arrow--regular',
14
14
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-automation',
15
15
  tags: ['experimental'],
16
16
  } satisfies PluginMeta;
@@ -34,9 +34,6 @@ export default [
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',
40
37
  },
41
38
  },
42
39
  },
@@ -12,11 +12,13 @@ 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 {}
19
+ export enum AutomationAction {
20
+ CREATE = `${AUTOMATION_ACTION}/create`,
21
+ }
20
22
 
21
23
  export type AutomationPluginProvides = SurfaceProvides &
22
24
  IntentResolverProvides &