@dxos/plugin-automation 0.7.0 → 0.7.1-staging.8709ba7

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