@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
@@ -28,100 +28,305 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var node_exports = {};
30
30
  __export(node_exports, {
31
- AutomationAction: () => import_chunk_SUMUWFZA.AutomationAction,
31
+ AssistantPanel: () => AssistantPanel,
32
+ AutomationAction: () => import_chunk_JHKEVE65.AutomationAction,
32
33
  AutomationPanel: () => AutomationPanel,
33
34
  AutomationPlugin: () => AutomationPlugin,
34
- Chain: () => Chain,
35
- ChainInputSchema: () => import_chunk_SUMUWFZA.ChainInputSchema,
36
- ChainInputType: () => import_chunk_SUMUWFZA.ChainInputType,
37
- ChainPresets: () => ChainPresets,
38
- ChainPromptType: () => import_chunk_SUMUWFZA.ChainPromptType,
39
- ChainType: () => import_chunk_SUMUWFZA.ChainType,
40
- PromptContainer: () => PromptContainer,
41
- PromptEditor: () => import_chunk_YGRHTCOX.PromptEditor,
42
- TriggerEditor: () => TriggerEditor,
35
+ ChainInputSchema: () => import_chunk_JHKEVE65.ChainInputSchema,
36
+ ChainInputType: () => import_chunk_JHKEVE65.ChainInputType,
37
+ ChainPromptType: () => import_chunk_JHKEVE65.ChainPromptType,
38
+ ChainType: () => import_chunk_JHKEVE65.ChainType,
43
39
  chainPresets: () => chainPresets,
44
40
  default: () => src_default,
45
41
  str: () => str
46
42
  });
47
43
  module.exports = __toCommonJS(node_exports);
48
- var import_chunk_YGRHTCOX = require("./chunk-YGRHTCOX.cjs");
49
- var import_chunk_SUMUWFZA = require("./chunk-SUMUWFZA.cjs");
50
- var import_chunk_JSZ6PAYL = require("./chunk-JSZ6PAYL.cjs");
44
+ var import_chunk_JHKEVE65 = require("./chunk-JHKEVE65.cjs");
45
+ var import_chunk_DTJ7XVO2 = require("./chunk-DTJ7XVO2.cjs");
51
46
  var import_react = __toESM(require("react"));
52
47
  var import_app_framework = require("@dxos/app-framework");
53
- var import_types = require("@dxos/functions/types");
48
+ var import_functions = require("@dxos/functions");
54
49
  var import_invariant = require("@dxos/invariant");
55
50
  var import_plugin_client = require("@dxos/plugin-client");
56
51
  var import_plugin_graph = require("@dxos/plugin-graph");
52
+ var import_plugin_space = require("@dxos/plugin-space");
57
53
  var import_echo = require("@dxos/react-client/echo");
54
+ var import_react_ui_form = require("@dxos/react-ui-form");
58
55
  var import_react2 = require("react");
59
- var import_react3 = __toESM(require("react"));
60
- var import_react_ui = require("@dxos/react-ui");
61
- var import_react4 = __toESM(require("react"));
62
- var import_echo2 = require("@dxos/react-client/echo");
63
- var import_react_ui2 = require("@dxos/react-ui");
64
- var import_util = require("@dxos/util");
65
56
  var import_echo_schema = require("@dxos/echo-schema");
66
- var import_react5 = __toESM(require("react"));
67
- var import_types2 = require("@dxos/functions/types");
68
- var import_invariant2 = require("@dxos/invariant");
69
- var import_types3 = require("@dxos/plugin-script/types");
70
- var import_echo3 = require("@dxos/react-client/echo");
71
- var import_react_ui3 = require("@dxos/react-ui");
72
- var import_react_ui_form = require("@dxos/react-ui-form");
73
- var import_util2 = require("@dxos/util");
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");
106
- var AutomationPanel = () => {
107
- const handleCreate = () => {
57
+ var AssistantPanel = (0, import_react2.lazy)(() => import("./AssistantPanel-HRJRVOZD.cjs"));
58
+ var AutomationPanel = (0, import_react2.lazy)(() => import("./AutomationPanel-Z2XW24BN.cjs"));
59
+ var translations_default = [
60
+ {
61
+ "en-US": {
62
+ [import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN]: {
63
+ "plugin name": "Automation",
64
+ "object placeholder": "New prompt",
65
+ "create object label": "Create prompt",
66
+ "create trigger label": "Create trigger",
67
+ "create stack section label": "Create prompt",
68
+ "command placeholder": "Enter slash command...",
69
+ "template placeholder": "Enter template...",
70
+ "value placeholder": "Enter value...",
71
+ "select preset template placeholder": "Select preset",
72
+ "open automation panel label": "Show Automations",
73
+ "function select label": "Function",
74
+ "function select placeholder": "Select function",
75
+ "function enabled": "Enabled",
76
+ "trigger select label": "Trigger",
77
+ "trigger select placeholder": "Trigger type",
78
+ "trigger type timer": "Timer",
79
+ "trigger type webhook": "Webhook",
80
+ "trigger type websocket": "Websocket",
81
+ "trigger type subscription": "Subscription",
82
+ "trigger filter": "Filter",
83
+ "trigger cron": "Cron",
84
+ "trigger method": "Method",
85
+ "trigger endpoint": "Endpoint",
86
+ "open assistant panel label": "Show Assistant",
87
+ "assistant panel label": "Assistant"
88
+ }
89
+ }
90
+ }
91
+ ];
92
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/AutomationPlugin.tsx";
93
+ var AutomationPlugin = () => {
94
+ return {
95
+ meta: import_chunk_DTJ7XVO2.meta_default,
96
+ provides: {
97
+ metadata: {
98
+ records: {
99
+ [import_chunk_JHKEVE65.ChainType.typename]: {
100
+ placeholder: [
101
+ "object placeholder",
102
+ {
103
+ ns: import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN
104
+ }
105
+ ],
106
+ icon: "ph--magic-wand--regular",
107
+ // TODO(wittjosiah): Move out of metadata.
108
+ loadReferences: (chain) => (0, import_echo.loadObjectReferences)(chain, (chain2) => chain2.prompts)
109
+ }
110
+ }
111
+ },
112
+ translations: [
113
+ ...translations_default,
114
+ ...import_react_ui_form.translations
115
+ ],
116
+ echo: {
117
+ schema: [
118
+ import_chunk_JHKEVE65.ChainType,
119
+ import_chunk_JHKEVE65.ChainPromptType,
120
+ import_functions.FunctionTrigger
121
+ ]
122
+ },
123
+ complementary: {
124
+ panels: [
125
+ {
126
+ id: "automation",
127
+ label: [
128
+ "open automation panel label",
129
+ {
130
+ ns: import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN
131
+ }
132
+ ],
133
+ icon: "ph--magic-wand--regular"
134
+ },
135
+ {
136
+ id: "assistant",
137
+ label: [
138
+ "open assistant panel label",
139
+ {
140
+ ns: import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN
141
+ }
142
+ ],
143
+ icon: "ph--atom--regular"
144
+ }
145
+ ]
146
+ },
147
+ graph: {
148
+ builder: (plugins) => {
149
+ const clientPlugin = (0, import_app_framework.resolvePlugin)(plugins, import_plugin_client.parseClientPlugin);
150
+ const metadataPlugin = (0, import_app_framework.resolvePlugin)(plugins, import_app_framework.parseMetadataResolverPlugin);
151
+ const resolve = metadataPlugin?.provides.metadata.resolver;
152
+ const client = clientPlugin?.provides.client;
153
+ (0, import_invariant.invariant)(resolve, void 0, {
154
+ F: __dxlog_file,
155
+ L: 66,
156
+ S: void 0,
157
+ A: [
158
+ "resolve",
159
+ ""
160
+ ]
161
+ });
162
+ (0, import_invariant.invariant)(client, void 0, {
163
+ F: __dxlog_file,
164
+ L: 67,
165
+ S: void 0,
166
+ A: [
167
+ "client",
168
+ ""
169
+ ]
170
+ });
171
+ return [
172
+ // Create nodes for object settings.
173
+ (0, import_plugin_graph.createExtension)({
174
+ id: `${import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN}/automation-for-subject`,
175
+ resolver: ({ id }) => {
176
+ if (!id.endsWith("~automation")) {
177
+ return;
178
+ }
179
+ const type = "orphan-settings-for-subject";
180
+ const icon = "ph--magic-wand--regular";
181
+ const [subjectId] = id.split("~");
182
+ const { spaceId, objectId } = (0, import_echo.parseId)(subjectId);
183
+ const spaces = (0, import_plugin_graph.toSignal)((onChange) => client.spaces.subscribe(() => onChange()).unsubscribe, () => client.spaces.get());
184
+ const space = spaces?.find((space2) => space2.id === spaceId && space2.state.get() === import_echo.SpaceState.SPACE_READY);
185
+ if (!objectId) {
186
+ const label2 = space ? space.properties.name || [
187
+ "unnamed space label",
188
+ {
189
+ ns: import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN
190
+ }
191
+ ] : [
192
+ "unnamed object settings label",
193
+ {
194
+ ns: import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN
195
+ }
196
+ ];
197
+ return {
198
+ id,
199
+ type,
200
+ data: null,
201
+ properties: {
202
+ icon,
203
+ label: label2,
204
+ showResolvedThreads: false,
205
+ object: null,
206
+ space
207
+ }
208
+ };
209
+ }
210
+ const [object] = (0, import_plugin_space.memoizeQuery)(space, {
211
+ id: objectId
212
+ });
213
+ if (!object || !subjectId) {
214
+ return;
215
+ }
216
+ const meta = resolve((0, import_echo.getTypename)(object) ?? "");
217
+ const label = meta.label?.(object) || object.name || meta.placeholder || [
218
+ "unnamed object settings label",
219
+ {
220
+ ns: import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN
221
+ }
222
+ ];
223
+ return {
224
+ id,
225
+ type,
226
+ data: null,
227
+ properties: {
228
+ icon,
229
+ label,
230
+ object
231
+ }
232
+ };
233
+ }
234
+ }),
235
+ (0, import_plugin_graph.createExtension)({
236
+ id: `${import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN}/assistant-for-subject`,
237
+ resolver: ({ id }) => {
238
+ if (!id.endsWith("~assistant")) {
239
+ return;
240
+ }
241
+ const [subjectId] = id.split("~");
242
+ const { spaceId, objectId } = (0, import_echo.parseId)(subjectId);
243
+ const spaces = (0, import_plugin_graph.toSignal)((onChange) => client.spaces.subscribe(() => onChange()).unsubscribe, () => client.spaces.get());
244
+ const space = spaces?.find((space2) => space2.id === spaceId && space2.state.get() === import_echo.SpaceState.SPACE_READY);
245
+ if (!objectId) {
246
+ return {
247
+ id,
248
+ type: "orphan-automation-for-subject",
249
+ data: null,
250
+ properties: {
251
+ icon: "ph--atom--regular",
252
+ label: [
253
+ "assistant panel label",
254
+ {
255
+ ns: import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN
256
+ }
257
+ ],
258
+ object: null,
259
+ space
260
+ }
261
+ };
262
+ }
263
+ const [object] = (0, import_plugin_space.memoizeQuery)(space, {
264
+ id: objectId
265
+ });
266
+ return {
267
+ id,
268
+ type: "orphan-automation-for-subject",
269
+ data: null,
270
+ properties: {
271
+ icon: "ph--atom--regular",
272
+ label: [
273
+ "assistant panel label",
274
+ {
275
+ ns: import_chunk_DTJ7XVO2.AUTOMATION_PLUGIN
276
+ }
277
+ ],
278
+ object
279
+ }
280
+ };
281
+ }
282
+ })
283
+ ];
284
+ }
285
+ },
286
+ surface: {
287
+ component: ({ data, role }) => {
288
+ switch (role) {
289
+ case "complementary--assistant":
290
+ return /* @__PURE__ */ import_react.default.createElement(AssistantPanel, {
291
+ subject: data.subject
292
+ });
293
+ case "complementary--automation": {
294
+ const object = data.subject;
295
+ const space = (0, import_echo.isEchoObject)(object) ? (0, import_echo.getSpace)(object) : void 0;
296
+ if (space) {
297
+ (0, import_invariant.invariant)((0, import_echo.isEchoObject)(object), void 0, {
298
+ F: __dxlog_file,
299
+ L: 193,
300
+ S: void 0,
301
+ A: [
302
+ "isEchoObject(object)",
303
+ ""
304
+ ]
305
+ });
306
+ return /* @__PURE__ */ import_react.default.createElement(AutomationPanel, {
307
+ space,
308
+ object
309
+ });
310
+ }
311
+ break;
312
+ }
313
+ }
314
+ return null;
315
+ }
316
+ },
317
+ intent: {
318
+ resolver: (intent) => {
319
+ }
320
+ }
321
+ }
108
322
  };
109
- return /* @__PURE__ */ import_react3.default.createElement("div", {
110
- className: "flex flex-col"
111
- }, /* @__PURE__ */ import_react3.default.createElement(import_react_ui.Toolbar.Root, {
112
- classNames: "p-2"
113
- }, /* @__PURE__ */ import_react3.default.createElement(import_react_ui.Button, {
114
- onClick: handleCreate
115
- }, /* @__PURE__ */ import_react3.default.createElement(import_react_ui.Icon, {
116
- icon: "ph--plus--regular"
117
- }))));
118
323
  };
119
324
  var str = (...text) => text.filter((value) => value !== void 0 && value !== false).flat().join("\n");
120
325
  var chainPresets = [
121
326
  {
122
327
  id: "dxos.org/prompt/translate",
123
328
  title: "Translate",
124
- createPrompt: () => (0, import_echo_schema.create)(import_chunk_SUMUWFZA.ChainPromptType, {
329
+ createPrompt: () => (0, import_echo_schema.create)(import_chunk_JHKEVE65.ChainPromptType, {
125
330
  command: "say",
126
331
  template: str(
127
332
  // prettier-ignore
@@ -133,12 +338,12 @@ var chainPresets = [
133
338
  ),
134
339
  inputs: [
135
340
  {
136
- type: import_chunk_SUMUWFZA.ChainInputType.VALUE,
341
+ type: import_chunk_JHKEVE65.ChainInputType.VALUE,
137
342
  name: "language",
138
343
  value: "japanese"
139
344
  },
140
345
  {
141
- type: import_chunk_SUMUWFZA.ChainInputType.PASS_THROUGH,
346
+ type: import_chunk_JHKEVE65.ChainInputType.PASS_THROUGH,
142
347
  name: "input"
143
348
  }
144
349
  ]
@@ -147,7 +352,7 @@ var chainPresets = [
147
352
  {
148
353
  id: "dxos.org/prompt/chess",
149
354
  title: "Chess",
150
- createPrompt: () => (0, import_echo_schema.create)(import_chunk_SUMUWFZA.ChainPromptType, {
355
+ createPrompt: () => (0, import_echo_schema.create)(import_chunk_JHKEVE65.ChainPromptType, {
151
356
  command: "hint",
152
357
  template: str(
153
358
  // prettier-ignore
@@ -159,7 +364,7 @@ var chainPresets = [
159
364
  ),
160
365
  inputs: [
161
366
  {
162
- type: import_chunk_SUMUWFZA.ChainInputType.CONTEXT,
367
+ type: import_chunk_JHKEVE65.ChainInputType.CONTEXT,
163
368
  name: "history",
164
369
  value: "object.pgn"
165
370
  }
@@ -169,7 +374,7 @@ var chainPresets = [
169
374
  {
170
375
  id: "dxos.org/prompt/mermaid",
171
376
  title: "Mermaid",
172
- createPrompt: () => (0, import_echo_schema.create)(import_chunk_SUMUWFZA.ChainPromptType, {
377
+ createPrompt: () => (0, import_echo_schema.create)(import_chunk_JHKEVE65.ChainPromptType, {
173
378
  command: "draw",
174
379
  template: str(
175
380
  // prettier-ignore
@@ -182,7 +387,7 @@ var chainPresets = [
182
387
  ),
183
388
  inputs: [
184
389
  {
185
- type: import_chunk_SUMUWFZA.ChainInputType.PASS_THROUGH,
390
+ type: import_chunk_JHKEVE65.ChainInputType.PASS_THROUGH,
186
391
  name: "input"
187
392
  }
188
393
  ]
@@ -191,7 +396,7 @@ var chainPresets = [
191
396
  {
192
397
  id: "dxos.org/prompt/list",
193
398
  title: "List",
194
- createPrompt: () => (0, import_echo_schema.create)(import_chunk_SUMUWFZA.ChainPromptType, {
399
+ createPrompt: () => (0, import_echo_schema.create)(import_chunk_JHKEVE65.ChainPromptType, {
195
400
  command: "list",
196
401
  template: str(
197
402
  // prettier-ignore
@@ -208,12 +413,12 @@ var chainPresets = [
208
413
  ),
209
414
  inputs: [
210
415
  {
211
- type: import_chunk_SUMUWFZA.ChainInputType.SCHEMA,
416
+ type: import_chunk_JHKEVE65.ChainInputType.SCHEMA,
212
417
  name: "schema",
213
418
  value: "example.com/type/project"
214
419
  },
215
420
  {
216
- type: import_chunk_SUMUWFZA.ChainInputType.PASS_THROUGH,
421
+ type: import_chunk_JHKEVE65.ChainInputType.PASS_THROUGH,
217
422
  name: "question"
218
423
  }
219
424
  ]
@@ -222,7 +427,7 @@ var chainPresets = [
222
427
  {
223
428
  id: "dxos.org/prompt/base",
224
429
  title: "RAG",
225
- createPrompt: () => (0, import_echo_schema.create)(import_chunk_SUMUWFZA.ChainPromptType, {
430
+ createPrompt: () => (0, import_echo_schema.create)(import_chunk_JHKEVE65.ChainPromptType, {
226
431
  command: "rag",
227
432
  template: str(
228
433
  // prettier-ignore
@@ -237,11 +442,11 @@ var chainPresets = [
237
442
  ),
238
443
  inputs: [
239
444
  {
240
- type: import_chunk_SUMUWFZA.ChainInputType.RETRIEVER,
445
+ type: import_chunk_JHKEVE65.ChainInputType.RETRIEVER,
241
446
  name: "context"
242
447
  },
243
448
  {
244
- type: import_chunk_SUMUWFZA.ChainInputType.CONTEXT,
449
+ type: import_chunk_JHKEVE65.ChainInputType.CONTEXT,
245
450
  name: "question",
246
451
  value: "object.text"
247
452
  }
@@ -251,7 +456,7 @@ var chainPresets = [
251
456
  {
252
457
  id: "dxos.org/prompt/lookup",
253
458
  title: "Lookup",
254
- createPrompt: () => (0, import_echo_schema.create)(import_chunk_SUMUWFZA.ChainPromptType, {
459
+ createPrompt: () => (0, import_echo_schema.create)(import_chunk_JHKEVE65.ChainPromptType, {
255
460
  command: "lookup",
256
461
  template: str(
257
462
  // prettier-ignore
@@ -263,7 +468,7 @@ var chainPresets = [
263
468
  ),
264
469
  inputs: [
265
470
  {
266
- type: import_chunk_SUMUWFZA.ChainInputType.CONTEXT,
471
+ type: import_chunk_JHKEVE65.ChainInputType.CONTEXT,
267
472
  name: "input",
268
473
  value: "text"
269
474
  }
@@ -273,7 +478,7 @@ var chainPresets = [
273
478
  {
274
479
  id: "dxos.org/prompt/extract",
275
480
  title: "Extract",
276
- createPrompt: () => (0, import_echo_schema.create)(import_chunk_SUMUWFZA.ChainPromptType, {
481
+ createPrompt: () => (0, import_echo_schema.create)(import_chunk_JHKEVE65.ChainPromptType, {
277
482
  command: "extract",
278
483
  template: str(
279
484
  // prettier-ignore
@@ -291,17 +496,17 @@ var chainPresets = [
291
496
  ),
292
497
  inputs: [
293
498
  {
294
- type: import_chunk_SUMUWFZA.ChainInputType.SCHEMA,
499
+ type: import_chunk_JHKEVE65.ChainInputType.SCHEMA,
295
500
  name: "contact",
296
501
  value: "example.com/type/contact"
297
502
  },
298
503
  {
299
- type: import_chunk_SUMUWFZA.ChainInputType.SCHEMA,
504
+ type: import_chunk_JHKEVE65.ChainInputType.SCHEMA,
300
505
  name: "company",
301
506
  value: "example.com/type/organization"
302
507
  },
303
508
  {
304
- type: import_chunk_SUMUWFZA.ChainInputType.CONTEXT,
509
+ type: import_chunk_JHKEVE65.ChainInputType.CONTEXT,
305
510
  name: "input",
306
511
  value: "text"
307
512
  }
@@ -311,7 +516,7 @@ var chainPresets = [
311
516
  {
312
517
  id: "dxos.org/prompt/discord",
313
518
  title: "Summarize",
314
- createPrompt: () => (0, import_echo_schema.create)(import_chunk_SUMUWFZA.ChainPromptType, {
519
+ createPrompt: () => (0, import_echo_schema.create)(import_chunk_JHKEVE65.ChainPromptType, {
315
520
  command: "summarize",
316
521
  template: str(
317
522
  // prettier-ignore
@@ -323,7 +528,7 @@ var chainPresets = [
323
528
  ),
324
529
  inputs: [
325
530
  {
326
- type: import_chunk_SUMUWFZA.ChainInputType.RESOLVER,
531
+ type: import_chunk_JHKEVE65.ChainInputType.RESOLVER,
327
532
  name: "context",
328
533
  value: "discord.messages.recent"
329
534
  }
@@ -331,932 +536,17 @@ var chainPresets = [
331
536
  })
332
537
  }
333
538
  ];
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
539
  var src_default = AutomationPlugin;
1246
540
  // Annotate the CommonJS export names for ESM import in node:
1247
541
  0 && (module.exports = {
542
+ AssistantPanel,
1248
543
  AutomationAction,
1249
544
  AutomationPanel,
1250
545
  AutomationPlugin,
1251
- Chain,
1252
546
  ChainInputSchema,
1253
547
  ChainInputType,
1254
- ChainPresets,
1255
548
  ChainPromptType,
1256
549
  ChainType,
1257
- PromptContainer,
1258
- PromptEditor,
1259
- TriggerEditor,
1260
550
  chainPresets,
1261
551
  str
1262
552
  });