@dxos/plugin-automation 0.6.14-main.1366248

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