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