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