@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
|
@@ -1,54 +1,301 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
PromptEditor
|
|
4
|
-
} from "./chunk-62AB5HXX.mjs";
|
|
5
2
|
import {
|
|
6
3
|
AutomationAction,
|
|
7
4
|
ChainInputSchema,
|
|
8
5
|
ChainInputType,
|
|
9
6
|
ChainPromptType,
|
|
10
7
|
ChainType
|
|
11
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ISJZVA2J.mjs";
|
|
12
9
|
import {
|
|
13
10
|
AUTOMATION_PLUGIN,
|
|
14
11
|
meta_default
|
|
15
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-HNOBZHWK.mjs";
|
|
16
13
|
|
|
17
14
|
// packages/plugins/experimental/plugin-automation/src/AutomationPlugin.tsx
|
|
18
|
-
import
|
|
15
|
+
import React from "react";
|
|
19
16
|
import { parseMetadataResolverPlugin, resolvePlugin } from "@dxos/app-framework";
|
|
20
|
-
import {
|
|
21
|
-
import { invariant
|
|
17
|
+
import { FunctionTrigger } from "@dxos/functions";
|
|
18
|
+
import { invariant } from "@dxos/invariant";
|
|
22
19
|
import { parseClientPlugin } from "@dxos/plugin-client";
|
|
23
20
|
import { createExtension, toSignal } from "@dxos/plugin-graph";
|
|
24
|
-
import {
|
|
21
|
+
import { memoizeQuery } from "@dxos/plugin-space";
|
|
22
|
+
import { getSpace, getTypename, isEchoObject, loadObjectReferences, parseId, SpaceState } from "@dxos/react-client/echo";
|
|
23
|
+
import { translations as formTranslations } from "@dxos/react-ui-form";
|
|
25
24
|
|
|
26
25
|
// packages/plugins/experimental/plugin-automation/src/components/index.ts
|
|
27
26
|
import { lazy } from "react";
|
|
27
|
+
var AssistantPanel = lazy(() => import("./AssistantPanel-QIIX7S4V.mjs"));
|
|
28
|
+
var AutomationPanel = lazy(() => import("./AutomationPanel-5L5NFVKU.mjs"));
|
|
28
29
|
|
|
29
|
-
// packages/plugins/experimental/plugin-automation/src/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
// packages/plugins/experimental/plugin-automation/src/translations.ts
|
|
31
|
+
var translations_default = [
|
|
32
|
+
{
|
|
33
|
+
"en-US": {
|
|
34
|
+
[AUTOMATION_PLUGIN]: {
|
|
35
|
+
"plugin name": "Automation",
|
|
36
|
+
"object placeholder": "New prompt",
|
|
37
|
+
"create object label": "Create prompt",
|
|
38
|
+
"create trigger label": "Create trigger",
|
|
39
|
+
"create stack section label": "Create prompt",
|
|
40
|
+
"command placeholder": "Enter slash command...",
|
|
41
|
+
"template placeholder": "Enter template...",
|
|
42
|
+
"value placeholder": "Enter value...",
|
|
43
|
+
"select preset template placeholder": "Select preset",
|
|
44
|
+
"open automation panel label": "Show Automations",
|
|
45
|
+
"function select label": "Function",
|
|
46
|
+
"function select placeholder": "Select function",
|
|
47
|
+
"function enabled": "Enabled",
|
|
48
|
+
"trigger select label": "Trigger",
|
|
49
|
+
"trigger select placeholder": "Trigger type",
|
|
50
|
+
"trigger type timer": "Timer",
|
|
51
|
+
"trigger type webhook": "Webhook",
|
|
52
|
+
"trigger type websocket": "Websocket",
|
|
53
|
+
"trigger type subscription": "Subscription",
|
|
54
|
+
"trigger filter": "Filter",
|
|
55
|
+
"trigger cron": "Cron",
|
|
56
|
+
"trigger method": "Method",
|
|
57
|
+
"trigger endpoint": "Endpoint",
|
|
58
|
+
"open assistant panel label": "Show Assistant",
|
|
59
|
+
"assistant panel label": "Assistant"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
];
|
|
64
|
+
|
|
65
|
+
// packages/plugins/experimental/plugin-automation/src/AutomationPlugin.tsx
|
|
66
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/AutomationPlugin.tsx";
|
|
67
|
+
var AutomationPlugin = () => {
|
|
68
|
+
return {
|
|
69
|
+
meta: meta_default,
|
|
70
|
+
provides: {
|
|
71
|
+
metadata: {
|
|
72
|
+
records: {
|
|
73
|
+
[ChainType.typename]: {
|
|
74
|
+
placeholder: [
|
|
75
|
+
"object placeholder",
|
|
76
|
+
{
|
|
77
|
+
ns: AUTOMATION_PLUGIN
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
icon: "ph--magic-wand--regular",
|
|
81
|
+
// TODO(wittjosiah): Move out of metadata.
|
|
82
|
+
loadReferences: (chain) => loadObjectReferences(chain, (chain2) => chain2.prompts)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
translations: [
|
|
87
|
+
...translations_default,
|
|
88
|
+
...formTranslations
|
|
89
|
+
],
|
|
90
|
+
echo: {
|
|
91
|
+
schema: [
|
|
92
|
+
ChainType,
|
|
93
|
+
ChainPromptType,
|
|
94
|
+
FunctionTrigger
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
complementary: {
|
|
98
|
+
panels: [
|
|
99
|
+
{
|
|
100
|
+
id: "automation",
|
|
101
|
+
label: [
|
|
102
|
+
"open automation panel label",
|
|
103
|
+
{
|
|
104
|
+
ns: AUTOMATION_PLUGIN
|
|
105
|
+
}
|
|
106
|
+
],
|
|
107
|
+
icon: "ph--magic-wand--regular"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: "assistant",
|
|
111
|
+
label: [
|
|
112
|
+
"open assistant panel label",
|
|
113
|
+
{
|
|
114
|
+
ns: AUTOMATION_PLUGIN
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
icon: "ph--atom--regular"
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
graph: {
|
|
122
|
+
builder: (plugins) => {
|
|
123
|
+
const clientPlugin = resolvePlugin(plugins, parseClientPlugin);
|
|
124
|
+
const metadataPlugin = resolvePlugin(plugins, parseMetadataResolverPlugin);
|
|
125
|
+
const resolve = metadataPlugin?.provides.metadata.resolver;
|
|
126
|
+
const client = clientPlugin?.provides.client;
|
|
127
|
+
invariant(resolve, void 0, {
|
|
128
|
+
F: __dxlog_file,
|
|
129
|
+
L: 66,
|
|
130
|
+
S: void 0,
|
|
131
|
+
A: [
|
|
132
|
+
"resolve",
|
|
133
|
+
""
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
invariant(client, void 0, {
|
|
137
|
+
F: __dxlog_file,
|
|
138
|
+
L: 67,
|
|
139
|
+
S: void 0,
|
|
140
|
+
A: [
|
|
141
|
+
"client",
|
|
142
|
+
""
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
return [
|
|
146
|
+
// Create nodes for object settings.
|
|
147
|
+
createExtension({
|
|
148
|
+
id: `${AUTOMATION_PLUGIN}/automation-for-subject`,
|
|
149
|
+
resolver: ({ id }) => {
|
|
150
|
+
if (!id.endsWith("~automation")) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const type = "orphan-settings-for-subject";
|
|
154
|
+
const icon = "ph--magic-wand--regular";
|
|
155
|
+
const [subjectId] = id.split("~");
|
|
156
|
+
const { spaceId, objectId } = parseId(subjectId);
|
|
157
|
+
const spaces = toSignal((onChange) => client.spaces.subscribe(() => onChange()).unsubscribe, () => client.spaces.get());
|
|
158
|
+
const space = spaces?.find((space2) => space2.id === spaceId && space2.state.get() === SpaceState.SPACE_READY);
|
|
159
|
+
if (!objectId) {
|
|
160
|
+
const label2 = space ? space.properties.name || [
|
|
161
|
+
"unnamed space label",
|
|
162
|
+
{
|
|
163
|
+
ns: AUTOMATION_PLUGIN
|
|
164
|
+
}
|
|
165
|
+
] : [
|
|
166
|
+
"unnamed object settings label",
|
|
167
|
+
{
|
|
168
|
+
ns: AUTOMATION_PLUGIN
|
|
169
|
+
}
|
|
170
|
+
];
|
|
171
|
+
return {
|
|
172
|
+
id,
|
|
173
|
+
type,
|
|
174
|
+
data: null,
|
|
175
|
+
properties: {
|
|
176
|
+
icon,
|
|
177
|
+
label: label2,
|
|
178
|
+
showResolvedThreads: false,
|
|
179
|
+
object: null,
|
|
180
|
+
space
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
const [object] = memoizeQuery(space, {
|
|
185
|
+
id: objectId
|
|
186
|
+
});
|
|
187
|
+
if (!object || !subjectId) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const meta = resolve(getTypename(object) ?? "");
|
|
191
|
+
const label = meta.label?.(object) || object.name || meta.placeholder || [
|
|
192
|
+
"unnamed object settings label",
|
|
193
|
+
{
|
|
194
|
+
ns: AUTOMATION_PLUGIN
|
|
195
|
+
}
|
|
196
|
+
];
|
|
197
|
+
return {
|
|
198
|
+
id,
|
|
199
|
+
type,
|
|
200
|
+
data: null,
|
|
201
|
+
properties: {
|
|
202
|
+
icon,
|
|
203
|
+
label,
|
|
204
|
+
object
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}),
|
|
209
|
+
createExtension({
|
|
210
|
+
id: `${AUTOMATION_PLUGIN}/assistant-for-subject`,
|
|
211
|
+
resolver: ({ id }) => {
|
|
212
|
+
if (!id.endsWith("~assistant")) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const [subjectId] = id.split("~");
|
|
216
|
+
const { spaceId, objectId } = parseId(subjectId);
|
|
217
|
+
const spaces = toSignal((onChange) => client.spaces.subscribe(() => onChange()).unsubscribe, () => client.spaces.get());
|
|
218
|
+
const space = spaces?.find((space2) => space2.id === spaceId && space2.state.get() === SpaceState.SPACE_READY);
|
|
219
|
+
if (!objectId) {
|
|
220
|
+
return {
|
|
221
|
+
id,
|
|
222
|
+
type: "orphan-automation-for-subject",
|
|
223
|
+
data: null,
|
|
224
|
+
properties: {
|
|
225
|
+
icon: "ph--atom--regular",
|
|
226
|
+
label: [
|
|
227
|
+
"assistant panel label",
|
|
228
|
+
{
|
|
229
|
+
ns: AUTOMATION_PLUGIN
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
object: null,
|
|
233
|
+
space
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const [object] = memoizeQuery(space, {
|
|
238
|
+
id: objectId
|
|
239
|
+
});
|
|
240
|
+
return {
|
|
241
|
+
id,
|
|
242
|
+
type: "orphan-automation-for-subject",
|
|
243
|
+
data: null,
|
|
244
|
+
properties: {
|
|
245
|
+
icon: "ph--atom--regular",
|
|
246
|
+
label: [
|
|
247
|
+
"assistant panel label",
|
|
248
|
+
{
|
|
249
|
+
ns: AUTOMATION_PLUGIN
|
|
250
|
+
}
|
|
251
|
+
],
|
|
252
|
+
object
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
surface: {
|
|
261
|
+
component: ({ data, role }) => {
|
|
262
|
+
switch (role) {
|
|
263
|
+
case "complementary--assistant":
|
|
264
|
+
return /* @__PURE__ */ React.createElement(AssistantPanel, {
|
|
265
|
+
subject: data.subject
|
|
266
|
+
});
|
|
267
|
+
case "complementary--automation": {
|
|
268
|
+
const object = data.subject;
|
|
269
|
+
const space = isEchoObject(object) ? getSpace(object) : void 0;
|
|
270
|
+
if (space) {
|
|
271
|
+
invariant(isEchoObject(object), void 0, {
|
|
272
|
+
F: __dxlog_file,
|
|
273
|
+
L: 193,
|
|
274
|
+
S: void 0,
|
|
275
|
+
A: [
|
|
276
|
+
"isEchoObject(object)",
|
|
277
|
+
""
|
|
278
|
+
]
|
|
279
|
+
});
|
|
280
|
+
return /* @__PURE__ */ React.createElement(AutomationPanel, {
|
|
281
|
+
space,
|
|
282
|
+
object
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
intent: {
|
|
292
|
+
resolver: (intent) => {
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
34
296
|
};
|
|
35
|
-
return /* @__PURE__ */ React.createElement("div", {
|
|
36
|
-
className: "flex flex-col"
|
|
37
|
-
}, /* @__PURE__ */ React.createElement(Toolbar.Root, {
|
|
38
|
-
classNames: "p-2"
|
|
39
|
-
}, /* @__PURE__ */ React.createElement(Button, {
|
|
40
|
-
onClick: handleCreate
|
|
41
|
-
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
42
|
-
icon: "ph--plus--regular"
|
|
43
|
-
}))));
|
|
44
297
|
};
|
|
45
298
|
|
|
46
|
-
// packages/plugins/experimental/plugin-automation/src/components/Chain.tsx
|
|
47
|
-
import React2 from "react";
|
|
48
|
-
import { getSpace } from "@dxos/react-client/echo";
|
|
49
|
-
import { Select, useTranslation } from "@dxos/react-ui";
|
|
50
|
-
import { nonNullable } from "@dxos/util";
|
|
51
|
-
|
|
52
299
|
// packages/plugins/experimental/plugin-automation/src/presets.ts
|
|
53
300
|
import { create } from "@dxos/echo-schema";
|
|
54
301
|
var str = (...text) => text.filter((value) => value !== void 0 && value !== false).flat().join("\n");
|
|
@@ -267,998 +514,17 @@ var chainPresets = [
|
|
|
267
514
|
}
|
|
268
515
|
];
|
|
269
516
|
|
|
270
|
-
// packages/plugins/experimental/plugin-automation/src/components/Chain.tsx
|
|
271
|
-
var Chain = ({ chain }) => {
|
|
272
|
-
const space = getSpace(chain);
|
|
273
|
-
if (!space) {
|
|
274
|
-
return null;
|
|
275
|
-
}
|
|
276
|
-
const handleSelectPreset = (preset) => {
|
|
277
|
-
chain.name = preset.title;
|
|
278
|
-
chain.prompts?.filter(nonNullable).forEach((prompt) => space.db.remove(prompt));
|
|
279
|
-
chain.prompts = [
|
|
280
|
-
preset.createPrompt()
|
|
281
|
-
];
|
|
282
|
-
};
|
|
283
|
-
return /* @__PURE__ */ React2.createElement("div", {
|
|
284
|
-
className: "flex flex-col my-2 gap-4"
|
|
285
|
-
}, chain.prompts?.filter(nonNullable).map((prompt, i) => /* @__PURE__ */ React2.createElement(PromptEditor, {
|
|
286
|
-
key: i,
|
|
287
|
-
prompt
|
|
288
|
-
})), /* @__PURE__ */ React2.createElement("div", {
|
|
289
|
-
className: "p-2"
|
|
290
|
-
}, /* @__PURE__ */ React2.createElement(ChainPresets, {
|
|
291
|
-
presets: chainPresets,
|
|
292
|
-
onSelect: handleSelectPreset
|
|
293
|
-
})));
|
|
294
|
-
};
|
|
295
|
-
var ChainPresets = ({ presets, onSelect }) => {
|
|
296
|
-
const { t } = useTranslation(AUTOMATION_PLUGIN);
|
|
297
|
-
return /* @__PURE__ */ React2.createElement(Select.Root, {
|
|
298
|
-
onValueChange: (value) => {
|
|
299
|
-
onSelect(presets.find(({ id }) => id === value));
|
|
300
|
-
}
|
|
301
|
-
}, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
|
|
302
|
-
classNames: "w-full",
|
|
303
|
-
placeholder: t("select preset template placeholder")
|
|
304
|
-
}), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, presets.map(({ id, title }) => /* @__PURE__ */ React2.createElement(Select.Option, {
|
|
305
|
-
key: id,
|
|
306
|
-
value: id
|
|
307
|
-
}, title))))));
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
// packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/TriggerEditor.tsx
|
|
311
|
-
import React5, { useEffect as useEffect2, useMemo } from "react";
|
|
312
|
-
import { FunctionTriggerSchema } from "@dxos/functions/types";
|
|
313
|
-
import { invariant as invariant3 } from "@dxos/invariant";
|
|
314
|
-
import { ScriptType } from "@dxos/plugin-script/types";
|
|
315
|
-
import { Filter as Filter3, useQuery as useQuery2 } from "@dxos/react-client/echo";
|
|
316
|
-
import { Input as Input3, Select as Select2, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
317
|
-
import { Form, SelectInput } from "@dxos/react-ui-form";
|
|
318
|
-
import { distinctBy } from "@dxos/util";
|
|
319
|
-
|
|
320
|
-
// packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/Form.tsx
|
|
321
|
-
import React3 from "react";
|
|
322
|
-
import { Input } from "@dxos/react-ui";
|
|
323
|
-
var InputRow = ({ label, children }) => /* @__PURE__ */ React3.createElement(Input.Root, null, /* @__PURE__ */ React3.createElement("tr", null, /* @__PURE__ */ React3.createElement("td", {
|
|
324
|
-
className: "w-[80px] px-2 text-right align-top pt-3 overflow-hidden"
|
|
325
|
-
}, /* @__PURE__ */ React3.createElement(Input.Label, {
|
|
326
|
-
classNames: "truncate text-xs"
|
|
327
|
-
}, label)), /* @__PURE__ */ React3.createElement("td", {
|
|
328
|
-
className: "p-1 pr-2"
|
|
329
|
-
}, children)));
|
|
330
|
-
|
|
331
|
-
// packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/meta.tsx
|
|
332
|
-
import React4 from "react";
|
|
333
|
-
import { create as create2, getMeta as getEchoMeta } from "@dxos/echo-schema";
|
|
334
|
-
import { GameType } from "@dxos/plugin-chess/types";
|
|
335
|
-
import { FileType } from "@dxos/plugin-ipfs/types";
|
|
336
|
-
import { DocumentType } from "@dxos/plugin-markdown";
|
|
337
|
-
import { DiagramType } from "@dxos/plugin-sketch/types";
|
|
338
|
-
import { CollectionType, MessageType } from "@dxos/plugin-space";
|
|
339
|
-
import { Input as Input2 } from "@dxos/react-ui";
|
|
340
|
-
import { safeParseInt } from "@dxos/util";
|
|
341
|
-
var stateInitialValues = {
|
|
342
|
-
schemas: [
|
|
343
|
-
// TODO(burdon): Get all schema from API.
|
|
344
|
-
DocumentType,
|
|
345
|
-
FileType,
|
|
346
|
-
GameType,
|
|
347
|
-
MessageType,
|
|
348
|
-
DiagramType,
|
|
349
|
-
CollectionType
|
|
350
|
-
],
|
|
351
|
-
selectedSchema: {}
|
|
352
|
-
};
|
|
353
|
-
var state = create2(stateInitialValues);
|
|
354
|
-
var USERFUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
|
|
355
|
-
var getFunctionMetaExtension = (trigger, script) => {
|
|
356
|
-
if (script) {
|
|
357
|
-
const meta = getEchoMeta(script).keys.find((key) => key.source === USERFUNCTIONS_PRESET_META_KEY);
|
|
358
|
-
const extension = meta && metaExtensions[meta.id];
|
|
359
|
-
if (extension) {
|
|
360
|
-
return extension;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return trigger?.function ? metaExtensions[trigger.function] : metaExtensions["dxos.org/function/gpt"];
|
|
364
|
-
};
|
|
365
|
-
var DefaultMetaProps = ({ meta }) => {
|
|
366
|
-
return /* @__PURE__ */ React4.createElement(React4.Fragment, null);
|
|
367
|
-
};
|
|
368
|
-
var ChessMetaProps = ({ meta }) => {
|
|
369
|
-
if (!meta) {
|
|
370
|
-
return null;
|
|
371
|
-
}
|
|
372
|
-
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
|
|
373
|
-
label: "Level"
|
|
374
|
-
}, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
|
|
375
|
-
type: "number",
|
|
376
|
-
value: meta.level ?? 1,
|
|
377
|
-
onChange: (event) => meta.level = safeParseInt(event.target.value),
|
|
378
|
-
placeholder: "Engine strength."
|
|
379
|
-
})));
|
|
380
|
-
};
|
|
381
|
-
var EmailWorkerMetaProps = ({ meta }) => {
|
|
382
|
-
if (!meta) {
|
|
383
|
-
return null;
|
|
384
|
-
}
|
|
385
|
-
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
|
|
386
|
-
label: "Account"
|
|
387
|
-
}, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
|
|
388
|
-
value: meta.account ?? "",
|
|
389
|
-
onChange: (event) => meta.account = event.target.value,
|
|
390
|
-
placeholder: "https://"
|
|
391
|
-
})));
|
|
392
|
-
};
|
|
393
|
-
var ChainPromptMetaProps = ({ meta, triggerId }) => {
|
|
394
|
-
const schema = triggerId ? state.selectedSchema[triggerId] : void 0;
|
|
395
|
-
if (!meta) {
|
|
396
|
-
return null;
|
|
397
|
-
}
|
|
398
|
-
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
|
|
399
|
-
label: "Model"
|
|
400
|
-
}, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
|
|
401
|
-
value: meta.model ?? "",
|
|
402
|
-
onChange: (event) => meta.model = event.target.value,
|
|
403
|
-
placeholder: "llama2"
|
|
404
|
-
})), /* @__PURE__ */ React4.createElement(InputRow, {
|
|
405
|
-
label: "Presets"
|
|
406
|
-
}, /* @__PURE__ */ React4.createElement(ChainPresets, {
|
|
407
|
-
presets: chainPresets,
|
|
408
|
-
onSelect: (preset) => {
|
|
409
|
-
meta.prompt = preset.createPrompt();
|
|
410
|
-
}
|
|
411
|
-
})), meta.prompt && /* @__PURE__ */ React4.createElement(InputRow, {
|
|
412
|
-
label: "Prompt"
|
|
413
|
-
}, /* @__PURE__ */ React4.createElement(PromptEditor, {
|
|
414
|
-
prompt: meta.prompt,
|
|
415
|
-
schema
|
|
416
|
-
})));
|
|
417
|
-
};
|
|
418
|
-
var EmbeddingMetaProps = ({ meta }) => {
|
|
419
|
-
if (!meta) {
|
|
420
|
-
return null;
|
|
421
|
-
}
|
|
422
|
-
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
|
|
423
|
-
label: "Model"
|
|
424
|
-
}, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
|
|
425
|
-
value: meta.model ?? "",
|
|
426
|
-
onChange: (event) => meta.model = event.target.value,
|
|
427
|
-
placeholder: "llama2"
|
|
428
|
-
})));
|
|
429
|
-
};
|
|
430
|
-
var metaExtensions = {
|
|
431
|
-
__DEFAULT__: {
|
|
432
|
-
initialValue: () => ({}),
|
|
433
|
-
component: DefaultMetaProps
|
|
434
|
-
},
|
|
435
|
-
"dxos.org/function/chess": {
|
|
436
|
-
initialValue: () => ({
|
|
437
|
-
level: 2
|
|
438
|
-
}),
|
|
439
|
-
component: ChessMetaProps
|
|
440
|
-
},
|
|
441
|
-
"dxos.org/function/email-worker": {
|
|
442
|
-
initialValue: () => ({
|
|
443
|
-
account: "hello@dxos.network"
|
|
444
|
-
}),
|
|
445
|
-
component: EmailWorkerMetaProps
|
|
446
|
-
},
|
|
447
|
-
"dxos.org/function/gpt": {
|
|
448
|
-
initialValue: () => ({
|
|
449
|
-
model: "llama2"
|
|
450
|
-
}),
|
|
451
|
-
component: ChainPromptMetaProps
|
|
452
|
-
},
|
|
453
|
-
"dxos.org/function/embedding": {
|
|
454
|
-
initialValue: () => ({
|
|
455
|
-
model: "llama2"
|
|
456
|
-
}),
|
|
457
|
-
component: EmbeddingMetaProps
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
// packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
|
|
462
|
-
import { useEffect, useState } from "react";
|
|
463
|
-
import { Mutex } from "@dxos/async";
|
|
464
|
-
import { Context } from "@dxos/context";
|
|
465
|
-
import { createSubscriptionTrigger, createWebsocketTrigger } from "@dxos/functions";
|
|
466
|
-
import { FunctionTrigger } from "@dxos/functions/types";
|
|
467
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
468
|
-
import { log as log3 } from "@dxos/log";
|
|
469
|
-
import { useClient } from "@dxos/react-client";
|
|
470
|
-
import { Filter as Filter2, useQuery } from "@dxos/react-client/echo";
|
|
471
|
-
|
|
472
|
-
// packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts
|
|
473
|
-
import { sleep } from "@dxos/async";
|
|
474
|
-
import { getObjectCore } from "@dxos/echo-db";
|
|
475
|
-
import { invariant } from "@dxos/invariant";
|
|
476
|
-
import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
|
|
477
|
-
import { log as log2 } from "@dxos/log";
|
|
478
|
-
import { FunctionType } from "@dxos/plugin-script";
|
|
479
|
-
|
|
480
|
-
// packages/plugins/experimental/plugin-automation/src/hooks/email.ts
|
|
481
|
-
import { findObjectWithForeignKey } from "@dxos/echo-db";
|
|
482
|
-
import { create as create3, foreignKey } from "@dxos/echo-schema";
|
|
483
|
-
import { log } from "@dxos/log";
|
|
484
|
-
import { MailboxType } from "@dxos/plugin-inbox/types";
|
|
485
|
-
import { MessageType as MessageType2 } from "@dxos/plugin-space/types";
|
|
486
|
-
import { Filter } from "@dxos/react-client/echo";
|
|
487
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/email.ts";
|
|
488
|
-
var SOURCE_ID = "hub.dxos.network/api/mailbox";
|
|
489
|
-
var handleEmail = async (space, data) => {
|
|
490
|
-
const { messages } = data;
|
|
491
|
-
const { objects: mailboxes } = await space.db.query(Filter.schema(MailboxType)).run();
|
|
492
|
-
const mailbox = mailboxes[0] ?? space.db.add(create3(MailboxType, {
|
|
493
|
-
messages: []
|
|
494
|
-
}));
|
|
495
|
-
log.info("messages", {
|
|
496
|
-
count: messages.length,
|
|
497
|
-
existingMailbox: mailboxes.length > 0
|
|
498
|
-
}, {
|
|
499
|
-
F: __dxlog_file,
|
|
500
|
-
L: 21,
|
|
501
|
-
S: void 0,
|
|
502
|
-
C: (f, a) => f(...a)
|
|
503
|
-
});
|
|
504
|
-
const { objects } = await space.db.query(Filter.schema(MessageType2)).run();
|
|
505
|
-
for (const message of messages) {
|
|
506
|
-
let object = findObjectWithForeignKey(objects, {
|
|
507
|
-
source: SOURCE_ID,
|
|
508
|
-
id: String(message.id)
|
|
509
|
-
});
|
|
510
|
-
if (!object) {
|
|
511
|
-
object = space.db.add(create3(MessageType2, {
|
|
512
|
-
sender: {
|
|
513
|
-
email: message.from
|
|
514
|
-
},
|
|
515
|
-
timestamp: new Date(message.created).toISOString(),
|
|
516
|
-
text: message.body,
|
|
517
|
-
properties: {
|
|
518
|
-
subject: message.subject,
|
|
519
|
-
to: [
|
|
520
|
-
{
|
|
521
|
-
email: message.to
|
|
522
|
-
}
|
|
523
|
-
]
|
|
524
|
-
}
|
|
525
|
-
}, {
|
|
526
|
-
keys: [
|
|
527
|
-
foreignKey(SOURCE_ID, String(message.id))
|
|
528
|
-
]
|
|
529
|
-
}));
|
|
530
|
-
mailbox.messages?.push(object);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
return 200;
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
// packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts
|
|
537
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts";
|
|
538
|
-
var MAX_RETRIES = 3;
|
|
539
|
-
var RETRY_DELAY = 1e3;
|
|
540
|
-
var callFunction = async (funcUrl, trigger, data) => {
|
|
541
|
-
const body = {
|
|
542
|
-
event: "trigger",
|
|
543
|
-
trigger,
|
|
544
|
-
data
|
|
545
|
-
};
|
|
546
|
-
let retryCount = 0;
|
|
547
|
-
while (retryCount < MAX_RETRIES) {
|
|
548
|
-
log2.info("exec", {
|
|
549
|
-
funcUrl,
|
|
550
|
-
body,
|
|
551
|
-
retryCount
|
|
552
|
-
}, {
|
|
553
|
-
F: __dxlog_file2,
|
|
554
|
-
L: 26,
|
|
555
|
-
S: void 0,
|
|
556
|
-
C: (f, a) => f(...a)
|
|
557
|
-
});
|
|
558
|
-
const response = await fetch(funcUrl, {
|
|
559
|
-
method: "POST",
|
|
560
|
-
headers: {
|
|
561
|
-
"Content-Type": "application/json"
|
|
562
|
-
},
|
|
563
|
-
body: JSON.stringify(body)
|
|
564
|
-
});
|
|
565
|
-
const data2 = await response.text();
|
|
566
|
-
log2.info("response", {
|
|
567
|
-
status: response.status,
|
|
568
|
-
body: data2
|
|
569
|
-
}, {
|
|
570
|
-
F: __dxlog_file2,
|
|
571
|
-
L: 36,
|
|
572
|
-
S: void 0,
|
|
573
|
-
C: (f, a) => f(...a)
|
|
574
|
-
});
|
|
575
|
-
if (response.status === 409) {
|
|
576
|
-
retryCount++;
|
|
577
|
-
await sleep(RETRY_DELAY * Math.min(retryCount, 2));
|
|
578
|
-
continue;
|
|
579
|
-
}
|
|
580
|
-
return {
|
|
581
|
-
status: response.status,
|
|
582
|
-
data: data2
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
return {
|
|
586
|
-
status: 500
|
|
587
|
-
};
|
|
588
|
-
};
|
|
589
|
-
var invokeFunction = async (client, space, trigger, data) => {
|
|
590
|
-
try {
|
|
591
|
-
invariant(trigger.spec, void 0, {
|
|
592
|
-
F: __dxlog_file2,
|
|
593
|
-
L: 50,
|
|
594
|
-
S: void 0,
|
|
595
|
-
A: [
|
|
596
|
-
"trigger.spec",
|
|
597
|
-
""
|
|
598
|
-
]
|
|
599
|
-
});
|
|
600
|
-
invariant(trigger.function, void 0, {
|
|
601
|
-
F: __dxlog_file2,
|
|
602
|
-
L: 51,
|
|
603
|
-
S: void 0,
|
|
604
|
-
A: [
|
|
605
|
-
"trigger.function",
|
|
606
|
-
""
|
|
607
|
-
]
|
|
608
|
-
});
|
|
609
|
-
if (trigger.spec.type === "websocket") {
|
|
610
|
-
return handleEmail(space, data.data);
|
|
611
|
-
}
|
|
612
|
-
const script = await space.crud.query({
|
|
613
|
-
id: trigger.function
|
|
614
|
-
}).first();
|
|
615
|
-
const { objects: functions } = await space.crud.query({
|
|
616
|
-
__typename: FunctionType.typename
|
|
617
|
-
}).run();
|
|
618
|
-
const func = functions.find((fn) => referenceEquals(fn.source, trigger.function));
|
|
619
|
-
const funcSlug = func?.__meta.keys.find((key) => key.source === USERFUNCTIONS_META_KEY)?.id;
|
|
620
|
-
if (!funcSlug) {
|
|
621
|
-
log2.warn("function not deployed", {
|
|
622
|
-
scriptId: script.id,
|
|
623
|
-
name: script.name
|
|
624
|
-
}, {
|
|
625
|
-
F: __dxlog_file2,
|
|
626
|
-
L: 61,
|
|
627
|
-
S: void 0,
|
|
628
|
-
C: (f, a) => f(...a)
|
|
629
|
-
});
|
|
630
|
-
return 404;
|
|
631
|
-
}
|
|
632
|
-
const funcUrl = getFunctionUrl(client.config, funcSlug, space.id);
|
|
633
|
-
const triggerData = {
|
|
634
|
-
...getObjectCore(trigger).toPlainObject(),
|
|
635
|
-
// TODO: Remove when functions can query by DXN.
|
|
636
|
-
promptId: trigger.meta?.prompt?.id
|
|
637
|
-
};
|
|
638
|
-
return (await callFunction(funcUrl, triggerData, data)).status;
|
|
639
|
-
} catch (err) {
|
|
640
|
-
return 400;
|
|
641
|
-
}
|
|
642
|
-
};
|
|
643
|
-
var USERFUNCTIONS_META_KEY = "dxos.org/service/function";
|
|
644
|
-
var getFunctionUrl = (config, slug, spaceId) => {
|
|
645
|
-
const baseUrl = new URL("functions/", config.values.runtime?.services?.edge?.url);
|
|
646
|
-
const relativeUrl = slug.replace(/^\//, "");
|
|
647
|
-
const url = new URL(`./${relativeUrl}`, baseUrl.toString());
|
|
648
|
-
spaceId && url.searchParams.set("spaceId", spaceId);
|
|
649
|
-
url.protocol = "https";
|
|
650
|
-
return url.toString();
|
|
651
|
-
};
|
|
652
|
-
var referenceEquals = (a, b) => {
|
|
653
|
-
const aDXN = toDXN(a);
|
|
654
|
-
const bDXN = toDXN(b);
|
|
655
|
-
return aDXN.toString() === bDXN.toString();
|
|
656
|
-
};
|
|
657
|
-
var toDXN = (ref) => {
|
|
658
|
-
if (typeof ref === "string") {
|
|
659
|
-
if (ref.startsWith("dxn:")) {
|
|
660
|
-
return DXN.parse(ref);
|
|
661
|
-
} else {
|
|
662
|
-
return new DXN(DXN.kind.ECHO, [
|
|
663
|
-
LOCAL_SPACE_TAG,
|
|
664
|
-
ref
|
|
665
|
-
]);
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
invariant(typeof ref["/"] === "string", void 0, {
|
|
669
|
-
F: __dxlog_file2,
|
|
670
|
-
L: 110,
|
|
671
|
-
S: void 0,
|
|
672
|
-
A: [
|
|
673
|
-
"typeof ref['/'] === 'string'",
|
|
674
|
-
""
|
|
675
|
-
]
|
|
676
|
-
});
|
|
677
|
-
return DXN.parse(ref["/"]);
|
|
678
|
-
};
|
|
679
|
-
|
|
680
|
-
// packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
|
|
681
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts";
|
|
682
|
-
var registerTriggersMutex = new Mutex();
|
|
683
|
-
var useLocalTriggerManager = (space) => {
|
|
684
|
-
const client = useClient();
|
|
685
|
-
const [registry] = useState(/* @__PURE__ */ new Map());
|
|
686
|
-
const triggers = useQuery(space, Filter2.schema(FunctionTrigger));
|
|
687
|
-
useEffect(() => {
|
|
688
|
-
setTimeout(async () => {
|
|
689
|
-
await registerTriggersMutex.executeSynchronized(async () => {
|
|
690
|
-
const deprecated = new Set(Array.from(registry.keys()));
|
|
691
|
-
log3("triggers", {
|
|
692
|
-
deprecated,
|
|
693
|
-
all: triggers.map((t) => t.id),
|
|
694
|
-
enabled: triggers.filter((t) => t.enabled).map((t) => t.id)
|
|
695
|
-
}, {
|
|
696
|
-
F: __dxlog_file3,
|
|
697
|
-
L: 31,
|
|
698
|
-
S: void 0,
|
|
699
|
-
C: (f, a) => f(...a)
|
|
700
|
-
});
|
|
701
|
-
for (const trigger of triggers) {
|
|
702
|
-
if (trigger.enabled) {
|
|
703
|
-
if (registry.has(trigger.id)) {
|
|
704
|
-
deprecated.delete(trigger.id);
|
|
705
|
-
continue;
|
|
706
|
-
}
|
|
707
|
-
log3.info("activating trigger", trigger.id, {
|
|
708
|
-
F: __dxlog_file3,
|
|
709
|
-
L: 43,
|
|
710
|
-
S: void 0,
|
|
711
|
-
C: (f, a) => f(...a)
|
|
712
|
-
});
|
|
713
|
-
const ctx = new Context(void 0, {
|
|
714
|
-
F: __dxlog_file3,
|
|
715
|
-
L: 45
|
|
716
|
-
});
|
|
717
|
-
registry.set(trigger.id, ctx);
|
|
718
|
-
const triggerSpec = trigger.spec;
|
|
719
|
-
invariant2(triggerSpec, void 0, {
|
|
720
|
-
F: __dxlog_file3,
|
|
721
|
-
L: 48,
|
|
722
|
-
S: void 0,
|
|
723
|
-
A: [
|
|
724
|
-
"triggerSpec",
|
|
725
|
-
""
|
|
726
|
-
]
|
|
727
|
-
});
|
|
728
|
-
let triggerFactory;
|
|
729
|
-
if (triggerSpec.type === "subscription") {
|
|
730
|
-
triggerFactory = createSubscriptionTrigger;
|
|
731
|
-
} else if (triggerSpec.type === "websocket") {
|
|
732
|
-
triggerFactory = createWebsocketTrigger;
|
|
733
|
-
} else {
|
|
734
|
-
log3.info("unsupported trigger", {
|
|
735
|
-
type: triggerSpec.type
|
|
736
|
-
}, {
|
|
737
|
-
F: __dxlog_file3,
|
|
738
|
-
L: 56,
|
|
739
|
-
S: void 0,
|
|
740
|
-
C: (f, a) => f(...a)
|
|
741
|
-
});
|
|
742
|
-
continue;
|
|
743
|
-
}
|
|
744
|
-
await triggerFactory(ctx, space, trigger.spec, (data) => {
|
|
745
|
-
return invokeFunction(client, space, trigger, data);
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
for (const id of deprecated) {
|
|
750
|
-
const ctx = registry.get(id);
|
|
751
|
-
if (ctx) {
|
|
752
|
-
await ctx.dispose();
|
|
753
|
-
registry.delete(id);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
});
|
|
757
|
-
});
|
|
758
|
-
}, [
|
|
759
|
-
JSON.stringify(triggers)
|
|
760
|
-
]);
|
|
761
|
-
useEffect(() => {
|
|
762
|
-
return () => {
|
|
763
|
-
for (const ctx of registry.values()) {
|
|
764
|
-
void ctx.dispose();
|
|
765
|
-
}
|
|
766
|
-
};
|
|
767
|
-
}, []);
|
|
768
|
-
};
|
|
769
|
-
|
|
770
|
-
// packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/TriggerEditor.tsx
|
|
771
|
-
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/TriggerEditor.tsx";
|
|
772
|
-
var triggerTypes = [
|
|
773
|
-
"timer",
|
|
774
|
-
"webhook",
|
|
775
|
-
"websocket",
|
|
776
|
-
"subscription"
|
|
777
|
-
];
|
|
778
|
-
var TriggerEditor = ({ space, trigger }) => {
|
|
779
|
-
const { t } = useTranslation2(AUTOMATION_PLUGIN);
|
|
780
|
-
const scripts = useQuery2(space, Filter3.schema(ScriptType));
|
|
781
|
-
const script = useMemo(() => scripts.find((script2) => script2.id === trigger.function), [
|
|
782
|
-
trigger.function,
|
|
783
|
-
scripts
|
|
784
|
-
]);
|
|
785
|
-
useLocalTriggerManager(space);
|
|
786
|
-
const triggerLabels = {
|
|
787
|
-
subscription: t("trigger type subscription"),
|
|
788
|
-
timer: t("trigger type timer"),
|
|
789
|
-
webhook: t("trigger type webhook"),
|
|
790
|
-
websocket: t("trigger type websocket")
|
|
791
|
-
};
|
|
792
|
-
useEffect2(() => {
|
|
793
|
-
void space.db.schemaRegistry.query().then((schemas) => {
|
|
794
|
-
state.schemas = distinctBy([
|
|
795
|
-
...state.schemas,
|
|
796
|
-
...schemas
|
|
797
|
-
], (schema) => schema.typename).sort((a, b) => a.typename < b.typename ? -1 : 1);
|
|
798
|
-
}).catch(() => {
|
|
799
|
-
});
|
|
800
|
-
}, [
|
|
801
|
-
space
|
|
802
|
-
]);
|
|
803
|
-
useEffect2(() => {
|
|
804
|
-
const spec = trigger.spec;
|
|
805
|
-
invariant3(spec, void 0, {
|
|
806
|
-
F: __dxlog_file4,
|
|
807
|
-
L: 65,
|
|
808
|
-
S: void 0,
|
|
809
|
-
A: [
|
|
810
|
-
"spec",
|
|
811
|
-
""
|
|
812
|
-
]
|
|
813
|
-
});
|
|
814
|
-
if (spec.type === "subscription") {
|
|
815
|
-
if (spec.filter) {
|
|
816
|
-
const type = spec.filter.type;
|
|
817
|
-
const foundSchema = state.schemas.find((schema) => schema.typename === type);
|
|
818
|
-
if (foundSchema) {
|
|
819
|
-
state.selectedSchema[trigger.id] = foundSchema;
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
}, [
|
|
824
|
-
JSON.stringify(trigger.spec),
|
|
825
|
-
state.schemas
|
|
826
|
-
]);
|
|
827
|
-
useEffect2(() => {
|
|
828
|
-
if (!trigger.meta) {
|
|
829
|
-
const extension = getFunctionMetaExtension(trigger, script);
|
|
830
|
-
trigger.meta = extension?.initialValue?.();
|
|
831
|
-
}
|
|
832
|
-
}, [
|
|
833
|
-
trigger.function,
|
|
834
|
-
trigger.meta
|
|
835
|
-
]);
|
|
836
|
-
const handleSelectFunction = (value) => {
|
|
837
|
-
const match = scripts.find((fn) => fn.id === value);
|
|
838
|
-
if (match) {
|
|
839
|
-
trigger.function = match.id;
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
const handleSelectTriggerType = (triggerType) => {
|
|
843
|
-
switch (triggerType) {
|
|
844
|
-
case "subscription": {
|
|
845
|
-
trigger.spec = {
|
|
846
|
-
type: "subscription",
|
|
847
|
-
filter: {}
|
|
848
|
-
};
|
|
849
|
-
break;
|
|
850
|
-
}
|
|
851
|
-
case "timer": {
|
|
852
|
-
trigger.spec = {
|
|
853
|
-
type: "timer",
|
|
854
|
-
cron: "0 0 * * *"
|
|
855
|
-
};
|
|
856
|
-
break;
|
|
857
|
-
}
|
|
858
|
-
case "webhook": {
|
|
859
|
-
trigger.spec = {
|
|
860
|
-
type: "webhook",
|
|
861
|
-
method: "GET"
|
|
862
|
-
};
|
|
863
|
-
break;
|
|
864
|
-
}
|
|
865
|
-
case "websocket": {
|
|
866
|
-
trigger.spec = {
|
|
867
|
-
type: "websocket",
|
|
868
|
-
url: "",
|
|
869
|
-
init: {
|
|
870
|
-
type: "sync"
|
|
871
|
-
}
|
|
872
|
-
};
|
|
873
|
-
break;
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
const TriggerMeta = getFunctionMetaExtension(trigger, script)?.component;
|
|
878
|
-
const test = true;
|
|
879
|
-
if (test) {
|
|
880
|
-
const object = {
|
|
881
|
-
spec: {
|
|
882
|
-
// type: 'timer',
|
|
883
|
-
type: "subscription",
|
|
884
|
-
// cron: '0 0 * * *'
|
|
885
|
-
filter: {
|
|
886
|
-
type: "dxos.org/type/Event"
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
};
|
|
890
|
-
return /* @__PURE__ */ React5.createElement(Form, {
|
|
891
|
-
schema: FunctionTriggerSchema,
|
|
892
|
-
values: object,
|
|
893
|
-
filter: (props) => props.filter((p) => p.name !== "meta"),
|
|
894
|
-
Custom: {
|
|
895
|
-
["function"]: (props) => /* @__PURE__ */ React5.createElement(SelectInput, {
|
|
896
|
-
...props,
|
|
897
|
-
// TODO(burdon): Query for functions.
|
|
898
|
-
options: [].map((value) => ({
|
|
899
|
-
value,
|
|
900
|
-
label: value
|
|
901
|
-
}))
|
|
902
|
-
}),
|
|
903
|
-
["spec.type"]: (props) => /* @__PURE__ */ React5.createElement(SelectInput, {
|
|
904
|
-
...props,
|
|
905
|
-
options: [
|
|
906
|
-
"timer",
|
|
907
|
-
"subscription"
|
|
908
|
-
].map((value) => ({
|
|
909
|
-
value,
|
|
910
|
-
label: value
|
|
911
|
-
}))
|
|
912
|
-
})
|
|
913
|
-
}
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
return /* @__PURE__ */ React5.createElement("div", {
|
|
917
|
-
className: "flex flex-col py-1"
|
|
918
|
-
}, /* @__PURE__ */ React5.createElement("table", {
|
|
919
|
-
className: "is-full table-fixed"
|
|
920
|
-
}, /* @__PURE__ */ React5.createElement("tbody", null, /* @__PURE__ */ React5.createElement(InputRow, {
|
|
921
|
-
label: t("function select label")
|
|
922
|
-
}, /* @__PURE__ */ React5.createElement(Select2.Root, {
|
|
923
|
-
value: script?.id,
|
|
924
|
-
onValueChange: handleSelectFunction
|
|
925
|
-
}, /* @__PURE__ */ React5.createElement(Select2.TriggerButton, {
|
|
926
|
-
classNames: "w-full",
|
|
927
|
-
placeholder: t("function select placeholder")
|
|
928
|
-
}), /* @__PURE__ */ React5.createElement(Select2.Portal, null, /* @__PURE__ */ React5.createElement(Select2.Content, null, /* @__PURE__ */ React5.createElement(Select2.Viewport, null, scripts.map(({ id, name }) => /* @__PURE__ */ React5.createElement(Select2.Option, {
|
|
929
|
-
key: id,
|
|
930
|
-
value: id
|
|
931
|
-
}, name ?? id))))))), script?.description?.length && /* @__PURE__ */ React5.createElement(InputRow, null, /* @__PURE__ */ React5.createElement("div", {
|
|
932
|
-
className: "px-2"
|
|
933
|
-
}, /* @__PURE__ */ React5.createElement("p", {
|
|
934
|
-
className: "text-sm text-description"
|
|
935
|
-
}, script?.description?.length))), /* @__PURE__ */ React5.createElement(InputRow, {
|
|
936
|
-
label: t("trigger select label")
|
|
937
|
-
}, /* @__PURE__ */ React5.createElement(Select2.Root, {
|
|
938
|
-
value: trigger.spec?.type,
|
|
939
|
-
onValueChange: handleSelectTriggerType
|
|
940
|
-
}, /* @__PURE__ */ React5.createElement(Select2.TriggerButton, {
|
|
941
|
-
placeholder: t("trigger select placeholder")
|
|
942
|
-
}), /* @__PURE__ */ React5.createElement(Select2.Portal, null, /* @__PURE__ */ React5.createElement(Select2.Content, null, /* @__PURE__ */ React5.createElement(Select2.Viewport, null, triggerTypes.map((trigger2) => /* @__PURE__ */ React5.createElement(Select2.Option, {
|
|
943
|
-
key: trigger2,
|
|
944
|
-
value: trigger2
|
|
945
|
-
}, triggerLabels[trigger2])))))))), /* @__PURE__ */ React5.createElement("tbody", null, trigger.spec && /* @__PURE__ */ React5.createElement(TriggerType, {
|
|
946
|
-
space,
|
|
947
|
-
spec: trigger.spec
|
|
948
|
-
}), /* @__PURE__ */ React5.createElement(InputRow, {
|
|
949
|
-
label: t("function enabled")
|
|
950
|
-
}, /* @__PURE__ */ React5.createElement("div", {
|
|
951
|
-
className: "flex items-center h-8"
|
|
952
|
-
}, /* @__PURE__ */ React5.createElement(Input3.Switch, {
|
|
953
|
-
checked: trigger.enabled,
|
|
954
|
-
onCheckedChange: (checked) => trigger.enabled = !!checked
|
|
955
|
-
})))), TriggerMeta && trigger.meta && /* @__PURE__ */ React5.createElement("tbody", null, /* @__PURE__ */ React5.createElement("tr", null, /* @__PURE__ */ React5.createElement("td", null), /* @__PURE__ */ React5.createElement("td", {
|
|
956
|
-
className: "py-2"
|
|
957
|
-
}, /* @__PURE__ */ React5.createElement("div", {
|
|
958
|
-
className: "border-b border-separator"
|
|
959
|
-
}))), /* @__PURE__ */ React5.createElement(TriggerMeta, {
|
|
960
|
-
meta: trigger.meta
|
|
961
|
-
}))));
|
|
962
|
-
};
|
|
963
|
-
var TriggerSpecSubscription = ({ spec }) => {
|
|
964
|
-
const { t } = useTranslation2(AUTOMATION_PLUGIN);
|
|
965
|
-
if (!spec.filter) {
|
|
966
|
-
return null;
|
|
967
|
-
}
|
|
968
|
-
const handleValueChange = (typename) => {
|
|
969
|
-
spec.filter = {
|
|
970
|
-
type: typename
|
|
971
|
-
};
|
|
972
|
-
};
|
|
973
|
-
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(InputRow, {
|
|
974
|
-
label: t("trigger filter")
|
|
975
|
-
}, /* @__PURE__ */ React5.createElement(Select2.Root, {
|
|
976
|
-
value: spec.filter?.type,
|
|
977
|
-
onValueChange: handleValueChange
|
|
978
|
-
}, /* @__PURE__ */ React5.createElement(Select2.TriggerButton, {
|
|
979
|
-
classNames: "w-full",
|
|
980
|
-
placeholder: "Select type"
|
|
981
|
-
}), /* @__PURE__ */ React5.createElement(Select2.Portal, null, /* @__PURE__ */ React5.createElement(Select2.Content, null, /* @__PURE__ */ React5.createElement(Select2.Viewport, null, state.schemas.map(({ typename }) => /* @__PURE__ */ React5.createElement(Select2.Option, {
|
|
982
|
-
key: typename,
|
|
983
|
-
value: typename
|
|
984
|
-
}, typename))))))));
|
|
985
|
-
};
|
|
986
|
-
var TriggerSpecTimer = ({ spec }) => {
|
|
987
|
-
const { t } = useTranslation2(AUTOMATION_PLUGIN);
|
|
988
|
-
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(InputRow, {
|
|
989
|
-
label: t("trigger cron")
|
|
990
|
-
}, /* @__PURE__ */ React5.createElement(Input3.TextInput, {
|
|
991
|
-
value: spec.cron,
|
|
992
|
-
onChange: (event) => spec.cron = event.target.value
|
|
993
|
-
})));
|
|
994
|
-
};
|
|
995
|
-
var methods = [
|
|
996
|
-
"GET",
|
|
997
|
-
"POST"
|
|
998
|
-
];
|
|
999
|
-
var TriggerSpecWebhook = ({ spec }) => {
|
|
1000
|
-
const { t } = useTranslation2(AUTOMATION_PLUGIN);
|
|
1001
|
-
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(InputRow, {
|
|
1002
|
-
label: t("trigger method")
|
|
1003
|
-
}, /* @__PURE__ */ React5.createElement(Select2.Root, {
|
|
1004
|
-
value: spec.method,
|
|
1005
|
-
onValueChange: (value) => spec.method = value
|
|
1006
|
-
}, /* @__PURE__ */ React5.createElement(Select2.TriggerButton, {
|
|
1007
|
-
placeholder: "type"
|
|
1008
|
-
}), /* @__PURE__ */ React5.createElement(Select2.Portal, null, /* @__PURE__ */ React5.createElement(Select2.Content, null, /* @__PURE__ */ React5.createElement(Select2.Viewport, null, methods.map((method) => /* @__PURE__ */ React5.createElement(Select2.Option, {
|
|
1009
|
-
key: method,
|
|
1010
|
-
value: method
|
|
1011
|
-
}, method))))))));
|
|
1012
|
-
};
|
|
1013
|
-
var TriggerSpecWebsocket = ({ spec }) => {
|
|
1014
|
-
const { t } = useTranslation2(AUTOMATION_PLUGIN);
|
|
1015
|
-
const handleChangeInit = (event) => {
|
|
1016
|
-
try {
|
|
1017
|
-
spec.init = JSON.parse(event.target.value);
|
|
1018
|
-
} catch (err) {
|
|
1019
|
-
}
|
|
1020
|
-
};
|
|
1021
|
-
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(InputRow, {
|
|
1022
|
-
label: t("trigger method")
|
|
1023
|
-
}, /* @__PURE__ */ React5.createElement(Input3.TextInput, {
|
|
1024
|
-
value: spec.url,
|
|
1025
|
-
onChange: (event) => spec.url = event.target.value,
|
|
1026
|
-
placeholder: "https://"
|
|
1027
|
-
})), /* @__PURE__ */ React5.createElement(InputRow, {
|
|
1028
|
-
label: "Init"
|
|
1029
|
-
}, /* @__PURE__ */ React5.createElement(Input3.TextInput, {
|
|
1030
|
-
value: JSON.stringify(spec.init),
|
|
1031
|
-
onChange: handleChangeInit,
|
|
1032
|
-
placeholder: "Initial message."
|
|
1033
|
-
})));
|
|
1034
|
-
};
|
|
1035
|
-
var triggerRenderers = {
|
|
1036
|
-
subscription: TriggerSpecSubscription,
|
|
1037
|
-
timer: TriggerSpecTimer,
|
|
1038
|
-
webhook: TriggerSpecWebhook,
|
|
1039
|
-
websocket: TriggerSpecWebsocket
|
|
1040
|
-
};
|
|
1041
|
-
var TriggerType = ({ space, spec }) => {
|
|
1042
|
-
const Component = triggerRenderers[spec.type];
|
|
1043
|
-
return Component ? /* @__PURE__ */ React5.createElement(Component, {
|
|
1044
|
-
space,
|
|
1045
|
-
spec
|
|
1046
|
-
}) : null;
|
|
1047
|
-
};
|
|
1048
|
-
|
|
1049
|
-
// packages/plugins/experimental/plugin-automation/src/components/index.ts
|
|
1050
|
-
var PromptContainer = lazy(() => import("./PromptContainer-4SCHQV5C.mjs"));
|
|
1051
|
-
|
|
1052
|
-
// packages/plugins/experimental/plugin-automation/src/translations.ts
|
|
1053
|
-
var translations_default = [
|
|
1054
|
-
{
|
|
1055
|
-
"en-US": {
|
|
1056
|
-
[AUTOMATION_PLUGIN]: {
|
|
1057
|
-
"plugin name": "Automation",
|
|
1058
|
-
"object placeholder": "New prompt",
|
|
1059
|
-
"create object label": "Create prompt",
|
|
1060
|
-
"create trigger label": "Create trigger",
|
|
1061
|
-
"create stack section label": "Create prompt",
|
|
1062
|
-
"command placeholder": "Enter slash command...",
|
|
1063
|
-
"template placeholder": "Enter template...",
|
|
1064
|
-
"value placeholder": "Enter value...",
|
|
1065
|
-
"select preset template placeholder": "Select preset",
|
|
1066
|
-
"open automation panel label": "Show Automations",
|
|
1067
|
-
"function select label": "Function",
|
|
1068
|
-
"function select placeholder": "Select function",
|
|
1069
|
-
"function enabled": "Enabled",
|
|
1070
|
-
"trigger select label": "Trigger",
|
|
1071
|
-
"trigger select placeholder": "Trigger type",
|
|
1072
|
-
"trigger type subscription": "Subscription",
|
|
1073
|
-
"trigger type timer": "Timer",
|
|
1074
|
-
"trigger type webhook": "Webhook",
|
|
1075
|
-
"trigger type websocket": "Websocket",
|
|
1076
|
-
"trigger filter": "Filter",
|
|
1077
|
-
"trigger cron": "Cron",
|
|
1078
|
-
"trigger method": "Method",
|
|
1079
|
-
"trigger endpoint": "Endpoint"
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
];
|
|
1084
|
-
|
|
1085
|
-
// packages/plugins/experimental/plugin-automation/src/AutomationPlugin.tsx
|
|
1086
|
-
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/AutomationPlugin.tsx";
|
|
1087
|
-
var AutomationPlugin = () => {
|
|
1088
|
-
return {
|
|
1089
|
-
meta: meta_default,
|
|
1090
|
-
provides: {
|
|
1091
|
-
metadata: {
|
|
1092
|
-
records: {
|
|
1093
|
-
[ChainType.typename]: {
|
|
1094
|
-
placeholder: [
|
|
1095
|
-
"object placeholder",
|
|
1096
|
-
{
|
|
1097
|
-
ns: AUTOMATION_PLUGIN
|
|
1098
|
-
}
|
|
1099
|
-
],
|
|
1100
|
-
icon: "ph--magic-wand--regular",
|
|
1101
|
-
// TODO(wittjosiah): Move out of metadata.
|
|
1102
|
-
loadReferences: (chain) => loadObjectReferences(chain, (chain2) => chain2.prompts)
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
},
|
|
1106
|
-
translations: translations_default,
|
|
1107
|
-
echo: {
|
|
1108
|
-
schema: [
|
|
1109
|
-
ChainType,
|
|
1110
|
-
ChainPromptType,
|
|
1111
|
-
FunctionDef,
|
|
1112
|
-
FunctionTrigger2
|
|
1113
|
-
]
|
|
1114
|
-
},
|
|
1115
|
-
complementary: {
|
|
1116
|
-
panels: [
|
|
1117
|
-
{
|
|
1118
|
-
id: "automation",
|
|
1119
|
-
label: [
|
|
1120
|
-
"open automation panel label",
|
|
1121
|
-
{
|
|
1122
|
-
ns: AUTOMATION_PLUGIN
|
|
1123
|
-
}
|
|
1124
|
-
],
|
|
1125
|
-
icon: "ph--flow-arrow--regular"
|
|
1126
|
-
}
|
|
1127
|
-
]
|
|
1128
|
-
},
|
|
1129
|
-
graph: {
|
|
1130
|
-
builder: (plugins) => {
|
|
1131
|
-
const clientPlugin = resolvePlugin(plugins, parseClientPlugin);
|
|
1132
|
-
const metadataPlugin = resolvePlugin(plugins, parseMetadataResolverPlugin);
|
|
1133
|
-
const resolve = metadataPlugin?.provides.metadata.resolver;
|
|
1134
|
-
const client = clientPlugin?.provides.client;
|
|
1135
|
-
invariant4(resolve, void 0, {
|
|
1136
|
-
F: __dxlog_file5,
|
|
1137
|
-
L: 52,
|
|
1138
|
-
S: void 0,
|
|
1139
|
-
A: [
|
|
1140
|
-
"resolve",
|
|
1141
|
-
""
|
|
1142
|
-
]
|
|
1143
|
-
});
|
|
1144
|
-
invariant4(client, void 0, {
|
|
1145
|
-
F: __dxlog_file5,
|
|
1146
|
-
L: 53,
|
|
1147
|
-
S: void 0,
|
|
1148
|
-
A: [
|
|
1149
|
-
"client",
|
|
1150
|
-
""
|
|
1151
|
-
]
|
|
1152
|
-
});
|
|
1153
|
-
return [
|
|
1154
|
-
// Create nodes for object settings.
|
|
1155
|
-
createExtension({
|
|
1156
|
-
id: `${AUTOMATION_PLUGIN}/automation-for-subject`,
|
|
1157
|
-
resolver: ({ id }) => {
|
|
1158
|
-
if (!id.endsWith("~automation")) {
|
|
1159
|
-
return;
|
|
1160
|
-
}
|
|
1161
|
-
const type = "orphan-settings-for-subject";
|
|
1162
|
-
const icon = "ph--flow-arrow--regular";
|
|
1163
|
-
const [subjectId] = id.split("~");
|
|
1164
|
-
const { spaceId, objectId } = parseId(subjectId);
|
|
1165
|
-
const space = client.spaces.get().find((space2) => space2.id === spaceId);
|
|
1166
|
-
if (!objectId) {
|
|
1167
|
-
const label2 = space ? space.properties.name || [
|
|
1168
|
-
"unnamed space label",
|
|
1169
|
-
{
|
|
1170
|
-
ns: AUTOMATION_PLUGIN
|
|
1171
|
-
}
|
|
1172
|
-
] : [
|
|
1173
|
-
"unnamed object settings label",
|
|
1174
|
-
{
|
|
1175
|
-
ns: AUTOMATION_PLUGIN
|
|
1176
|
-
}
|
|
1177
|
-
];
|
|
1178
|
-
return {
|
|
1179
|
-
id,
|
|
1180
|
-
type,
|
|
1181
|
-
data: null,
|
|
1182
|
-
properties: {
|
|
1183
|
-
icon,
|
|
1184
|
-
label: label2,
|
|
1185
|
-
showResolvedThreads: false,
|
|
1186
|
-
object: null,
|
|
1187
|
-
space
|
|
1188
|
-
}
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
const object = toSignal((onChange) => {
|
|
1192
|
-
const timeout = setTimeout(async () => {
|
|
1193
|
-
await space?.db.loadObjectById(objectId);
|
|
1194
|
-
onChange();
|
|
1195
|
-
});
|
|
1196
|
-
return () => clearTimeout(timeout);
|
|
1197
|
-
}, () => space?.db.getObjectById(objectId), subjectId);
|
|
1198
|
-
if (!object || !subjectId) {
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
const meta = resolve(getTypename(object) ?? "");
|
|
1202
|
-
const label = meta.label?.(object) || object.name || meta.placeholder || [
|
|
1203
|
-
"unnamed object settings label",
|
|
1204
|
-
{
|
|
1205
|
-
ns: AUTOMATION_PLUGIN
|
|
1206
|
-
}
|
|
1207
|
-
];
|
|
1208
|
-
return {
|
|
1209
|
-
id,
|
|
1210
|
-
type,
|
|
1211
|
-
data: null,
|
|
1212
|
-
properties: {
|
|
1213
|
-
icon,
|
|
1214
|
-
label,
|
|
1215
|
-
object
|
|
1216
|
-
}
|
|
1217
|
-
};
|
|
1218
|
-
}
|
|
1219
|
-
})
|
|
1220
|
-
];
|
|
1221
|
-
}
|
|
1222
|
-
},
|
|
1223
|
-
surface: {
|
|
1224
|
-
component: ({ data, role }) => {
|
|
1225
|
-
switch (role) {
|
|
1226
|
-
// case 'article':
|
|
1227
|
-
// return data.object instanceof ChainType ? <ChainArticle chain={data.object} /> : null;
|
|
1228
|
-
case "complementary--automation":
|
|
1229
|
-
return /* @__PURE__ */ React6.createElement(AutomationPanel, null);
|
|
1230
|
-
}
|
|
1231
|
-
return null;
|
|
1232
|
-
}
|
|
1233
|
-
},
|
|
1234
|
-
intent: {
|
|
1235
|
-
resolver: (intent) => {
|
|
1236
|
-
switch (intent.action) {
|
|
1237
|
-
case AutomationAction.CREATE: {
|
|
1238
|
-
return {};
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
};
|
|
1246
|
-
|
|
1247
517
|
// packages/plugins/experimental/plugin-automation/src/index.ts
|
|
1248
518
|
var src_default = AutomationPlugin;
|
|
1249
519
|
export {
|
|
520
|
+
AssistantPanel,
|
|
1250
521
|
AutomationAction,
|
|
1251
522
|
AutomationPanel,
|
|
1252
523
|
AutomationPlugin,
|
|
1253
|
-
Chain,
|
|
1254
524
|
ChainInputSchema,
|
|
1255
525
|
ChainInputType,
|
|
1256
|
-
ChainPresets,
|
|
1257
526
|
ChainPromptType,
|
|
1258
527
|
ChainType,
|
|
1259
|
-
PromptContainer,
|
|
1260
|
-
PromptEditor,
|
|
1261
|
-
TriggerEditor,
|
|
1262
528
|
chainPresets,
|
|
1263
529
|
src_default as default,
|
|
1264
530
|
str
|