@powerhousedao/reactor-workflow 6.2.3-dev.24 → 6.2.3-dev.26
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/README.md +3 -1
- package/dist/{descriptor-E4swpRpd.js → descriptor-CtMB-wPx.js} +21 -12
- package/dist/descriptor-CtMB-wPx.js.map +1 -0
- package/dist/index.d.ts +69 -56
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +171 -64
- package/dist/index.js.map +1 -1
- package/dist/{piece-registry-CYXV_aEv.js → piece-registry-CAS4wiSA.js} +25 -7
- package/dist/{piece-registry-CYXV_aEv.js.map → piece-registry-CAS4wiSA.js.map} +1 -1
- package/dist/{piece-registry-q4bgYbXa.d.ts → piece-registry-D6dvy2OD.d.ts} +7 -37
- package/dist/piece-registry-D6dvy2OD.d.ts.map +1 -0
- package/dist/{redact-C2y8tU--.js → redact-DM3JhxdF.js} +16 -5
- package/dist/redact-DM3JhxdF.js.map +1 -0
- package/dist/testing.d.ts +37 -2
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +3 -3
- package/dist/worker-entry.d.ts +2 -1
- package/dist/worker-entry.js +36 -28
- package/dist/worker-entry.js.map +1 -1
- package/package.json +7 -7
- package/dist/descriptor-E4swpRpd.js.map +0 -1
- package/dist/piece-registry-q4bgYbXa.d.ts.map +0 -1
- package/dist/redact-C2y8tU--.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
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-
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
630
|
+
const INDEX_TTL_MS = 36e5;
|
|
622
631
|
const DEFAULT_LIMIT = 30;
|
|
623
632
|
const MAX_LIMIT = 100;
|
|
624
633
|
function buildSearchIndex(raw) {
|
|
@@ -744,8 +753,29 @@ function searchBlocks(query, limit, local) {
|
|
|
744
753
|
};
|
|
745
754
|
}
|
|
746
755
|
//#endregion
|
|
756
|
+
//#region src/reactor/run-scope.ts
|
|
757
|
+
const storage = new AsyncLocalStorage();
|
|
758
|
+
function withRunScope(scope, fn) {
|
|
759
|
+
return storage.run(scope, fn);
|
|
760
|
+
}
|
|
761
|
+
function currentWorkflowId() {
|
|
762
|
+
return storage.getStore()?.workflowId;
|
|
763
|
+
}
|
|
764
|
+
function currentRunId() {
|
|
765
|
+
return storage.getStore()?.runId ?? void 0;
|
|
766
|
+
}
|
|
767
|
+
function currentBoundConnections() {
|
|
768
|
+
return storage.getStore()?.connections;
|
|
769
|
+
}
|
|
770
|
+
function currentDocumentRecorder() {
|
|
771
|
+
return storage.getStore()?.recordDocuments;
|
|
772
|
+
}
|
|
773
|
+
function currentPieceWorker() {
|
|
774
|
+
return storage.getStore()?.pieceWorker;
|
|
775
|
+
}
|
|
776
|
+
//#endregion
|
|
747
777
|
//#region src/reactor/reactor-port.ts
|
|
748
|
-
const DRIVE_DOCUMENT_TYPES = new Set(["powerhouse/document-drive", "powerhouse/reactor-drive"]);
|
|
778
|
+
const DRIVE_DOCUMENT_TYPES = /* @__PURE__ */ new Set(["powerhouse/document-drive", "powerhouse/reactor-drive"]);
|
|
749
779
|
const FIND_PAGE_LIMIT = 100;
|
|
750
780
|
const DESIGN_TIME_WRITES_REFUSED = "Reactor writes are not available while resolving design-time options";
|
|
751
781
|
const DESIGN_TIME_CALLER_REQUIRED = "Design-time reactor access requires an authenticated request";
|
|
@@ -791,6 +821,7 @@ function assertOperationsApplied(document, dispatched) {
|
|
|
791
821
|
throw new Error(failed.map((operation) => `Action ${operation.action.type} failed: ${operation.error ?? "unknown error"}`).join("; "));
|
|
792
822
|
}
|
|
793
823
|
var SubgraphReactorPort = class {
|
|
824
|
+
host;
|
|
794
825
|
constructor(host) {
|
|
795
826
|
this.host = host;
|
|
796
827
|
}
|
|
@@ -818,7 +849,8 @@ var SubgraphReactorPort = class {
|
|
|
818
849
|
};
|
|
819
850
|
}
|
|
820
851
|
async get(input) {
|
|
821
|
-
|
|
852
|
+
const document = await this.client.get(input.documentId);
|
|
853
|
+
return this.handOver(documentSummary(document, true));
|
|
822
854
|
}
|
|
823
855
|
async find(input) {
|
|
824
856
|
const limit = input.limit ?? FIND_PAGE_LIMIT;
|
|
@@ -833,31 +865,38 @@ var SubgraphReactorPort = class {
|
|
|
833
865
|
results = (await Promise.all(types.map((type) => this.findByType(type, limit)))).flat();
|
|
834
866
|
}
|
|
835
867
|
const seen = /* @__PURE__ */ new Set();
|
|
836
|
-
return results.filter((document) => {
|
|
868
|
+
return this.handOver(results.filter((document) => {
|
|
837
869
|
if (seen.has(document.header.id)) return false;
|
|
838
870
|
seen.add(document.header.id);
|
|
839
871
|
return true;
|
|
840
|
-
}).filter((document) => matchesState(document, input.match)).map((document) => documentSummary(document, input.withState === true));
|
|
872
|
+
}).filter((document) => matchesState(document, input.match)).map((document) => documentSummary(document, input.withState === true)));
|
|
841
873
|
}
|
|
842
874
|
async create(input) {
|
|
843
875
|
const target = input.parentId ? await this.resolveDriveTarget(input.parentId) : null;
|
|
844
876
|
if (!target) {
|
|
845
877
|
const created = await this.client.createEmpty(input.documentType, { parentIdentifier: input.parentId });
|
|
846
|
-
if (!input.name) return documentSummary(created, true);
|
|
878
|
+
if (!input.name) return this.handOver(documentSummary(created, true));
|
|
847
879
|
const naming = createAction("SET_NAME", { name: input.name });
|
|
848
880
|
const named = await this.client.execute(created.header.id, "main", [naming]);
|
|
849
881
|
assertOperationsApplied(named, [naming]);
|
|
850
|
-
return documentSummary(named, true);
|
|
882
|
+
return this.handOver(documentSummary(named, true));
|
|
851
883
|
}
|
|
852
|
-
const
|
|
884
|
+
const module = await this.client.getDocumentModelModule(input.documentType);
|
|
885
|
+
const empty = withSignaturePolicy(module.utils.createDocument(), await this.client.getCreateSignaturePolicy());
|
|
853
886
|
if (input.name) empty.header.name = input.name;
|
|
854
|
-
|
|
887
|
+
const created = await this.client.drives.addFile(target.driveId, empty, target.parentFolder);
|
|
888
|
+
return this.handOver(documentSummary(created, true));
|
|
855
889
|
}
|
|
856
890
|
async execute(input) {
|
|
857
891
|
const actions = input.actions.map((entry) => createAction(entry.type, entry.input, void 0, void 0, entry.scope ?? "global"));
|
|
858
892
|
const document = await this.client.execute(input.documentId, input.branch ?? "main", actions);
|
|
859
893
|
assertOperationsApplied(document, input.actions);
|
|
860
|
-
return documentSummary(document, true);
|
|
894
|
+
return this.handOver(documentSummary(document, true));
|
|
895
|
+
}
|
|
896
|
+
async handOver(summaries) {
|
|
897
|
+
const record = currentDocumentRecorder();
|
|
898
|
+
if (record) await record((Array.isArray(summaries) ? summaries : [summaries]).map((summary) => summary.documentId));
|
|
899
|
+
return summaries;
|
|
861
900
|
}
|
|
862
901
|
async findByType(type, limit, parentId) {
|
|
863
902
|
try {
|
|
@@ -892,6 +931,8 @@ var SubgraphReactorPort = class {
|
|
|
892
931
|
}
|
|
893
932
|
};
|
|
894
933
|
var ScopedDesignTimeReactorPort = class {
|
|
934
|
+
host;
|
|
935
|
+
caller;
|
|
895
936
|
inner;
|
|
896
937
|
constructor(host, caller) {
|
|
897
938
|
this.host = host;
|
|
@@ -915,10 +956,10 @@ var ScopedDesignTimeReactorPort = class {
|
|
|
915
956
|
return found.filter((_, index) => allowed[index]);
|
|
916
957
|
}
|
|
917
958
|
create(_input) {
|
|
918
|
-
return Promise.reject(new Error(DESIGN_TIME_WRITES_REFUSED));
|
|
959
|
+
return Promise.reject(/* @__PURE__ */ new Error(DESIGN_TIME_WRITES_REFUSED));
|
|
919
960
|
}
|
|
920
961
|
execute(_input) {
|
|
921
|
-
return Promise.reject(new Error(DESIGN_TIME_WRITES_REFUSED));
|
|
962
|
+
return Promise.reject(/* @__PURE__ */ new Error(DESIGN_TIME_WRITES_REFUSED));
|
|
922
963
|
}
|
|
923
964
|
async canRead(documentId) {
|
|
924
965
|
if (!this.caller) return false;
|
|
@@ -926,24 +967,6 @@ var ScopedDesignTimeReactorPort = class {
|
|
|
926
967
|
}
|
|
927
968
|
};
|
|
928
969
|
//#endregion
|
|
929
|
-
//#region src/reactor/run-scope.ts
|
|
930
|
-
const storage = new AsyncLocalStorage();
|
|
931
|
-
function withRunScope(scope, fn) {
|
|
932
|
-
return storage.run(scope, fn);
|
|
933
|
-
}
|
|
934
|
-
function currentWorkflowId() {
|
|
935
|
-
return storage.getStore()?.workflowId;
|
|
936
|
-
}
|
|
937
|
-
function currentRunId() {
|
|
938
|
-
return storage.getStore()?.runId ?? void 0;
|
|
939
|
-
}
|
|
940
|
-
function currentBoundConnections() {
|
|
941
|
-
return storage.getStore()?.connections;
|
|
942
|
-
}
|
|
943
|
-
function currentPieceWorker() {
|
|
944
|
-
return storage.getStore()?.pieceWorker;
|
|
945
|
-
}
|
|
946
|
-
//#endregion
|
|
947
970
|
//#region src/reactor/piece-store-port.ts
|
|
948
971
|
const logger$3 = childLogger(["workflow", "piece-store"]);
|
|
949
972
|
const PROJECT_SCOPE_KEY = "reactor";
|
|
@@ -952,7 +975,7 @@ function testPartitionKey(scope, workflowId) {
|
|
|
952
975
|
return (scope === "PROJECT" ? `${PROJECT_SCOPE_KEY}#${workflowId}` : workflowId) + TEST_PARTITION_SUFFIX;
|
|
953
976
|
}
|
|
954
977
|
const CURSOR_KEY = "lastPoll";
|
|
955
|
-
const MAX_CURSOR_SKEW_MS =
|
|
978
|
+
const MAX_CURSOR_SKEW_MS = 864e5;
|
|
956
979
|
function isPlausibleCursor(value, now) {
|
|
957
980
|
return typeof value === "number" && Number.isFinite(value) && value > 0 && value <= now + MAX_CURSOR_SKEW_MS;
|
|
958
981
|
}
|
|
@@ -1007,6 +1030,8 @@ var ConnectorMismatchError = class extends Error {
|
|
|
1007
1030
|
}
|
|
1008
1031
|
};
|
|
1009
1032
|
var DocumentConnectionResolver = class {
|
|
1033
|
+
host;
|
|
1034
|
+
secrets;
|
|
1010
1035
|
constructor(host, secrets) {
|
|
1011
1036
|
this.host = host;
|
|
1012
1037
|
this.secrets = secrets;
|
|
@@ -1351,7 +1376,6 @@ function coreBlockDescriptor(blockType) {
|
|
|
1351
1376
|
//#endregion
|
|
1352
1377
|
//#region src/reactor/secret-store.ts
|
|
1353
1378
|
const IV_BYTES = 12;
|
|
1354
|
-
const TAG_BYTES = 16;
|
|
1355
1379
|
const KEY_BYTES = 32;
|
|
1356
1380
|
async function up$1(db) {
|
|
1357
1381
|
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 +1400,8 @@ function loadKey(options) {
|
|
|
1376
1400
|
return key;
|
|
1377
1401
|
}
|
|
1378
1402
|
var LocalEncryptedSecretStore = class LocalEncryptedSecretStore {
|
|
1403
|
+
db;
|
|
1404
|
+
key;
|
|
1379
1405
|
constructor(db, key) {
|
|
1380
1406
|
this.db = db;
|
|
1381
1407
|
this.key = key;
|
|
@@ -1398,10 +1424,10 @@ var LocalEncryptedSecretStore = class LocalEncryptedSecretStore {
|
|
|
1398
1424
|
decrypt(enc) {
|
|
1399
1425
|
const raw = Buffer.from(enc, "base64");
|
|
1400
1426
|
const iv = raw.subarray(0, IV_BYTES);
|
|
1401
|
-
const tag = raw.subarray(IV_BYTES,
|
|
1427
|
+
const tag = raw.subarray(IV_BYTES, 28);
|
|
1402
1428
|
const decipher = createDecipheriv("aes-256-gcm", this.key, iv);
|
|
1403
1429
|
decipher.setAuthTag(tag);
|
|
1404
|
-
return Buffer.concat([decipher.update(raw.subarray(
|
|
1430
|
+
return Buffer.concat([decipher.update(raw.subarray(28)), decipher.final()]).toString("utf8");
|
|
1405
1431
|
}
|
|
1406
1432
|
async row(ref) {
|
|
1407
1433
|
const id = parseSecretRef(ref);
|
|
@@ -1493,12 +1519,16 @@ async function up(db) {
|
|
|
1493
1519
|
} catch {}
|
|
1494
1520
|
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
1521
|
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();
|
|
1522
|
+
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();
|
|
1523
|
+
for (const column of ["started_at", "ended_at"]) try {
|
|
1524
|
+
await db.schema.alterTable("step_execution").addColumn(column, "text").execute();
|
|
1525
|
+
} catch {}
|
|
1497
1526
|
try {
|
|
1498
1527
|
await db.schema.alterTable("step_execution").addUniqueConstraint("step_execution_run_step", ["run_id", "step_id"]).execute();
|
|
1499
1528
|
} catch (error) {
|
|
1500
1529
|
if (!isDuplicateObject(error)) throw new Error(`Could not add the step_execution (run_id, step_id) unique constraint, which per-step journaling upserts against: ${errorMessage(error)}`, { cause: error });
|
|
1501
1530
|
}
|
|
1531
|
+
await db.schema.createTable("run_document").addColumn("run_id", "text", (col) => col.notNull()).addColumn("document_id", "text", (col) => col.notNull()).addPrimaryKeyConstraint("run_document_pk", ["run_id", "document_id"]).ifNotExists().execute();
|
|
1502
1532
|
await db.schema.createTable("piece_store").addColumn("scope", "text", (col) => col.notNull()).addColumn("scope_key", "text", (col) => col.notNull()).addColumn("key", "text", (col) => col.notNull()).addColumn("value", "text", (col) => col.notNull()).addColumn("updated_at", "text", (col) => col.notNull()).addPrimaryKeyConstraint("piece_store_pk", [
|
|
1503
1533
|
"scope",
|
|
1504
1534
|
"scope_key",
|
|
@@ -1617,7 +1647,7 @@ function warnIfOverPieceStoreLimits(scope, scopeKey, key, encoded) {
|
|
|
1617
1647
|
const size = Buffer.byteLength(encoded, "utf8");
|
|
1618
1648
|
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
1649
|
}
|
|
1620
|
-
const PIECE_STORE_MAX_VALUE_BYTES =
|
|
1650
|
+
const PIECE_STORE_MAX_VALUE_BYTES = 524288;
|
|
1621
1651
|
var PieceStoreLimitError = class extends Error {
|
|
1622
1652
|
constructor(message) {
|
|
1623
1653
|
super(message);
|
|
@@ -1642,7 +1672,9 @@ function stepValues(runId, ordinal, step) {
|
|
|
1642
1672
|
input: jsonOrNull(redact(step.input)),
|
|
1643
1673
|
output: jsonOrNull(redact(step.output)),
|
|
1644
1674
|
port: step.port ?? null,
|
|
1645
|
-
error: step.error ? redactMessage(step.error) : null
|
|
1675
|
+
error: step.error ? redactMessage(step.error) : null,
|
|
1676
|
+
started_at: step.startedAt ?? null,
|
|
1677
|
+
ended_at: step.endedAt ?? null
|
|
1646
1678
|
};
|
|
1647
1679
|
}
|
|
1648
1680
|
function jsonOrNull(value) {
|
|
@@ -1654,6 +1686,8 @@ function jsonOrNull(value) {
|
|
|
1654
1686
|
}
|
|
1655
1687
|
}
|
|
1656
1688
|
var WorkflowRunStore = class WorkflowRunStore {
|
|
1689
|
+
db;
|
|
1690
|
+
unmigrated;
|
|
1657
1691
|
runsInFlight = /* @__PURE__ */ new Set();
|
|
1658
1692
|
constructor(db, unmigrated) {
|
|
1659
1693
|
this.db = db;
|
|
@@ -1661,7 +1695,8 @@ var WorkflowRunStore = class WorkflowRunStore {
|
|
|
1661
1695
|
}
|
|
1662
1696
|
static async create(relationalDb) {
|
|
1663
1697
|
const db = await relationalDb.createNamespace("workflow_runtime");
|
|
1664
|
-
const
|
|
1698
|
+
const unmigrated = await up(db);
|
|
1699
|
+
const store = new WorkflowRunStore(db, unmigrated);
|
|
1665
1700
|
await store.recoverOrphanedRuns();
|
|
1666
1701
|
await store.recoverAbandonedRuns();
|
|
1667
1702
|
return store;
|
|
@@ -1784,7 +1819,9 @@ var WorkflowRunStore = class WorkflowRunStore {
|
|
|
1784
1819
|
input: eb.ref("excluded.input"),
|
|
1785
1820
|
output: eb.ref("excluded.output"),
|
|
1786
1821
|
port: eb.ref("excluded.port"),
|
|
1787
|
-
error: eb.ref("excluded.error")
|
|
1822
|
+
error: eb.ref("excluded.error"),
|
|
1823
|
+
started_at: eb.ref("excluded.started_at"),
|
|
1824
|
+
ended_at: eb.ref("excluded.ended_at")
|
|
1788
1825
|
}))).execute();
|
|
1789
1826
|
}
|
|
1790
1827
|
async failRun(runId, error) {
|
|
@@ -1808,6 +1845,16 @@ var WorkflowRunStore = class WorkflowRunStore {
|
|
|
1808
1845
|
async getSteps(runId) {
|
|
1809
1846
|
return this.db.selectFrom("step_execution").selectAll().where("run_id", "=", runId).orderBy("ordinal", "asc").execute();
|
|
1810
1847
|
}
|
|
1848
|
+
async recordRunDocuments(runId, documentIds) {
|
|
1849
|
+
if (documentIds.length === 0) return;
|
|
1850
|
+
await this.db.insertInto("run_document").values([...new Set(documentIds)].map((documentId) => ({
|
|
1851
|
+
run_id: runId,
|
|
1852
|
+
document_id: documentId
|
|
1853
|
+
}))).onConflict((oc) => oc.columns(["run_id", "document_id"]).doNothing()).execute();
|
|
1854
|
+
}
|
|
1855
|
+
async getRunDocuments(runId) {
|
|
1856
|
+
return (await this.db.selectFrom("run_document").select("document_id").where("run_id", "=", runId).execute()).map((row) => row.document_id);
|
|
1857
|
+
}
|
|
1811
1858
|
async getTriggerState(workflowId) {
|
|
1812
1859
|
return this.db.selectFrom("trigger_state").selectAll().where("workflow_id", "=", workflowId).executeTakeFirst();
|
|
1813
1860
|
}
|
|
@@ -1914,9 +1961,9 @@ var WorkflowRunStore = class WorkflowRunStore {
|
|
|
1914
1961
|
const logger$1 = childLogger(["workflow", "trigger-supervisor"]);
|
|
1915
1962
|
const SCHEDULE_TRIGGER_KIND = "schedule";
|
|
1916
1963
|
const MIN_INTERVAL_MS = MIN_SCHEDULE_INTERVAL_MS;
|
|
1917
|
-
const MAX_BACKOFF_MS =
|
|
1964
|
+
const MAX_BACKOFF_MS = 18e5;
|
|
1918
1965
|
const DEDUPE_TTL_MS = 3e4;
|
|
1919
|
-
const DEFAULT_RECONCILE_INTERVAL_MS =
|
|
1966
|
+
const DEFAULT_RECONCILE_INTERVAL_MS = 9e5;
|
|
1920
1967
|
function isSchedule(binding) {
|
|
1921
1968
|
return binding.kind === "schedule";
|
|
1922
1969
|
}
|
|
@@ -1960,6 +2007,7 @@ function backoffMs(intervalMs, failures) {
|
|
|
1960
2007
|
return Math.min(intervalMs * 2 ** failures, MAX_BACKOFF_MS);
|
|
1961
2008
|
}
|
|
1962
2009
|
var TriggerSupervisor = class {
|
|
2010
|
+
options;
|
|
1963
2011
|
bindings = /* @__PURE__ */ new Map();
|
|
1964
2012
|
worker;
|
|
1965
2013
|
tickMs;
|
|
@@ -2424,19 +2472,19 @@ var TriggerSupervisor = class {
|
|
|
2424
2472
|
//#region src/reactor/webhook.ts
|
|
2425
2473
|
const WEBHOOK_BLOCK = "core#webhook";
|
|
2426
2474
|
const WEBHOOK_TRIGGER_KIND = "webhook";
|
|
2427
|
-
const ALGORITHMS = new Set([
|
|
2475
|
+
const ALGORITHMS = /* @__PURE__ */ new Set([
|
|
2428
2476
|
"sha1",
|
|
2429
2477
|
"sha256",
|
|
2430
2478
|
"sha512"
|
|
2431
2479
|
]);
|
|
2432
|
-
const ENCODINGS = new Set(["hex", "base64"]);
|
|
2433
|
-
const SIGNED_SCHEMES = new Set([
|
|
2480
|
+
const ENCODINGS = /* @__PURE__ */ new Set(["hex", "base64"]);
|
|
2481
|
+
const SIGNED_SCHEMES = /* @__PURE__ */ new Set([
|
|
2434
2482
|
"token",
|
|
2435
2483
|
"hmac",
|
|
2436
2484
|
"hmac-prefixed",
|
|
2437
2485
|
"hmac-timestamped"
|
|
2438
2486
|
]);
|
|
2439
|
-
const SCHEMES = new Set([
|
|
2487
|
+
const SCHEMES = /* @__PURE__ */ new Set([
|
|
2440
2488
|
"none",
|
|
2441
2489
|
"token",
|
|
2442
2490
|
"hmac",
|
|
@@ -2630,11 +2678,26 @@ const CHILD_RELATIONSHIP = "child";
|
|
|
2630
2678
|
function operationKey(op) {
|
|
2631
2679
|
return op.context.ordinal > 0 ? `o:${op.context.ordinal}` : `${op.context.documentId}:${op.context.scope}:${op.context.branch}:${op.operation.index}`;
|
|
2632
2680
|
}
|
|
2633
|
-
const OPERATION_DEDUPE_TTL_MS =
|
|
2681
|
+
const OPERATION_DEDUPE_TTL_MS = 864e5;
|
|
2634
2682
|
function stringField(record, key) {
|
|
2635
2683
|
const value = record[key];
|
|
2636
2684
|
return typeof value === "string" && value !== "" ? value : void 0;
|
|
2637
2685
|
}
|
|
2686
|
+
function journaledTriggerDocumentIds(payload) {
|
|
2687
|
+
if (payload === null) return [];
|
|
2688
|
+
try {
|
|
2689
|
+
return triggerDocumentIds(JSON.parse(payload));
|
|
2690
|
+
} catch {
|
|
2691
|
+
return [];
|
|
2692
|
+
}
|
|
2693
|
+
}
|
|
2694
|
+
function triggerDocumentIds(payload) {
|
|
2695
|
+
const record = inputRecord(payload);
|
|
2696
|
+
return [...new Set([stringField(record, "documentId"), stringField(record, "driveId")].filter((id) => id !== void 0))];
|
|
2697
|
+
}
|
|
2698
|
+
function isAbsent(error) {
|
|
2699
|
+
return error instanceof Error && (error.name === "DocumentNotFoundError" || error.name === "DocumentDeletedError");
|
|
2700
|
+
}
|
|
2638
2701
|
function inputRecord(input) {
|
|
2639
2702
|
if (input === null || typeof input !== "object") return {};
|
|
2640
2703
|
return input;
|
|
@@ -2683,7 +2746,7 @@ function checkFailureDetail(error) {
|
|
|
2683
2746
|
return pieceFailureDetail(error, `Connection check timed out after ${Math.round(CHECK_TIMEOUT_MS / 1e3)}s`);
|
|
2684
2747
|
}
|
|
2685
2748
|
const PIECE_WEBHOOK_KIND = "piece-webhook";
|
|
2686
|
-
const SUPERVISED_KINDS = new Set([
|
|
2749
|
+
const SUPERVISED_KINDS = /* @__PURE__ */ new Set([
|
|
2687
2750
|
"piece",
|
|
2688
2751
|
"schedule",
|
|
2689
2752
|
PIECE_WEBHOOK_KIND
|
|
@@ -2697,10 +2760,10 @@ function hasCredentials(state) {
|
|
|
2697
2760
|
function isAbsentFromCatalog(error) {
|
|
2698
2761
|
return error instanceof CatalogStatusError && error.status === 404;
|
|
2699
2762
|
}
|
|
2700
|
-
const PIECE_VERSION_MISS_TTL_MS =
|
|
2763
|
+
const PIECE_VERSION_MISS_TTL_MS = 3e5;
|
|
2701
2764
|
const PIECE_VERSION_LOOKUP_TIMEOUT_MS = 2e3;
|
|
2702
2765
|
const UNREACHABLE_RETRY_MS = 3e4;
|
|
2703
|
-
const UNREACHABLE_RETRY_CAP_MS =
|
|
2766
|
+
const UNREACHABLE_RETRY_CAP_MS = 9e5;
|
|
2704
2767
|
const UNAUTHORIZED = { status: 401 };
|
|
2705
2768
|
const JSON_CONTENT_TYPE = "application/json; charset=utf-8";
|
|
2706
2769
|
const DELIVERY_TIMEOUT_MS = Number(process.env.PH_WORKFLOWS_WEBHOOK_TIMEOUT_MS) || 3e4;
|
|
@@ -3465,7 +3528,7 @@ var WorkflowRuntimeService = class {
|
|
|
3465
3528
|
if (scope.length === 0) return [];
|
|
3466
3529
|
} else if (!ctx) return [];
|
|
3467
3530
|
const rows = await store.listRuns(scope, args.limit ?? 25);
|
|
3468
|
-
const readable = await this.readableRows(rows, (row) => row.workflow_id, ctx);
|
|
3531
|
+
const readable = await this.servedRuns(await this.readableRows(rows, (row) => row.workflow_id, ctx), ctx);
|
|
3469
3532
|
return Promise.all(readable.map(async (row) => ({
|
|
3470
3533
|
row,
|
|
3471
3534
|
steps: await store.getSteps(row.id)
|
|
@@ -3477,14 +3540,16 @@ var WorkflowRuntimeService = class {
|
|
|
3477
3540
|
const row = await store.getRun(runId);
|
|
3478
3541
|
if (!row) return null;
|
|
3479
3542
|
if (!await this.canReadDocument(row.workflow_id, ctx)) return null;
|
|
3543
|
+
if ((await this.servedRuns([row], ctx)).length === 0) return null;
|
|
3480
3544
|
return {
|
|
3481
3545
|
row,
|
|
3482
3546
|
steps: await store.getSteps(row.id)
|
|
3483
3547
|
};
|
|
3484
3548
|
}
|
|
3485
3549
|
async connections(ctx) {
|
|
3486
|
-
const
|
|
3487
|
-
|
|
3550
|
+
const subject = ctx && this.host.subjectOf?.(ctx);
|
|
3551
|
+
const page = await this.host.reactorClient.find({ type: "powerhouse/connection" }, subject ? { subject } : void 0);
|
|
3552
|
+
return (await this.readableDocuments(page.results, ctx)).filter((document) => document.state.global !== void 0).map((document) => {
|
|
3488
3553
|
const state = document.state.global;
|
|
3489
3554
|
return {
|
|
3490
3555
|
id: document.header.id,
|
|
@@ -3725,7 +3790,7 @@ var WorkflowRuntimeService = class {
|
|
|
3725
3790
|
const common = {
|
|
3726
3791
|
displayName: descriptor.displayName,
|
|
3727
3792
|
logoUrl: descriptor.logoUrl,
|
|
3728
|
-
auth: descriptor.auth
|
|
3793
|
+
auth: clientAuth(descriptor.auth)
|
|
3729
3794
|
};
|
|
3730
3795
|
if (parsed.kind === "trigger") {
|
|
3731
3796
|
const trigger = descriptor.triggers.find((entry) => entry.name === parsed.name);
|
|
@@ -3755,6 +3820,32 @@ var WorkflowRuntimeService = class {
|
|
|
3755
3820
|
canReadDocument(documentId, ctx) {
|
|
3756
3821
|
return this.host.assertCanRead(documentId, ctx).then(() => true).catch(() => false);
|
|
3757
3822
|
}
|
|
3823
|
+
async servedRuns(rows, ctx) {
|
|
3824
|
+
if (!ctx) return [];
|
|
3825
|
+
const decisions = /* @__PURE__ */ new Map();
|
|
3826
|
+
const store = await this.store();
|
|
3827
|
+
const served = await Promise.all(rows.map(async (row) => this.servesDocuments([...journaledTriggerDocumentIds(row.trigger_payload), ...await store?.getRunDocuments(row.id) ?? []], ctx, decisions)));
|
|
3828
|
+
return rows.filter((_, index) => served[index]);
|
|
3829
|
+
}
|
|
3830
|
+
async servesDocuments(documentIds, ctx, decisions = /* @__PURE__ */ new Map()) {
|
|
3831
|
+
return (await Promise.all([...new Set(documentIds)].map((documentId) => {
|
|
3832
|
+
let decision = decisions.get(documentId);
|
|
3833
|
+
if (!decision) {
|
|
3834
|
+
decision = this.servesRunDocument(documentId, ctx);
|
|
3835
|
+
decisions.set(documentId, decision);
|
|
3836
|
+
}
|
|
3837
|
+
return decision;
|
|
3838
|
+
}))).every(Boolean);
|
|
3839
|
+
}
|
|
3840
|
+
async servesRunDocument(documentId, ctx) {
|
|
3841
|
+
if (await this.canReadDocument(documentId, ctx)) return true;
|
|
3842
|
+
try {
|
|
3843
|
+
await this.host.reactorClient.get(documentId, { scopes: ["document"] });
|
|
3844
|
+
} catch (error) {
|
|
3845
|
+
return isAbsent(error);
|
|
3846
|
+
}
|
|
3847
|
+
return false;
|
|
3848
|
+
}
|
|
3758
3849
|
async assertCanReadDocument(documentId, ctx) {
|
|
3759
3850
|
if (!ctx) throw new Error("Connection access requires an authenticated request");
|
|
3760
3851
|
await this.host.assertCanRead(documentId, ctx);
|
|
@@ -3963,11 +4054,18 @@ var WorkflowRuntimeService = class {
|
|
|
3963
4054
|
let session;
|
|
3964
4055
|
try {
|
|
3965
4056
|
session = this.workers().session();
|
|
4057
|
+
const journal = store;
|
|
4058
|
+
const journaledRunId = runId;
|
|
4059
|
+
const handed = /* @__PURE__ */ new Set();
|
|
3966
4060
|
const result = await withRunScope({
|
|
3967
4061
|
workflowId,
|
|
3968
4062
|
runId,
|
|
3969
4063
|
connections,
|
|
3970
|
-
pieceWorker: session
|
|
4064
|
+
pieceWorker: session,
|
|
4065
|
+
recordDocuments: async (documentIds) => {
|
|
4066
|
+
for (const documentId of documentIds) handed.add(documentId);
|
|
4067
|
+
if (journal && journaledRunId) await journal.recordRunDocuments(journaledRunId, documentIds);
|
|
4068
|
+
}
|
|
3971
4069
|
}, () => runWorkflow({
|
|
3972
4070
|
definition,
|
|
3973
4071
|
executor: this.executor,
|
|
@@ -3989,10 +4087,17 @@ var WorkflowRuntimeService = class {
|
|
|
3989
4087
|
} catch (error) {
|
|
3990
4088
|
this.logger.warn(`Run ${runId}: closing the run journal out failed; the run's outcome stands`, error);
|
|
3991
4089
|
}
|
|
3992
|
-
|
|
4090
|
+
const finished = {
|
|
3993
4091
|
...result,
|
|
3994
4092
|
runId
|
|
3995
4093
|
};
|
|
4094
|
+
if (!ctx) return finished;
|
|
4095
|
+
const ids = [...triggerDocumentIds(triggerPayload), ...handed];
|
|
4096
|
+
return await this.servesDocuments(ids, ctx) ? finished : {
|
|
4097
|
+
status: finished.status,
|
|
4098
|
+
steps: [],
|
|
4099
|
+
runId
|
|
4100
|
+
};
|
|
3996
4101
|
} catch (error) {
|
|
3997
4102
|
if (store && runId) await store.failRun(runId, error instanceof Error ? error.message : String(error));
|
|
3998
4103
|
throw error;
|
|
@@ -4006,6 +4111,7 @@ var WorkflowRuntimeService = class {
|
|
|
4006
4111
|
const run = await store.getRun(runId);
|
|
4007
4112
|
if (!run) throw new Error(`Run "${runId}" not found`);
|
|
4008
4113
|
await this.assertCanReadDocument(run.workflow_id, ctx);
|
|
4114
|
+
if (!ctx || (await this.servedRuns([run], ctx)).length === 0) throw new Error(`Run "${runId}" not found`);
|
|
4009
4115
|
if (run.status !== "FAILED") throw new Error(`Only FAILED runs can be rerun; run is ${run.status}`);
|
|
4010
4116
|
const triggerPayload = run.trigger_payload === null ? void 0 : JSON.parse(run.trigger_payload);
|
|
4011
4117
|
if (containsRedactedMarker(triggerPayload)) throw new Error(`Trigger payload of run "${runId}" was redacted and cannot be replayed; fire the workflow again instead of rerunning it`);
|
|
@@ -4024,7 +4130,7 @@ var WorkflowRuntimeService = class {
|
|
|
4024
4130
|
return this.fire(run.workflow_id, triggerPayload, "rerun", {
|
|
4025
4131
|
completedSteps,
|
|
4026
4132
|
rerunOf: runId
|
|
4027
|
-
});
|
|
4133
|
+
}, ctx);
|
|
4028
4134
|
}
|
|
4029
4135
|
};
|
|
4030
4136
|
/** The runtime a host composes: one instance, its lifetime the host's. */
|
|
@@ -4036,6 +4142,7 @@ function createWorkflowRuntime(deps) {
|
|
|
4036
4142
|
const WORKFLOW_TRIGGERS_READ_MODEL = "workflow-triggers";
|
|
4037
4143
|
const WORKFLOW_TRIGGERS_READ_MODEL_STAGE = "post_ready";
|
|
4038
4144
|
var WorkflowTriggersReadModel = class extends BaseReadModel {
|
|
4145
|
+
runtime;
|
|
4039
4146
|
freshRegistration = false;
|
|
4040
4147
|
constructor(db, operationIndex, writeCache, consistencyTracker, runtime) {
|
|
4041
4148
|
super(db, operationIndex, writeCache, consistencyTracker, {
|