@dxos/plugin-automation 0.7.0 → 0.7.1-staging.599df14

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 (63) hide show
  1. package/dist/lib/browser/{PromptContainer-3GUENQHE.mjs → PromptContainer-6CBNCUKQ.mjs} +3 -3
  2. package/dist/lib/browser/{chunk-J4SYTP4Y.mjs → chunk-B3Z4NQC2.mjs} +2 -2
  3. package/dist/lib/browser/{chunk-J4SYTP4Y.mjs.map → chunk-B3Z4NQC2.mjs.map} +1 -1
  4. package/dist/lib/browser/{chunk-2FOJUVYG.mjs → chunk-CJMV64XO.mjs} +2 -2
  5. package/dist/lib/browser/index.mjs +299 -213
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/types/index.mjs +1 -1
  9. package/dist/lib/node/{PromptContainer-74ZRO4HK.cjs → PromptContainer-7RCGCU3K.cjs} +7 -7
  10. package/dist/lib/node/{chunk-XS53UP75.cjs → chunk-SUMUWFZA.cjs} +4 -4
  11. package/dist/lib/node/{chunk-XS53UP75.cjs.map → chunk-SUMUWFZA.cjs.map} +1 -1
  12. package/dist/lib/node/{chunk-4TMTUB4X.cjs → chunk-YGRHTCOX.cjs} +16 -16
  13. package/dist/lib/node/index.cjs +322 -240
  14. package/dist/lib/node/index.cjs.map +4 -4
  15. package/dist/lib/node/meta.json +1 -1
  16. package/dist/lib/node/types/index.cjs +6 -6
  17. package/dist/lib/node/types/index.cjs.map +1 -1
  18. package/dist/lib/node-esm/{PromptContainer-5OK4GWIR.mjs → PromptContainer-4SCHQV5C.mjs} +3 -3
  19. package/dist/lib/node-esm/{chunk-FN6DOJZP.mjs → chunk-62AB5HXX.mjs} +2 -2
  20. package/dist/lib/node-esm/{chunk-AAUSG7OA.mjs → chunk-PYT2WY4B.mjs} +2 -2
  21. package/dist/lib/node-esm/{chunk-AAUSG7OA.mjs.map → chunk-PYT2WY4B.mjs.map} +1 -1
  22. package/dist/lib/node-esm/index.mjs +299 -213
  23. package/dist/lib/node-esm/index.mjs.map +4 -4
  24. package/dist/lib/node-esm/meta.json +1 -1
  25. package/dist/lib/node-esm/types/index.mjs +1 -1
  26. package/dist/types/src/AutomationPlugin.d.ts.map +1 -1
  27. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts +4 -3
  28. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
  29. package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts +1 -0
  30. package/dist/types/src/components/TriggerEditor/TriggerEditor.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/TriggerEditor/meta.d.ts.map +1 -1
  32. package/dist/types/src/hooks/email.d.ts.map +1 -0
  33. package/dist/types/src/hooks/index.d.ts +2 -0
  34. package/dist/types/src/hooks/index.d.ts.map +1 -0
  35. package/dist/types/src/{components/TriggerEditor/invokation-handler.d.ts → hooks/invocation-handler.d.ts} +1 -1
  36. package/dist/types/src/hooks/invocation-handler.d.ts.map +1 -0
  37. package/dist/types/src/hooks/useLocalTriggerManager.d.ts +3 -0
  38. package/dist/types/src/hooks/useLocalTriggerManager.d.ts.map +1 -0
  39. package/dist/types/src/types/index.d.ts +1 -1
  40. package/dist/types/src/types/index.d.ts.map +1 -1
  41. package/dist/types/src/types/{chain.d.ts → schema.d.ts} +1 -1
  42. package/dist/types/src/types/schema.d.ts.map +1 -0
  43. package/package.json +35 -34
  44. package/src/AutomationPlugin.tsx +0 -3
  45. package/src/components/TriggerEditor/TriggerEditor.stories.tsx +4 -3
  46. package/src/components/TriggerEditor/TriggerEditor.tsx +69 -86
  47. package/src/components/TriggerEditor/meta.tsx +1 -0
  48. package/src/hooks/index.ts +5 -0
  49. package/src/{components/TriggerEditor/invokation-handler.ts → hooks/invocation-handler.ts} +4 -2
  50. package/src/hooks/useLocalTriggerManager.ts +84 -0
  51. package/src/types/index.ts +1 -1
  52. package/dist/types/src/components/TriggerEditor/email.d.ts.map +0 -1
  53. package/dist/types/src/components/TriggerEditor/invokation-handler.d.ts.map +0 -1
  54. package/dist/types/src/types/chain.d.ts.map +0 -1
  55. /package/dist/lib/browser/{PromptContainer-3GUENQHE.mjs.map → PromptContainer-6CBNCUKQ.mjs.map} +0 -0
  56. /package/dist/lib/browser/{chunk-2FOJUVYG.mjs.map → chunk-CJMV64XO.mjs.map} +0 -0
  57. /package/dist/lib/node/{PromptContainer-74ZRO4HK.cjs.map → PromptContainer-7RCGCU3K.cjs.map} +0 -0
  58. /package/dist/lib/node/{chunk-4TMTUB4X.cjs.map → chunk-YGRHTCOX.cjs.map} +0 -0
  59. /package/dist/lib/node-esm/{PromptContainer-5OK4GWIR.mjs.map → PromptContainer-4SCHQV5C.mjs.map} +0 -0
  60. /package/dist/lib/node-esm/{chunk-FN6DOJZP.mjs.map → chunk-62AB5HXX.mjs.map} +0 -0
  61. /package/dist/types/src/{components/TriggerEditor → hooks}/email.d.ts +0 -0
  62. /package/src/{components/TriggerEditor → hooks}/email.ts +0 -0
  63. /package/src/types/{chain.ts → schema.ts} +0 -0
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  PromptEditor
3
- } from "./chunk-2FOJUVYG.mjs";
3
+ } from "./chunk-CJMV64XO.mjs";
4
4
  import {
5
5
  AutomationAction,
6
6
  ChainInputSchema,
7
7
  ChainInputType,
8
8
  ChainPromptType,
9
9
  ChainType
10
- } from "./chunk-J4SYTP4Y.mjs";
10
+ } from "./chunk-B3Z4NQC2.mjs";
11
11
  import {
12
12
  AUTOMATION_PLUGIN,
13
13
  meta_default
@@ -17,7 +17,7 @@ import {
17
17
  import React6 from "react";
18
18
  import { parseMetadataResolverPlugin, resolvePlugin } from "@dxos/app-framework";
19
19
  import { FunctionDef, FunctionTrigger as FunctionTrigger2 } from "@dxos/functions/types";
20
- import { invariant as invariant2 } from "@dxos/invariant";
20
+ import { invariant as invariant4 } from "@dxos/invariant";
21
21
  import { parseClientPlugin } from "@dxos/plugin-client";
22
22
  import { createExtension, toSignal } from "@dxos/plugin-graph";
23
23
  import { getTypename, loadObjectReferences, parseId } from "@dxos/react-client/echo";
@@ -307,16 +307,13 @@ var ChainPresets = ({ presets, onSelect }) => {
307
307
  };
308
308
 
309
309
  // packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/TriggerEditor.tsx
310
- import React5, { useEffect, useMemo, useState } from "react";
311
- import { Mutex } from "@dxos/async";
312
- import { Context } from "@dxos/context";
313
- import { createSubscriptionTrigger, createWebsocketTrigger } from "@dxos/functions";
314
- import { FunctionTrigger } from "@dxos/functions/types";
315
- import { log as log3 } from "@dxos/log";
310
+ import React5, { useEffect as useEffect2, useMemo } from "react";
311
+ import { FunctionTriggerSchema } from "@dxos/functions/types";
312
+ import { invariant as invariant3 } from "@dxos/invariant";
316
313
  import { ScriptType } from "@dxos/plugin-script/types";
317
- import { useClient } from "@dxos/react-client";
318
- import { Filter as Filter2, useQuery } from "@dxos/react-client/echo";
314
+ import { Filter as Filter3, useQuery as useQuery2 } from "@dxos/react-client/echo";
319
315
  import { Input as Input3, Select as Select2, useTranslation as useTranslation2 } from "@dxos/react-ui";
316
+ import { Form, SelectInput } from "@dxos/react-ui-form";
320
317
  import { distinctBy } from "@dxos/util";
321
318
 
322
319
  // packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/Form.tsx
@@ -330,7 +327,148 @@ var InputRow = ({ label, children }) => /* @__PURE__ */ React3.createElement(Inp
330
327
  className: "p-1 pr-2"
331
328
  }, children)));
332
329
 
333
- // packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/invokation-handler.ts
330
+ // packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/meta.tsx
331
+ import React4 from "react";
332
+ import { create as create2, getMeta as getEchoMeta } from "@dxos/echo-schema";
333
+ import { GameType } from "@dxos/plugin-chess/types";
334
+ import { FileType } from "@dxos/plugin-ipfs/types";
335
+ import { DocumentType } from "@dxos/plugin-markdown";
336
+ import { DiagramType } from "@dxos/plugin-sketch/types";
337
+ import { CollectionType, MessageType } from "@dxos/plugin-space";
338
+ import { Input as Input2 } from "@dxos/react-ui";
339
+ import { safeParseInt } from "@dxos/util";
340
+ var stateInitialValues = {
341
+ schemas: [
342
+ // TODO(burdon): Get all schema from API.
343
+ DocumentType,
344
+ FileType,
345
+ GameType,
346
+ MessageType,
347
+ DiagramType,
348
+ CollectionType
349
+ ],
350
+ selectedSchema: {}
351
+ };
352
+ var state = create2(stateInitialValues);
353
+ var USERFUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
354
+ var getFunctionMetaExtension = (trigger, script) => {
355
+ if (script) {
356
+ const meta = getEchoMeta(script).keys.find((key) => key.source === USERFUNCTIONS_PRESET_META_KEY);
357
+ const extension = meta && metaExtensions[meta.id];
358
+ if (extension) {
359
+ return extension;
360
+ }
361
+ }
362
+ return trigger?.function ? metaExtensions[trigger.function] : metaExtensions["dxos.org/function/gpt"];
363
+ };
364
+ var DefaultMetaProps = ({ meta }) => {
365
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null);
366
+ };
367
+ var ChessMetaProps = ({ meta }) => {
368
+ if (!meta) {
369
+ return null;
370
+ }
371
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
372
+ label: "Level"
373
+ }, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
374
+ type: "number",
375
+ value: meta.level ?? 1,
376
+ onChange: (event) => meta.level = safeParseInt(event.target.value),
377
+ placeholder: "Engine strength."
378
+ })));
379
+ };
380
+ var EmailWorkerMetaProps = ({ meta }) => {
381
+ if (!meta) {
382
+ return null;
383
+ }
384
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
385
+ label: "Account"
386
+ }, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
387
+ value: meta.account ?? "",
388
+ onChange: (event) => meta.account = event.target.value,
389
+ placeholder: "https://"
390
+ })));
391
+ };
392
+ var ChainPromptMetaProps = ({ meta, triggerId }) => {
393
+ const schema = triggerId ? state.selectedSchema[triggerId] : void 0;
394
+ if (!meta) {
395
+ return null;
396
+ }
397
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
398
+ label: "Model"
399
+ }, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
400
+ value: meta.model ?? "",
401
+ onChange: (event) => meta.model = event.target.value,
402
+ placeholder: "llama2"
403
+ })), /* @__PURE__ */ React4.createElement(InputRow, {
404
+ label: "Presets"
405
+ }, /* @__PURE__ */ React4.createElement(ChainPresets, {
406
+ presets: chainPresets,
407
+ onSelect: (preset) => {
408
+ meta.prompt = preset.createPrompt();
409
+ }
410
+ })), meta.prompt && /* @__PURE__ */ React4.createElement(InputRow, {
411
+ label: "Prompt"
412
+ }, /* @__PURE__ */ React4.createElement(PromptEditor, {
413
+ prompt: meta.prompt,
414
+ schema
415
+ })));
416
+ };
417
+ var EmbeddingMetaProps = ({ meta }) => {
418
+ if (!meta) {
419
+ return null;
420
+ }
421
+ return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
422
+ label: "Model"
423
+ }, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
424
+ value: meta.model ?? "",
425
+ onChange: (event) => meta.model = event.target.value,
426
+ placeholder: "llama2"
427
+ })));
428
+ };
429
+ var metaExtensions = {
430
+ __DEFAULT__: {
431
+ initialValue: () => ({}),
432
+ component: DefaultMetaProps
433
+ },
434
+ "dxos.org/function/chess": {
435
+ initialValue: () => ({
436
+ level: 2
437
+ }),
438
+ component: ChessMetaProps
439
+ },
440
+ "dxos.org/function/email-worker": {
441
+ initialValue: () => ({
442
+ account: "hello@dxos.network"
443
+ }),
444
+ component: EmailWorkerMetaProps
445
+ },
446
+ "dxos.org/function/gpt": {
447
+ initialValue: () => ({
448
+ model: "llama2"
449
+ }),
450
+ component: ChainPromptMetaProps
451
+ },
452
+ "dxos.org/function/embedding": {
453
+ initialValue: () => ({
454
+ model: "llama2"
455
+ }),
456
+ component: EmbeddingMetaProps
457
+ }
458
+ };
459
+
460
+ // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
461
+ import { useEffect, useState } from "react";
462
+ import { Mutex } from "@dxos/async";
463
+ import { Context } from "@dxos/context";
464
+ import { createSubscriptionTrigger, createWebsocketTrigger } from "@dxos/functions";
465
+ import { FunctionTrigger } from "@dxos/functions/types";
466
+ import { invariant as invariant2 } from "@dxos/invariant";
467
+ import { log as log3 } from "@dxos/log";
468
+ import { useClient } from "@dxos/react-client";
469
+ import { Filter as Filter2, useQuery } from "@dxos/react-client/echo";
470
+
471
+ // packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts
334
472
  import { sleep } from "@dxos/async";
335
473
  import { getObjectCore } from "@dxos/echo-db";
336
474
  import { invariant } from "@dxos/invariant";
@@ -338,19 +476,19 @@ import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
338
476
  import { log as log2 } from "@dxos/log";
339
477
  import { FunctionType } from "@dxos/plugin-script";
340
478
 
341
- // packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/email.ts
479
+ // packages/plugins/experimental/plugin-automation/src/hooks/email.ts
342
480
  import { findObjectWithForeignKey } from "@dxos/echo-db";
343
- import { create as create2, foreignKey } from "@dxos/echo-schema";
481
+ import { create as create3, foreignKey } from "@dxos/echo-schema";
344
482
  import { log } from "@dxos/log";
345
483
  import { MailboxType } from "@dxos/plugin-inbox/types";
346
- import { MessageType } from "@dxos/plugin-space/types";
484
+ import { MessageType as MessageType2 } from "@dxos/plugin-space/types";
347
485
  import { Filter } from "@dxos/react-client/echo";
348
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/email.ts";
486
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/email.ts";
349
487
  var SOURCE_ID = "hub.dxos.network/api/mailbox";
350
488
  var handleEmail = async (space, data) => {
351
489
  const { messages } = data;
352
490
  const { objects: mailboxes } = await space.db.query(Filter.schema(MailboxType)).run();
353
- const mailbox = mailboxes[0] ?? space.db.add(create2(MailboxType, {
491
+ const mailbox = mailboxes[0] ?? space.db.add(create3(MailboxType, {
354
492
  messages: []
355
493
  }));
356
494
  log.info("messages", {
@@ -362,14 +500,14 @@ var handleEmail = async (space, data) => {
362
500
  S: void 0,
363
501
  C: (f, a) => f(...a)
364
502
  });
365
- const { objects } = await space.db.query(Filter.schema(MessageType)).run();
503
+ const { objects } = await space.db.query(Filter.schema(MessageType2)).run();
366
504
  for (const message of messages) {
367
505
  let object = findObjectWithForeignKey(objects, {
368
506
  source: SOURCE_ID,
369
507
  id: String(message.id)
370
508
  });
371
509
  if (!object) {
372
- object = space.db.add(create2(MessageType, {
510
+ object = space.db.add(create3(MessageType2, {
373
511
  sender: {
374
512
  email: message.from
375
513
  },
@@ -394,8 +532,8 @@ var handleEmail = async (space, data) => {
394
532
  return 200;
395
533
  };
396
534
 
397
- // packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/invokation-handler.ts
398
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/invokation-handler.ts";
535
+ // packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts
536
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts";
399
537
  var MAX_RETRIES = 3;
400
538
  var RETRY_DELAY = 1e3;
401
539
  var callFunction = async (funcUrl, trigger, data) => {
@@ -449,6 +587,24 @@ var callFunction = async (funcUrl, trigger, data) => {
449
587
  };
450
588
  var invokeFunction = async (client, space, trigger, data) => {
451
589
  try {
590
+ invariant(trigger.spec, void 0, {
591
+ F: __dxlog_file2,
592
+ L: 50,
593
+ S: void 0,
594
+ A: [
595
+ "trigger.spec",
596
+ ""
597
+ ]
598
+ });
599
+ invariant(trigger.function, void 0, {
600
+ F: __dxlog_file2,
601
+ L: 51,
602
+ S: void 0,
603
+ A: [
604
+ "trigger.function",
605
+ ""
606
+ ]
607
+ });
452
608
  if (trigger.spec.type === "websocket") {
453
609
  return handleEmail(space, data.data);
454
610
  }
@@ -466,7 +622,7 @@ var invokeFunction = async (client, space, trigger, data) => {
466
622
  name: script.name
467
623
  }, {
468
624
  F: __dxlog_file2,
469
- L: 59,
625
+ L: 61,
470
626
  S: void 0,
471
627
  C: (f, a) => f(...a)
472
628
  });
@@ -510,7 +666,7 @@ var toDXN = (ref) => {
510
666
  }
511
667
  invariant(typeof ref["/"] === "string", void 0, {
512
668
  F: __dxlog_file2,
513
- L: 108,
669
+ L: 110,
514
670
  S: void 0,
515
671
  A: [
516
672
  "typeof ref['/'] === 'string'",
@@ -520,193 +676,54 @@ var toDXN = (ref) => {
520
676
  return DXN.parse(ref["/"]);
521
677
  };
522
678
 
523
- // packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/meta.tsx
524
- import React4 from "react";
525
- import { create as create3, getMeta as getEchoMeta } from "@dxos/echo-schema";
526
- import { GameType } from "@dxos/plugin-chess/types";
527
- import { FileType } from "@dxos/plugin-ipfs/types";
528
- import { DocumentType } from "@dxos/plugin-markdown";
529
- import { DiagramType } from "@dxos/plugin-sketch/types";
530
- import { CollectionType, MessageType as MessageType2 } from "@dxos/plugin-space";
531
- import { Input as Input2 } from "@dxos/react-ui";
532
- import { safeParseInt } from "@dxos/util";
533
- var stateInitialValues = {
534
- schemas: [
535
- // TODO(burdon): Get all schema from API.
536
- DocumentType,
537
- FileType,
538
- GameType,
539
- MessageType2,
540
- DiagramType,
541
- CollectionType
542
- ],
543
- selectedSchema: {}
544
- };
545
- var state = create3(stateInitialValues);
546
- var USERFUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
547
- var getFunctionMetaExtension = (trigger, script) => {
548
- if (script) {
549
- const meta = getEchoMeta(script).keys.find((key) => key.source === USERFUNCTIONS_PRESET_META_KEY);
550
- const extension = meta && metaExtensions[meta.id];
551
- if (extension) {
552
- return extension;
553
- }
554
- }
555
- return trigger?.function ? metaExtensions[trigger.function] : metaExtensions["dxos.org/function/gpt"];
556
- };
557
- var DefaultMetaProps = ({ meta }) => {
558
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null);
559
- };
560
- var ChessMetaProps = ({ meta }) => {
561
- if (!meta) {
562
- return null;
563
- }
564
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
565
- label: "Level"
566
- }, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
567
- type: "number",
568
- value: meta.level ?? 1,
569
- onChange: (event) => meta.level = safeParseInt(event.target.value),
570
- placeholder: "Engine strength."
571
- })));
572
- };
573
- var EmailWorkerMetaProps = ({ meta }) => {
574
- if (!meta) {
575
- return null;
576
- }
577
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
578
- label: "Account"
579
- }, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
580
- value: meta.account ?? "",
581
- onChange: (event) => meta.account = event.target.value,
582
- placeholder: "https://"
583
- })));
584
- };
585
- var ChainPromptMetaProps = ({ meta, triggerId }) => {
586
- const schema = triggerId ? state.selectedSchema[triggerId] : void 0;
587
- if (!meta) {
588
- return null;
589
- }
590
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
591
- label: "Model"
592
- }, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
593
- value: meta.model ?? "",
594
- onChange: (event) => meta.model = event.target.value,
595
- placeholder: "llama2"
596
- })), /* @__PURE__ */ React4.createElement(InputRow, {
597
- label: "Presets"
598
- }, /* @__PURE__ */ React4.createElement(ChainPresets, {
599
- presets: chainPresets,
600
- onSelect: (preset) => {
601
- meta.prompt = preset.createPrompt();
602
- }
603
- })), meta.prompt && /* @__PURE__ */ React4.createElement(InputRow, {
604
- label: "Prompt"
605
- }, /* @__PURE__ */ React4.createElement(PromptEditor, {
606
- prompt: meta.prompt,
607
- schema
608
- })));
609
- };
610
- var EmbeddingMetaProps = ({ meta }) => {
611
- if (!meta) {
612
- return null;
613
- }
614
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(InputRow, {
615
- label: "Model"
616
- }, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
617
- value: meta.model ?? "",
618
- onChange: (event) => meta.model = event.target.value,
619
- placeholder: "llama2"
620
- })));
621
- };
622
- var metaExtensions = {
623
- __DEFAULT__: {
624
- initialValue: () => ({}),
625
- component: DefaultMetaProps
626
- },
627
- "dxos.org/function/chess": {
628
- initialValue: () => ({
629
- level: 2
630
- }),
631
- component: ChessMetaProps
632
- },
633
- "dxos.org/function/email-worker": {
634
- initialValue: () => ({
635
- account: "hello@dxos.network"
636
- }),
637
- component: EmailWorkerMetaProps
638
- },
639
- "dxos.org/function/gpt": {
640
- initialValue: () => ({
641
- model: "llama2"
642
- }),
643
- component: ChainPromptMetaProps
644
- },
645
- "dxos.org/function/embedding": {
646
- initialValue: () => ({
647
- model: "llama2"
648
- }),
649
- component: EmbeddingMetaProps
650
- }
651
- };
652
-
653
- // packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/TriggerEditor.tsx
654
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/TriggerEditor.tsx";
655
- var triggerTypes = [
656
- "subscription",
657
- "timer",
658
- "webhook",
659
- "websocket"
660
- ];
679
+ // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
680
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts";
661
681
  var registerTriggersMutex = new Mutex();
662
- var TriggerEditor = ({ space, trigger }) => {
663
- const { t } = useTranslation2(AUTOMATION_PLUGIN);
682
+ var useLocalTriggerManager = (space) => {
664
683
  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 triggerLabels = {
671
- subscription: t("trigger type subscription"),
672
- timer: t("trigger type timer"),
673
- webhook: t("trigger type webhook"),
674
- websocket: t("trigger type websocket")
675
- };
676
684
  const [registry] = useState(/* @__PURE__ */ new Map());
677
685
  const triggers = useQuery(space, Filter2.schema(FunctionTrigger));
678
686
  useEffect(() => {
679
687
  setTimeout(async () => {
680
688
  await registerTriggersMutex.executeSynchronized(async () => {
681
689
  const deprecated = new Set(Array.from(registry.keys()));
682
- log3.info("triggers", {
690
+ log3("triggers", {
683
691
  deprecated,
684
- all: triggers.map((t2) => t2.id),
685
- enabled: triggers.filter((t2) => t2.enabled).map((t2) => t2.id)
692
+ all: triggers.map((t) => t.id),
693
+ enabled: triggers.filter((t) => t.enabled).map((t) => t.id)
686
694
  }, {
687
695
  F: __dxlog_file3,
688
- L: 56,
696
+ L: 31,
689
697
  S: void 0,
690
698
  C: (f, a) => f(...a)
691
699
  });
692
- for (const trigger2 of triggers) {
693
- if (trigger2.enabled) {
694
- if (registry.has(trigger2.id)) {
695
- deprecated.delete(trigger2.id);
700
+ for (const trigger of triggers) {
701
+ if (trigger.enabled) {
702
+ if (registry.has(trigger.id)) {
703
+ deprecated.delete(trigger.id);
696
704
  continue;
697
705
  }
698
- log3.info("activating trigger", trigger2.id, {
706
+ log3.info("activating trigger", trigger.id, {
699
707
  F: __dxlog_file3,
700
- L: 68,
708
+ L: 43,
701
709
  S: void 0,
702
710
  C: (f, a) => f(...a)
703
711
  });
704
712
  const ctx = new Context(void 0, {
705
713
  F: __dxlog_file3,
706
- L: 70
714
+ L: 45
715
+ });
716
+ registry.set(trigger.id, ctx);
717
+ const triggerSpec = trigger.spec;
718
+ invariant2(triggerSpec, void 0, {
719
+ F: __dxlog_file3,
720
+ L: 48,
721
+ S: void 0,
722
+ A: [
723
+ "triggerSpec",
724
+ ""
725
+ ]
707
726
  });
708
- registry.set(trigger2.id, ctx);
709
- const triggerSpec = trigger2.spec;
710
727
  let triggerFactory;
711
728
  if (triggerSpec.type === "subscription") {
712
729
  triggerFactory = createSubscriptionTrigger;
@@ -717,14 +734,14 @@ var TriggerEditor = ({ space, trigger }) => {
717
734
  type: triggerSpec.type
718
735
  }, {
719
736
  F: __dxlog_file3,
720
- L: 80,
737
+ L: 56,
721
738
  S: void 0,
722
739
  C: (f, a) => f(...a)
723
740
  });
724
741
  continue;
725
742
  }
726
- await triggerFactory(ctx, space, trigger2.spec, (data) => {
727
- return invokeFunction(client, space, trigger2, data);
743
+ await triggerFactory(ctx, space, trigger.spec, (data) => {
744
+ return invokeFunction(client, space, trigger, data);
728
745
  });
729
746
  }
730
747
  }
@@ -747,7 +764,31 @@ var TriggerEditor = ({ space, trigger }) => {
747
764
  }
748
765
  };
749
766
  }, []);
750
- useEffect(() => {
767
+ };
768
+
769
+ // packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/TriggerEditor.tsx
770
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/TriggerEditor/TriggerEditor.tsx";
771
+ var triggerTypes = [
772
+ "timer",
773
+ "webhook",
774
+ "websocket",
775
+ "subscription"
776
+ ];
777
+ var TriggerEditor = ({ space, trigger }) => {
778
+ const { t } = useTranslation2(AUTOMATION_PLUGIN);
779
+ const scripts = useQuery2(space, Filter3.schema(ScriptType));
780
+ const script = useMemo(() => scripts.find((script2) => script2.id === trigger.function), [
781
+ trigger.function,
782
+ scripts
783
+ ]);
784
+ useLocalTriggerManager(space);
785
+ const triggerLabels = {
786
+ subscription: t("trigger type subscription"),
787
+ timer: t("trigger type timer"),
788
+ webhook: t("trigger type webhook"),
789
+ websocket: t("trigger type websocket")
790
+ };
791
+ useEffect2(() => {
751
792
  void space.db.schemaRegistry.query().then((schemas) => {
752
793
  state.schemas = distinctBy([
753
794
  ...state.schemas,
@@ -758,11 +799,20 @@ var TriggerEditor = ({ space, trigger }) => {
758
799
  }, [
759
800
  space
760
801
  ]);
761
- useEffect(() => {
802
+ useEffect2(() => {
762
803
  const spec = trigger.spec;
804
+ invariant3(spec, void 0, {
805
+ F: __dxlog_file4,
806
+ L: 65,
807
+ S: void 0,
808
+ A: [
809
+ "spec",
810
+ ""
811
+ ]
812
+ });
763
813
  if (spec.type === "subscription") {
764
- if (spec.filter && spec.filter.length > 0) {
765
- const type = spec.filter[0].type;
814
+ if (spec.filter) {
815
+ const type = spec.filter.type;
766
816
  const foundSchema = state.schemas.find((schema) => schema.typename === type);
767
817
  if (foundSchema) {
768
818
  state.selectedSchema[trigger.id] = foundSchema;
@@ -773,7 +823,7 @@ var TriggerEditor = ({ space, trigger }) => {
773
823
  JSON.stringify(trigger.spec),
774
824
  state.schemas
775
825
  ]);
776
- useEffect(() => {
826
+ useEffect2(() => {
777
827
  if (!trigger.meta) {
778
828
  const extension = getFunctionMetaExtension(trigger, script);
779
829
  trigger.meta = extension?.initialValue?.();
@@ -793,7 +843,7 @@ var TriggerEditor = ({ space, trigger }) => {
793
843
  case "subscription": {
794
844
  trigger.spec = {
795
845
  type: "subscription",
796
- filter: []
846
+ filter: {}
797
847
  };
798
848
  break;
799
849
  }
@@ -824,6 +874,44 @@ var TriggerEditor = ({ space, trigger }) => {
824
874
  }
825
875
  };
826
876
  const TriggerMeta = getFunctionMetaExtension(trigger, script)?.component;
877
+ const test = true;
878
+ if (test) {
879
+ const object = {
880
+ spec: {
881
+ // type: 'timer',
882
+ type: "subscription",
883
+ // cron: '0 0 * * *'
884
+ filter: {
885
+ type: "dxos.org/type/Event"
886
+ }
887
+ }
888
+ };
889
+ return /* @__PURE__ */ React5.createElement(Form, {
890
+ schema: FunctionTriggerSchema,
891
+ values: object,
892
+ filter: (props) => props.filter((p) => p.name !== "meta"),
893
+ Custom: {
894
+ ["function"]: (props) => /* @__PURE__ */ React5.createElement(SelectInput, {
895
+ ...props,
896
+ // TODO(burdon): Query for functions.
897
+ options: [].map((value) => ({
898
+ value,
899
+ label: value
900
+ }))
901
+ }),
902
+ ["spec.type"]: (props) => /* @__PURE__ */ React5.createElement(SelectInput, {
903
+ ...props,
904
+ options: [
905
+ "timer",
906
+ "subscription"
907
+ ].map((value) => ({
908
+ value,
909
+ label: value
910
+ }))
911
+ })
912
+ }
913
+ });
914
+ }
827
915
  return /* @__PURE__ */ React5.createElement("div", {
828
916
  className: "flex flex-col py-1"
829
917
  }, /* @__PURE__ */ React5.createElement("table", {
@@ -853,7 +941,7 @@ var TriggerEditor = ({ space, trigger }) => {
853
941
  }), /* @__PURE__ */ React5.createElement(Select2.Portal, null, /* @__PURE__ */ React5.createElement(Select2.Content, null, /* @__PURE__ */ React5.createElement(Select2.Viewport, null, triggerTypes.map((trigger2) => /* @__PURE__ */ React5.createElement(Select2.Option, {
854
942
  key: trigger2,
855
943
  value: trigger2
856
- }, triggerLabels[trigger2])))))))), /* @__PURE__ */ React5.createElement("tbody", null, trigger.spec && /* @__PURE__ */ React5.createElement(TriggerSpec, {
944
+ }, triggerLabels[trigger2])))))))), /* @__PURE__ */ React5.createElement("tbody", null, trigger.spec && /* @__PURE__ */ React5.createElement(TriggerType, {
857
945
  space,
858
946
  spec: trigger.spec
859
947
  }), /* @__PURE__ */ React5.createElement(InputRow, {
@@ -863,7 +951,7 @@ var TriggerEditor = ({ space, trigger }) => {
863
951
  }, /* @__PURE__ */ React5.createElement(Input3.Switch, {
864
952
  checked: trigger.enabled,
865
953
  onCheckedChange: (checked) => trigger.enabled = !!checked
866
- })))), TriggerMeta && /* @__PURE__ */ React5.createElement("tbody", null, /* @__PURE__ */ React5.createElement("tr", null, /* @__PURE__ */ React5.createElement("td", null), /* @__PURE__ */ React5.createElement("td", {
954
+ })))), TriggerMeta && trigger.meta && /* @__PURE__ */ React5.createElement("tbody", null, /* @__PURE__ */ React5.createElement("tr", null, /* @__PURE__ */ React5.createElement("td", null), /* @__PURE__ */ React5.createElement("td", {
867
955
  className: "py-2"
868
956
  }, /* @__PURE__ */ React5.createElement("div", {
869
957
  className: "border-b border-separator"
@@ -877,16 +965,14 @@ var TriggerSpecSubscription = ({ spec }) => {
877
965
  return null;
878
966
  }
879
967
  const handleValueChange = (typename) => {
880
- spec.filter = [
881
- {
882
- type: typename
883
- }
884
- ];
968
+ spec.filter = {
969
+ type: typename
970
+ };
885
971
  };
886
972
  return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(InputRow, {
887
973
  label: t("trigger filter")
888
974
  }, /* @__PURE__ */ React5.createElement(Select2.Root, {
889
- value: spec.filter.length > 0 ? spec.filter[0].type : void 0,
975
+ value: spec.filter?.type,
890
976
  onValueChange: handleValueChange
891
977
  }, /* @__PURE__ */ React5.createElement(Select2.TriggerButton, {
892
978
  classNames: "w-full",
@@ -951,7 +1037,7 @@ var triggerRenderers = {
951
1037
  webhook: TriggerSpecWebhook,
952
1038
  websocket: TriggerSpecWebsocket
953
1039
  };
954
- var TriggerSpec = ({ space, spec }) => {
1040
+ var TriggerType = ({ space, spec }) => {
955
1041
  const Component = triggerRenderers[spec.type];
956
1042
  return Component ? /* @__PURE__ */ React5.createElement(Component, {
957
1043
  space,
@@ -960,7 +1046,7 @@ var TriggerSpec = ({ space, spec }) => {
960
1046
  };
961
1047
 
962
1048
  // packages/plugins/experimental/plugin-automation/src/components/index.ts
963
- var PromptContainer = lazy(() => import("./PromptContainer-3GUENQHE.mjs"));
1049
+ var PromptContainer = lazy(() => import("./PromptContainer-6CBNCUKQ.mjs"));
964
1050
 
965
1051
  // packages/plugins/experimental/plugin-automation/src/translations.ts
966
1052
  var translations_default = [
@@ -996,7 +1082,7 @@ var translations_default = [
996
1082
  ];
997
1083
 
998
1084
  // packages/plugins/experimental/plugin-automation/src/AutomationPlugin.tsx
999
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/AutomationPlugin.tsx";
1085
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/AutomationPlugin.tsx";
1000
1086
  var AutomationPlugin = () => {
1001
1087
  return {
1002
1088
  meta: meta_default,
@@ -1045,18 +1131,18 @@ var AutomationPlugin = () => {
1045
1131
  const metadataPlugin = resolvePlugin(plugins, parseMetadataResolverPlugin);
1046
1132
  const resolve = metadataPlugin?.provides.metadata.resolver;
1047
1133
  const client = clientPlugin?.provides.client;
1048
- invariant2(resolve, void 0, {
1049
- F: __dxlog_file4,
1050
- L: 55,
1134
+ invariant4(resolve, void 0, {
1135
+ F: __dxlog_file5,
1136
+ L: 52,
1051
1137
  S: void 0,
1052
1138
  A: [
1053
1139
  "resolve",
1054
1140
  ""
1055
1141
  ]
1056
1142
  });
1057
- invariant2(client, void 0, {
1058
- F: __dxlog_file4,
1059
- L: 56,
1143
+ invariant4(client, void 0, {
1144
+ F: __dxlog_file5,
1145
+ L: 53,
1060
1146
  S: void 0,
1061
1147
  A: [
1062
1148
  "client",