@powerhousedao/reactor-workflow 6.2.3-dev.24 → 6.2.3-dev.25

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.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { L as UnsupportedPieceFeatureError, R as unsupportedAuth, _ as FileTooLargeError, a as redactMessage, b as maxFileBytes, c as DEFAULT_EGRESS_POLICY, f as extractDedupeKey, n as containsRedactedMarker, o as rememberSecrets, r as redact, s as secretsFor, z as unsupportedTrigger } from "./redact-C2y8tU--.js";
2
- import { A as setPieceRegistryUrl, C as PieceWorkerError, D as ensurePieceBundle, E as pieceModuleRef, S as PieceWorker, T as localFirstResolver, _ as SecretDeletedError, a as CompositeBlockExecutor, b as secretRefFromId, c as parseBlockType, d as storeHandlers, f as BoundConnectionResolver, h as shapeConnection, i as ActivepiecesBlockExecutor, k as pieceRegistrySource, l as reactorHandlers, m as declaredConnectionIds, n as packagePieces, o as REACTOR_PORT_PIECE, r as runWorkflow, s as blockTypeParts, t as PieceRegistry, u as servesReactorPort, v as SecretNotFoundError, w as PieceWorkerTimeoutError, x as PieceWorkerPool, y as parseSecretRef } from "./piece-registry-CYXV_aEv.js";
1
+ import { B as unsupportedTrigger, L as UnsupportedPieceFeatureError, _ as FileTooLargeError, a as redactMessage, b as maxFileBytes, c as DEFAULT_EGRESS_POLICY, f as extractDedupeKey, n as containsRedactedMarker, o as rememberSecrets, r as redact, s as secretsFor, z as unsupportedAuth } from "./redact-DM3JhxdF.js";
2
+ import { A as setPieceRegistryUrl, C as PieceWorkerError, D as ensurePieceBundle, E as pieceModuleRef, S as PieceWorker, T as localFirstResolver, _ as SecretDeletedError, a as CompositeBlockExecutor, b as secretRefFromId, c as parseBlockType, d as storeHandlers, f as BoundConnectionResolver, h as shapeConnection, i as ActivepiecesBlockExecutor, k as pieceRegistrySource, l as reactorHandlers, m as declaredConnectionIds, n as packagePieces, o as REACTOR_PORT_PIECE, r as runWorkflow, s as blockTypeParts, t as PieceRegistry, u as servesReactorPort, v as SecretNotFoundError, w as PieceWorkerTimeoutError, x as PieceWorkerPool, y as parseSecretRef } from "./piece-registry-CAS4wiSA.js";
3
3
  import { WebhookHandshakeStrategy } from "@powerhousedao/pieces-framework";
4
4
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { open, readFile, rm } from "node:fs/promises";
@@ -332,7 +332,7 @@ function documentEventTree(actionInputChildren) {
332
332
  }
333
333
  //#endregion
334
334
  //#region src/reactor/unsupported-pieces.ts
335
- const SERVER_ONLY_PIECES = new Set([
335
+ const SERVER_ONLY_PIECES = /* @__PURE__ */ new Set([
336
336
  "@activepieces/piece-ai",
337
337
  "@activepieces/piece-text-ai",
338
338
  "@activepieces/piece-image-ai",
@@ -345,7 +345,7 @@ const SERVER_ONLY_PIECES = new Set([
345
345
  //#endregion
346
346
  //#region src/reactor/piece-catalog.ts
347
347
  const CATALOG_URL = "https://cloud.activepieces.com/api/v1/pieces";
348
- const CACHE_TTL_MS = 3600 * 1e3;
348
+ const CACHE_TTL_MS = 36e5;
349
349
  const logger$4 = childLogger(["workflow", "piece-catalog"]);
350
350
  function aiLast(audience) {
351
351
  return audience === "ai" ? 1 : 0;
@@ -356,7 +356,16 @@ function pieceUrl(packageName) {
356
356
  function reasonOf(feature) {
357
357
  return feature ? { unsupported: feature.reason } : {};
358
358
  }
359
+ function clientAuth(auth) {
360
+ if (!auth) return null;
361
+ const one = ({ unsupported, ...method }) => ({
362
+ ...method,
363
+ ...reasonOf(unsupported)
364
+ });
365
+ return Array.isArray(auth) ? auth.map(one) : one(auth);
366
+ }
359
367
  var CatalogStatusError = class extends Error {
368
+ status;
360
369
  constructor(url, status) {
361
370
  super(`${url} responded ${status}`);
362
371
  this.status = status;
@@ -523,7 +532,7 @@ function catalogEntry(descriptor, pieceName, version) {
523
532
  actionCount: descriptor.actions.length,
524
533
  triggerCount: descriptor.triggers.length,
525
534
  categories: descriptor.categories ?? [],
526
- auth: descriptor.auth ?? null,
535
+ auth: clientAuth(descriptor.auth),
527
536
  ...reasonOf(descriptor.unsupported)
528
537
  };
529
538
  }
@@ -540,7 +549,7 @@ function actionsResult(descriptor, pieceName, version) {
540
549
  audience: action.audience ?? null,
541
550
  ...reasonOf(descriptor.unsupported)
542
551
  })).sort((a, b) => aiLast(a.audience) - aiLast(b.audience)),
543
- auth: descriptor.auth ?? null
552
+ auth: clientAuth(descriptor.auth)
544
553
  };
545
554
  }
546
555
  function triggersResult(descriptor, pieceName, version) {
@@ -556,7 +565,7 @@ function triggersResult(descriptor, pieceName, version) {
556
565
  blockType: localBlockType(pieceName, trigger.name, "trigger"),
557
566
  ...reasonOf(descriptor.unsupported ?? trigger.unsupported)
558
567
  })),
559
- auth: descriptor.auth ?? null
568
+ auth: clientAuth(descriptor.auth)
560
569
  };
561
570
  }
562
571
  function localSearchHits(descriptor, pieceName) {
@@ -592,7 +601,7 @@ function detailResult(descriptor, pieceName, version) {
592
601
  logoUrl: descriptor.logoUrl ?? "",
593
602
  version,
594
603
  categories: descriptor.categories ?? [],
595
- auth: descriptor.auth ?? null,
604
+ auth: clientAuth(descriptor.auth),
596
605
  actions: Object.fromEntries(descriptor.actions.map((action) => [action.name, {
597
606
  name: action.name,
598
607
  displayName: action.displayName,
@@ -618,7 +627,7 @@ function detailResult(descriptor, pieceName, version) {
618
627
  }
619
628
  //#endregion
620
629
  //#region src/reactor/block-search.ts
621
- const INDEX_TTL_MS = 3600 * 1e3;
630
+ const INDEX_TTL_MS = 36e5;
622
631
  const DEFAULT_LIMIT = 30;
623
632
  const MAX_LIMIT = 100;
624
633
  function buildSearchIndex(raw) {
@@ -745,7 +754,7 @@ function searchBlocks(query, limit, local) {
745
754
  }
746
755
  //#endregion
747
756
  //#region src/reactor/reactor-port.ts
748
- const DRIVE_DOCUMENT_TYPES = new Set(["powerhouse/document-drive", "powerhouse/reactor-drive"]);
757
+ const DRIVE_DOCUMENT_TYPES = /* @__PURE__ */ new Set(["powerhouse/document-drive", "powerhouse/reactor-drive"]);
749
758
  const FIND_PAGE_LIMIT = 100;
750
759
  const DESIGN_TIME_WRITES_REFUSED = "Reactor writes are not available while resolving design-time options";
751
760
  const DESIGN_TIME_CALLER_REQUIRED = "Design-time reactor access requires an authenticated request";
@@ -791,6 +800,7 @@ function assertOperationsApplied(document, dispatched) {
791
800
  throw new Error(failed.map((operation) => `Action ${operation.action.type} failed: ${operation.error ?? "unknown error"}`).join("; "));
792
801
  }
793
802
  var SubgraphReactorPort = class {
803
+ host;
794
804
  constructor(host) {
795
805
  this.host = host;
796
806
  }
@@ -849,7 +859,8 @@ var SubgraphReactorPort = class {
849
859
  assertOperationsApplied(named, [naming]);
850
860
  return documentSummary(named, true);
851
861
  }
852
- const empty = withSignaturePolicy((await this.client.getDocumentModelModule(input.documentType)).utils.createDocument(), await this.client.getCreateSignaturePolicy());
862
+ const module = await this.client.getDocumentModelModule(input.documentType);
863
+ const empty = withSignaturePolicy(module.utils.createDocument(), await this.client.getCreateSignaturePolicy());
853
864
  if (input.name) empty.header.name = input.name;
854
865
  return documentSummary(await this.client.drives.addFile(target.driveId, empty, target.parentFolder), true);
855
866
  }
@@ -892,6 +903,8 @@ var SubgraphReactorPort = class {
892
903
  }
893
904
  };
894
905
  var ScopedDesignTimeReactorPort = class {
906
+ host;
907
+ caller;
895
908
  inner;
896
909
  constructor(host, caller) {
897
910
  this.host = host;
@@ -915,10 +928,10 @@ var ScopedDesignTimeReactorPort = class {
915
928
  return found.filter((_, index) => allowed[index]);
916
929
  }
917
930
  create(_input) {
918
- return Promise.reject(new Error(DESIGN_TIME_WRITES_REFUSED));
931
+ return Promise.reject(/* @__PURE__ */ new Error(DESIGN_TIME_WRITES_REFUSED));
919
932
  }
920
933
  execute(_input) {
921
- return Promise.reject(new Error(DESIGN_TIME_WRITES_REFUSED));
934
+ return Promise.reject(/* @__PURE__ */ new Error(DESIGN_TIME_WRITES_REFUSED));
922
935
  }
923
936
  async canRead(documentId) {
924
937
  if (!this.caller) return false;
@@ -952,7 +965,7 @@ function testPartitionKey(scope, workflowId) {
952
965
  return (scope === "PROJECT" ? `${PROJECT_SCOPE_KEY}#${workflowId}` : workflowId) + TEST_PARTITION_SUFFIX;
953
966
  }
954
967
  const CURSOR_KEY = "lastPoll";
955
- const MAX_CURSOR_SKEW_MS = 1440 * 6e4;
968
+ const MAX_CURSOR_SKEW_MS = 864e5;
956
969
  function isPlausibleCursor(value, now) {
957
970
  return typeof value === "number" && Number.isFinite(value) && value > 0 && value <= now + MAX_CURSOR_SKEW_MS;
958
971
  }
@@ -1007,6 +1020,8 @@ var ConnectorMismatchError = class extends Error {
1007
1020
  }
1008
1021
  };
1009
1022
  var DocumentConnectionResolver = class {
1023
+ host;
1024
+ secrets;
1010
1025
  constructor(host, secrets) {
1011
1026
  this.host = host;
1012
1027
  this.secrets = secrets;
@@ -1351,7 +1366,6 @@ function coreBlockDescriptor(blockType) {
1351
1366
  //#endregion
1352
1367
  //#region src/reactor/secret-store.ts
1353
1368
  const IV_BYTES = 12;
1354
- const TAG_BYTES = 16;
1355
1369
  const KEY_BYTES = 32;
1356
1370
  async function up$1(db) {
1357
1371
  await db.schema.createTable("secret").addColumn("id", "text", (col) => col.primaryKey()).addColumn("label", "text").addColumn("version", "integer", (col) => col.notNull()).addColumn("enc", "text").addColumn("status", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.notNull()).addColumn("updated_at", "text", (col) => col.notNull()).ifNotExists().execute();
@@ -1376,6 +1390,8 @@ function loadKey(options) {
1376
1390
  return key;
1377
1391
  }
1378
1392
  var LocalEncryptedSecretStore = class LocalEncryptedSecretStore {
1393
+ db;
1394
+ key;
1379
1395
  constructor(db, key) {
1380
1396
  this.db = db;
1381
1397
  this.key = key;
@@ -1398,10 +1414,10 @@ var LocalEncryptedSecretStore = class LocalEncryptedSecretStore {
1398
1414
  decrypt(enc) {
1399
1415
  const raw = Buffer.from(enc, "base64");
1400
1416
  const iv = raw.subarray(0, IV_BYTES);
1401
- const tag = raw.subarray(IV_BYTES, IV_BYTES + TAG_BYTES);
1417
+ const tag = raw.subarray(IV_BYTES, 28);
1402
1418
  const decipher = createDecipheriv("aes-256-gcm", this.key, iv);
1403
1419
  decipher.setAuthTag(tag);
1404
- return Buffer.concat([decipher.update(raw.subarray(IV_BYTES + TAG_BYTES)), decipher.final()]).toString("utf8");
1420
+ return Buffer.concat([decipher.update(raw.subarray(28)), decipher.final()]).toString("utf8");
1405
1421
  }
1406
1422
  async row(ref) {
1407
1423
  const id = parseSecretRef(ref);
@@ -1493,7 +1509,10 @@ async function up(db) {
1493
1509
  } catch {}
1494
1510
  await db.schema.createTable("trigger_state").addColumn("workflow_id", "text", (col) => col.primaryKey()).addColumn("block_type", "text", (col) => col.notNull()).addColumn("config_hash", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull()).addColumn("store_state", "text", (col) => col.notNull()).addColumn("interval_ms", "integer", (col) => col.notNull()).addColumn("next_poll_at", "text").addColumn("last_poll_at", "text").addColumn("last_error", "text").addColumn("consecutive_failures", "integer", (col) => col.notNull()).addColumn("lease_owner", "text").addColumn("lease_expires_at", "text").addColumn("updated_at", "text", (col) => col.notNull()).ifNotExists().execute();
1495
1511
  await db.schema.createTable("trigger_dedupe").addColumn("workflow_id", "text", (col) => col.notNull()).addColumn("dedupe_key", "text", (col) => col.notNull()).addColumn("run_id", "text").addColumn("created_at", "text", (col) => col.notNull()).addPrimaryKeyConstraint("trigger_dedupe_pk", ["workflow_id", "dedupe_key"]).ifNotExists().execute();
1496
- await db.schema.createTable("step_execution").addColumn("id", "text", (col) => col.primaryKey()).addColumn("run_id", "text", (col) => col.notNull()).addColumn("ordinal", "integer", (col) => col.notNull()).addColumn("step_id", "text", (col) => col.notNull()).addColumn("step_key", "text", (col) => col.notNull()).addColumn("block_type", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull()).addColumn("input", "text").addColumn("output", "text").addColumn("port", "text").addColumn("error", "text").addUniqueConstraint("step_execution_run_step", ["run_id", "step_id"]).ifNotExists().execute();
1512
+ await db.schema.createTable("step_execution").addColumn("id", "text", (col) => col.primaryKey()).addColumn("run_id", "text", (col) => col.notNull()).addColumn("ordinal", "integer", (col) => col.notNull()).addColumn("step_id", "text", (col) => col.notNull()).addColumn("step_key", "text", (col) => col.notNull()).addColumn("block_type", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull()).addColumn("input", "text").addColumn("output", "text").addColumn("port", "text").addColumn("error", "text").addColumn("started_at", "text").addColumn("ended_at", "text").addUniqueConstraint("step_execution_run_step", ["run_id", "step_id"]).ifNotExists().execute();
1513
+ for (const column of ["started_at", "ended_at"]) try {
1514
+ await db.schema.alterTable("step_execution").addColumn(column, "text").execute();
1515
+ } catch {}
1497
1516
  try {
1498
1517
  await db.schema.alterTable("step_execution").addUniqueConstraint("step_execution_run_step", ["run_id", "step_id"]).execute();
1499
1518
  } catch (error) {
@@ -1617,7 +1636,7 @@ function warnIfOverPieceStoreLimits(scope, scopeKey, key, encoded) {
1617
1636
  const size = Buffer.byteLength(encoded, "utf8");
1618
1637
  if (size > 524288) logger$2.warn(`Migrated store value ${at} is ${size} bytes, over the ${PIECE_STORE_MAX_VALUE_BYTES} limit; writes to it will fail`);
1619
1638
  }
1620
- const PIECE_STORE_MAX_VALUE_BYTES = 512 * 1024;
1639
+ const PIECE_STORE_MAX_VALUE_BYTES = 524288;
1621
1640
  var PieceStoreLimitError = class extends Error {
1622
1641
  constructor(message) {
1623
1642
  super(message);
@@ -1642,7 +1661,9 @@ function stepValues(runId, ordinal, step) {
1642
1661
  input: jsonOrNull(redact(step.input)),
1643
1662
  output: jsonOrNull(redact(step.output)),
1644
1663
  port: step.port ?? null,
1645
- error: step.error ? redactMessage(step.error) : null
1664
+ error: step.error ? redactMessage(step.error) : null,
1665
+ started_at: step.startedAt ?? null,
1666
+ ended_at: step.endedAt ?? null
1646
1667
  };
1647
1668
  }
1648
1669
  function jsonOrNull(value) {
@@ -1654,6 +1675,8 @@ function jsonOrNull(value) {
1654
1675
  }
1655
1676
  }
1656
1677
  var WorkflowRunStore = class WorkflowRunStore {
1678
+ db;
1679
+ unmigrated;
1657
1680
  runsInFlight = /* @__PURE__ */ new Set();
1658
1681
  constructor(db, unmigrated) {
1659
1682
  this.db = db;
@@ -1661,7 +1684,8 @@ var WorkflowRunStore = class WorkflowRunStore {
1661
1684
  }
1662
1685
  static async create(relationalDb) {
1663
1686
  const db = await relationalDb.createNamespace("workflow_runtime");
1664
- const store = new WorkflowRunStore(db, await up(db));
1687
+ const unmigrated = await up(db);
1688
+ const store = new WorkflowRunStore(db, unmigrated);
1665
1689
  await store.recoverOrphanedRuns();
1666
1690
  await store.recoverAbandonedRuns();
1667
1691
  return store;
@@ -1784,7 +1808,9 @@ var WorkflowRunStore = class WorkflowRunStore {
1784
1808
  input: eb.ref("excluded.input"),
1785
1809
  output: eb.ref("excluded.output"),
1786
1810
  port: eb.ref("excluded.port"),
1787
- error: eb.ref("excluded.error")
1811
+ error: eb.ref("excluded.error"),
1812
+ started_at: eb.ref("excluded.started_at"),
1813
+ ended_at: eb.ref("excluded.ended_at")
1788
1814
  }))).execute();
1789
1815
  }
1790
1816
  async failRun(runId, error) {
@@ -1914,9 +1940,9 @@ var WorkflowRunStore = class WorkflowRunStore {
1914
1940
  const logger$1 = childLogger(["workflow", "trigger-supervisor"]);
1915
1941
  const SCHEDULE_TRIGGER_KIND = "schedule";
1916
1942
  const MIN_INTERVAL_MS = MIN_SCHEDULE_INTERVAL_MS;
1917
- const MAX_BACKOFF_MS = 30 * 6e4;
1943
+ const MAX_BACKOFF_MS = 18e5;
1918
1944
  const DEDUPE_TTL_MS = 3e4;
1919
- const DEFAULT_RECONCILE_INTERVAL_MS = 15 * 6e4;
1945
+ const DEFAULT_RECONCILE_INTERVAL_MS = 9e5;
1920
1946
  function isSchedule(binding) {
1921
1947
  return binding.kind === "schedule";
1922
1948
  }
@@ -1960,6 +1986,7 @@ function backoffMs(intervalMs, failures) {
1960
1986
  return Math.min(intervalMs * 2 ** failures, MAX_BACKOFF_MS);
1961
1987
  }
1962
1988
  var TriggerSupervisor = class {
1989
+ options;
1963
1990
  bindings = /* @__PURE__ */ new Map();
1964
1991
  worker;
1965
1992
  tickMs;
@@ -2424,19 +2451,19 @@ var TriggerSupervisor = class {
2424
2451
  //#region src/reactor/webhook.ts
2425
2452
  const WEBHOOK_BLOCK = "core#webhook";
2426
2453
  const WEBHOOK_TRIGGER_KIND = "webhook";
2427
- const ALGORITHMS = new Set([
2454
+ const ALGORITHMS = /* @__PURE__ */ new Set([
2428
2455
  "sha1",
2429
2456
  "sha256",
2430
2457
  "sha512"
2431
2458
  ]);
2432
- const ENCODINGS = new Set(["hex", "base64"]);
2433
- const SIGNED_SCHEMES = new Set([
2459
+ const ENCODINGS = /* @__PURE__ */ new Set(["hex", "base64"]);
2460
+ const SIGNED_SCHEMES = /* @__PURE__ */ new Set([
2434
2461
  "token",
2435
2462
  "hmac",
2436
2463
  "hmac-prefixed",
2437
2464
  "hmac-timestamped"
2438
2465
  ]);
2439
- const SCHEMES = new Set([
2466
+ const SCHEMES = /* @__PURE__ */ new Set([
2440
2467
  "none",
2441
2468
  "token",
2442
2469
  "hmac",
@@ -2630,7 +2657,7 @@ const CHILD_RELATIONSHIP = "child";
2630
2657
  function operationKey(op) {
2631
2658
  return op.context.ordinal > 0 ? `o:${op.context.ordinal}` : `${op.context.documentId}:${op.context.scope}:${op.context.branch}:${op.operation.index}`;
2632
2659
  }
2633
- const OPERATION_DEDUPE_TTL_MS = 1440 * 6e4;
2660
+ const OPERATION_DEDUPE_TTL_MS = 864e5;
2634
2661
  function stringField(record, key) {
2635
2662
  const value = record[key];
2636
2663
  return typeof value === "string" && value !== "" ? value : void 0;
@@ -2683,7 +2710,7 @@ function checkFailureDetail(error) {
2683
2710
  return pieceFailureDetail(error, `Connection check timed out after ${Math.round(CHECK_TIMEOUT_MS / 1e3)}s`);
2684
2711
  }
2685
2712
  const PIECE_WEBHOOK_KIND = "piece-webhook";
2686
- const SUPERVISED_KINDS = new Set([
2713
+ const SUPERVISED_KINDS = /* @__PURE__ */ new Set([
2687
2714
  "piece",
2688
2715
  "schedule",
2689
2716
  PIECE_WEBHOOK_KIND
@@ -2697,10 +2724,10 @@ function hasCredentials(state) {
2697
2724
  function isAbsentFromCatalog(error) {
2698
2725
  return error instanceof CatalogStatusError && error.status === 404;
2699
2726
  }
2700
- const PIECE_VERSION_MISS_TTL_MS = 5 * 6e4;
2727
+ const PIECE_VERSION_MISS_TTL_MS = 3e5;
2701
2728
  const PIECE_VERSION_LOOKUP_TIMEOUT_MS = 2e3;
2702
2729
  const UNREACHABLE_RETRY_MS = 3e4;
2703
- const UNREACHABLE_RETRY_CAP_MS = 15 * 6e4;
2730
+ const UNREACHABLE_RETRY_CAP_MS = 9e5;
2704
2731
  const UNAUTHORIZED = { status: 401 };
2705
2732
  const JSON_CONTENT_TYPE = "application/json; charset=utf-8";
2706
2733
  const DELIVERY_TIMEOUT_MS = Number(process.env.PH_WORKFLOWS_WEBHOOK_TIMEOUT_MS) || 3e4;
@@ -3725,7 +3752,7 @@ var WorkflowRuntimeService = class {
3725
3752
  const common = {
3726
3753
  displayName: descriptor.displayName,
3727
3754
  logoUrl: descriptor.logoUrl,
3728
- auth: descriptor.auth ?? null
3755
+ auth: clientAuth(descriptor.auth)
3729
3756
  };
3730
3757
  if (parsed.kind === "trigger") {
3731
3758
  const trigger = descriptor.triggers.find((entry) => entry.name === parsed.name);
@@ -4036,6 +4063,7 @@ function createWorkflowRuntime(deps) {
4036
4063
  const WORKFLOW_TRIGGERS_READ_MODEL = "workflow-triggers";
4037
4064
  const WORKFLOW_TRIGGERS_READ_MODEL_STAGE = "post_ready";
4038
4065
  var WorkflowTriggersReadModel = class extends BaseReadModel {
4066
+ runtime;
4039
4067
  freshRegistration = false;
4040
4068
  constructor(db, operationIndex, writeCache, consistencyTracker, runtime) {
4041
4069
  super(db, operationIndex, writeCache, consistencyTracker, {