@powerhousedao/reactor-workflow 6.2.3-dev.84 → 6.2.3-dev.86
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 +133 -37
- package/dist/index.d.ts +218 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1634 -123
- package/dist/index.js.map +1 -1
- package/dist/{piece-registry-ByALLpvA.d.ts → piece-registry-C1Pc0hD6.d.ts} +83 -3
- package/dist/piece-registry-C1Pc0hD6.d.ts.map +1 -0
- package/dist/{telemetry-CSemNycC.js → telemetry-GZA1FLlY.js} +674 -28
- package/dist/telemetry-GZA1FLlY.js.map +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/worker-entry.js +161 -16
- package/dist/worker-entry.js.map +1 -1
- package/package.json +7 -7
- package/dist/piece-registry-ByALLpvA.d.ts.map +0 -1
- package/dist/telemetry-CSemNycC.js.map +0 -1
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as PieceTarget, B as loadPieceFromDir, D as LocalPiece, N as RecordedSchedule, O as PackagePiece, P as extractDedupeKey, R as PieceDescriptor, S as BlockExecution, T as WorkflowRunResult, _ as PieceWorker, a as runWorkflow, b as WorkflowTelemetry, c as CompositeBlockExecutor, d as InMemorySecretProvider, h as IPieceWorker, j as sourcedResolver, k as PieceResolver, m as PieceWorkerPool, o as ActivepiecesBlockExecutor, s as AttachmentPort, t as PieceRegistry, u as StaticConnectionResolver, z as buildDescriptor } from "./piece-registry-
|
|
1
|
+
import { A as PieceTarget, B as loadPieceFromDir, D as LocalPiece, N as RecordedSchedule, O as PackagePiece, P as extractDedupeKey, R as PieceDescriptor, S as BlockExecution, T as WorkflowRunResult, _ as PieceWorker, a as runWorkflow, b as WorkflowTelemetry, c as CompositeBlockExecutor, d as InMemorySecretProvider, h as IPieceWorker, j as sourcedResolver, k as PieceResolver, m as PieceWorkerPool, o as ActivepiecesBlockExecutor, s as AttachmentPort, t as PieceRegistry, u as StaticConnectionResolver, z as buildDescriptor } from "./piece-registry-C1Pc0hD6.js";
|
|
2
2
|
//#region src/pieces/activepieces/fetch.d.ts
|
|
3
3
|
interface FetchPieceBundleOptions {
|
|
4
4
|
name: string;
|
package/dist/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { J as
|
|
1
|
+
import { J as PieceWorkerPool, M as StaticConnectionResolver, Y as PieceWorker, a as PieceRegistry, d as runWorkflow, ft as sourcedResolver, n as WorkflowTelemetry, pt as buildDescriptor, st as extractDedupeKey, v as ActivepiecesBlockExecutor, vt as ensurePieceBundle, y as CompositeBlockExecutor, yt as fetchPieceBundle, z as InMemorySecretProvider } from "./telemetry-GZA1FLlY.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { readFileSync, realpathSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
package/dist/worker-entry.js
CHANGED
|
@@ -2,9 +2,9 @@ import { createRequire, flushCompileCache } from "node:module";
|
|
|
2
2
|
import crypto from "crypto";
|
|
3
3
|
import path, { resolve } from "node:path";
|
|
4
4
|
import { mkdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
5
|
+
import { randomBytes, randomUUID } from "node:crypto";
|
|
5
6
|
import { format } from "node:util";
|
|
6
7
|
import { Readable, Transform } from "node:stream";
|
|
7
|
-
import { randomUUID } from "node:crypto";
|
|
8
8
|
import { createReadStream, createWriteStream, readFileSync, realpathSync } from "node:fs";
|
|
9
9
|
import { pipeline } from "node:stream/promises";
|
|
10
10
|
import { Cron } from "croner";
|
|
@@ -2650,10 +2650,112 @@ var InMemoryKeyValueStore = class {
|
|
|
2650
2650
|
return scope === "PROJECT" ? `PROJECT:${key}` : key;
|
|
2651
2651
|
}
|
|
2652
2652
|
};
|
|
2653
|
+
var RunCannotPauseError = class extends Error {
|
|
2654
|
+
constructor(member) {
|
|
2655
|
+
super(`ctx.run.${member} suspends the run, which only a workflow run can do, not a step test`);
|
|
2656
|
+
this.name = "RunCannotPauseError";
|
|
2657
|
+
}
|
|
2658
|
+
};
|
|
2659
|
+
function waitpointCall(params) {
|
|
2660
|
+
const value = params ?? {};
|
|
2661
|
+
if (value.type !== "DELAY" && value.type !== "WEBHOOK") throw new Error(`createWaitpoint: type must be DELAY or WEBHOOK, got ${String(value.type)}`);
|
|
2662
|
+
const resumeDateTime = typeof value.resumeDateTime === "string" ? value.resumeDateTime : void 0;
|
|
2663
|
+
if (value.type === "DELAY") {
|
|
2664
|
+
if (!resumeDateTime || Number.isNaN(Date.parse(resumeDateTime))) throw new Error("createWaitpoint: a DELAY needs a valid resumeDateTime");
|
|
2665
|
+
}
|
|
2666
|
+
const response = value.responseToSend;
|
|
2667
|
+
return {
|
|
2668
|
+
type: value.type,
|
|
2669
|
+
...resumeDateTime ? { resumeDateTime } : {},
|
|
2670
|
+
...response ? { responseToSend: jsonSafe(response) } : {}
|
|
2671
|
+
};
|
|
2672
|
+
}
|
|
2673
|
+
function buildResumeUrl(resumeUrl, params) {
|
|
2674
|
+
const url = new URL(`${resumeUrl}${params.sync ? "/sync" : ""}`);
|
|
2675
|
+
url.search = new URLSearchParams(params.queryParams ?? {}).toString();
|
|
2676
|
+
return url.toString();
|
|
2677
|
+
}
|
|
2678
|
+
function runResponse(params) {
|
|
2679
|
+
const response = params?.response;
|
|
2680
|
+
return jsonSafe(response ?? {}) ?? {};
|
|
2681
|
+
}
|
|
2682
|
+
function runHooks(options) {
|
|
2683
|
+
const port = options.canPause ? options.waitpoints : void 0;
|
|
2684
|
+
let hook = { type: "none" };
|
|
2685
|
+
let legacyToken;
|
|
2686
|
+
const assertCanPause = (member) => {
|
|
2687
|
+
if (!port) throw new RunCannotPauseError(member);
|
|
2688
|
+
return port;
|
|
2689
|
+
};
|
|
2690
|
+
return {
|
|
2691
|
+
canPause: port !== void 0,
|
|
2692
|
+
paused: () => hook.type === "paused" ? hook.paused : void 0,
|
|
2693
|
+
response: () => hook.type === "respond" || hook.type === "stopped" ? hook.response : void 0,
|
|
2694
|
+
stopped: () => hook.type === "stopped",
|
|
2695
|
+
respond: (params) => {
|
|
2696
|
+
hook = {
|
|
2697
|
+
type: "respond",
|
|
2698
|
+
response: runResponse(params)
|
|
2699
|
+
};
|
|
2700
|
+
},
|
|
2701
|
+
stop: (params) => {
|
|
2702
|
+
hook = {
|
|
2703
|
+
type: "stopped",
|
|
2704
|
+
response: runResponse(params)
|
|
2705
|
+
};
|
|
2706
|
+
},
|
|
2707
|
+
createWaitpoint: async (params) => {
|
|
2708
|
+
const created = await assertCanPause("createWaitpoint").create(waitpointCall(params));
|
|
2709
|
+
return {
|
|
2710
|
+
id: created.id,
|
|
2711
|
+
resumeUrl: created.resumeUrl,
|
|
2712
|
+
buildResumeUrl: (args) => buildResumeUrl(created.resumeUrl, args)
|
|
2713
|
+
};
|
|
2714
|
+
},
|
|
2715
|
+
waitForWaitpoint: (waitpointId) => {
|
|
2716
|
+
assertCanPause("waitForWaitpoint");
|
|
2717
|
+
if (typeof waitpointId !== "string" || waitpointId === "") throw new Error("waitForWaitpoint: a waitpoint id is required");
|
|
2718
|
+
hook = {
|
|
2719
|
+
type: "paused",
|
|
2720
|
+
paused: { waitpointId }
|
|
2721
|
+
};
|
|
2722
|
+
},
|
|
2723
|
+
pause: (params) => {
|
|
2724
|
+
assertCanPause("pause");
|
|
2725
|
+
const metadata = params?.pauseMetadata ?? {};
|
|
2726
|
+
const pause = waitpointCall({
|
|
2727
|
+
type: metadata.type,
|
|
2728
|
+
resumeDateTime: metadata.resumeDateTime,
|
|
2729
|
+
responseToSend: metadata.response
|
|
2730
|
+
});
|
|
2731
|
+
hook = {
|
|
2732
|
+
type: "paused",
|
|
2733
|
+
paused: legacyToken ? {
|
|
2734
|
+
pause,
|
|
2735
|
+
token: legacyToken
|
|
2736
|
+
} : { pause }
|
|
2737
|
+
};
|
|
2738
|
+
},
|
|
2739
|
+
generateResumeUrl: (args) => {
|
|
2740
|
+
assertCanPause("generateResumeUrl");
|
|
2741
|
+
if (!options.resumeBaseUrl) throw new Error("generateResumeUrl: this host serves no resume URLs: resume URLs need an HTTP host");
|
|
2742
|
+
legacyToken ??= randomBytes(32).toString("base64url");
|
|
2743
|
+
if (hook.type === "paused" && "pause" in hook.paused) hook = {
|
|
2744
|
+
...hook,
|
|
2745
|
+
paused: {
|
|
2746
|
+
...hook.paused,
|
|
2747
|
+
token: legacyToken
|
|
2748
|
+
}
|
|
2749
|
+
};
|
|
2750
|
+
return buildResumeUrl(`${options.resumeBaseUrl.replace(/\/+$/, "")}/${legacyToken}`, args ?? {});
|
|
2751
|
+
}
|
|
2752
|
+
};
|
|
2753
|
+
}
|
|
2653
2754
|
function buildActionContext(options) {
|
|
2654
2755
|
const { identity = {} } = options;
|
|
2655
2756
|
const store = options.store ?? new InMemoryKeyValueStore();
|
|
2656
2757
|
const touched = /* @__PURE__ */ new Set();
|
|
2758
|
+
const hooks = runHooks(options);
|
|
2657
2759
|
return {
|
|
2658
2760
|
context: withTouchTracking({
|
|
2659
2761
|
executionType: options.executionType ?? "BEGIN",
|
|
@@ -2674,11 +2776,12 @@ function buildActionContext(options) {
|
|
|
2674
2776
|
agent: throwingStub("agent"),
|
|
2675
2777
|
run: {
|
|
2676
2778
|
id: identity.runId ?? "run",
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2779
|
+
canPause: hooks.canPause,
|
|
2780
|
+
stop: hooks.stop,
|
|
2781
|
+
pause: hooks.pause,
|
|
2782
|
+
respond: hooks.respond,
|
|
2783
|
+
createWaitpoint: hooks.createWaitpoint,
|
|
2784
|
+
waitForWaitpoint: hooks.waitForWaitpoint
|
|
2682
2785
|
},
|
|
2683
2786
|
project: {
|
|
2684
2787
|
id: identity.projectId ?? "project",
|
|
@@ -2692,9 +2795,12 @@ function buildActionContext(options) {
|
|
|
2692
2795
|
}
|
|
2693
2796
|
},
|
|
2694
2797
|
step: { name: identity.stepName ?? "step" },
|
|
2695
|
-
generateResumeUrl:
|
|
2798
|
+
generateResumeUrl: hooks.generateResumeUrl
|
|
2696
2799
|
}, touched, options.onTouch),
|
|
2697
|
-
touched
|
|
2800
|
+
touched,
|
|
2801
|
+
paused: hooks.paused,
|
|
2802
|
+
response: hooks.response,
|
|
2803
|
+
stopped: hooks.stopped
|
|
2698
2804
|
};
|
|
2699
2805
|
}
|
|
2700
2806
|
//#endregion
|
|
@@ -2706,6 +2812,8 @@ const OUTPUT_UPDATE = "output.update";
|
|
|
2706
2812
|
const STORE_GET = "store.get";
|
|
2707
2813
|
const STORE_PUT = "store.put";
|
|
2708
2814
|
const STORE_DELETE = "store.delete";
|
|
2815
|
+
const FILES_UPLOAD = "files.upload";
|
|
2816
|
+
const WAITPOINT_CREATE = "waitpoint.create";
|
|
2709
2817
|
//#endregion
|
|
2710
2818
|
//#region src/pieces/activepieces/indeterminate.ts
|
|
2711
2819
|
/** The property name, so both sides spell it once. */
|
|
@@ -2727,9 +2835,14 @@ function markIndeterminate(error) {
|
|
|
2727
2835
|
* the host may have written and simply not got the answer back in time, so
|
|
2728
2836
|
* reporting it as a failure is a claim nobody can stand behind. Reactor writes
|
|
2729
2837
|
* go over the reactor RPC, not a host call; their unconfirmed outcome is
|
|
2730
|
-
* recognised by error name instead (`../indeterminate.ts`).
|
|
2838
|
+
* recognised by error name instead (`../indeterminate.ts`). WAITPOINT_CREATE
|
|
2839
|
+
* is not here: a retry returns the waitpoint the lost call made.
|
|
2731
2840
|
*/
|
|
2732
|
-
const MUTATING_HOST_CALLS = [
|
|
2841
|
+
const MUTATING_HOST_CALLS = [
|
|
2842
|
+
STORE_PUT,
|
|
2843
|
+
STORE_DELETE,
|
|
2844
|
+
FILES_UPLOAD
|
|
2845
|
+
];
|
|
2733
2846
|
let fromWire$1;
|
|
2734
2847
|
let stopAt;
|
|
2735
2848
|
const MIN_DEADLINE_MARGIN_MS = 250;
|
|
@@ -5057,6 +5170,13 @@ var DataUriFilesService = class {
|
|
|
5057
5170
|
if (data.byteLength > maxFileBytes()) throw new FileTooLargeError(data.byteLength);
|
|
5058
5171
|
return `data:application/octet-stream;base64,${data.toString("base64")}`;
|
|
5059
5172
|
}
|
|
5173
|
+
async upload(file) {
|
|
5174
|
+
const url = await this.write(file);
|
|
5175
|
+
return {
|
|
5176
|
+
id: url,
|
|
5177
|
+
url
|
|
5178
|
+
};
|
|
5179
|
+
}
|
|
5060
5180
|
};
|
|
5061
5181
|
const EXTENSION_TYPES = {
|
|
5062
5182
|
pdf: "application/pdf",
|
|
@@ -5076,14 +5196,34 @@ function contentTypeFor(fileName) {
|
|
|
5076
5196
|
}
|
|
5077
5197
|
var StagedFilesService = class {
|
|
5078
5198
|
stagingDir;
|
|
5199
|
+
uploader;
|
|
5079
5200
|
files = [];
|
|
5080
|
-
constructor(stagingDir) {
|
|
5201
|
+
constructor(stagingDir, uploader) {
|
|
5081
5202
|
this.stagingDir = stagingDir;
|
|
5203
|
+
this.uploader = uploader;
|
|
5082
5204
|
}
|
|
5083
5205
|
staged() {
|
|
5084
5206
|
return [...this.files];
|
|
5085
5207
|
}
|
|
5086
5208
|
async write(file) {
|
|
5209
|
+
const staged = await this.stage(file);
|
|
5210
|
+
this.files.push(staged);
|
|
5211
|
+
return staged.token;
|
|
5212
|
+
}
|
|
5213
|
+
async upload(file) {
|
|
5214
|
+
if (!this.uploader) throw new Error("ctx.files.upload needs an attachment store, and none is configured for this reactor");
|
|
5215
|
+
const staged = await this.stage(file);
|
|
5216
|
+
try {
|
|
5217
|
+
const ref = await this.uploader(staged);
|
|
5218
|
+
return {
|
|
5219
|
+
id: ref,
|
|
5220
|
+
url: ref
|
|
5221
|
+
};
|
|
5222
|
+
} finally {
|
|
5223
|
+
await rm(staged.path, { force: true });
|
|
5224
|
+
}
|
|
5225
|
+
}
|
|
5226
|
+
async stage(file) {
|
|
5087
5227
|
const token = randomUUID();
|
|
5088
5228
|
const fileName = file.fileName && file.fileName !== "" ? file.fileName : token;
|
|
5089
5229
|
const target = path.join(this.stagingDir, token);
|
|
@@ -5104,14 +5244,13 @@ var StagedFilesService = class {
|
|
|
5104
5244
|
await writeFile(target, data);
|
|
5105
5245
|
size = data.byteLength;
|
|
5106
5246
|
}
|
|
5107
|
-
|
|
5247
|
+
return {
|
|
5108
5248
|
token: `${APFILE_SCHEME}${token}`,
|
|
5109
5249
|
path: target,
|
|
5110
5250
|
fileName,
|
|
5111
5251
|
size,
|
|
5112
5252
|
contentType: contentTypeFor(fileName)
|
|
5113
|
-
}
|
|
5114
|
-
return `${APFILE_SCHEME}${token}`;
|
|
5253
|
+
};
|
|
5115
5254
|
}
|
|
5116
5255
|
};
|
|
5117
5256
|
//#endregion
|
|
@@ -6526,7 +6665,7 @@ async function handleRun(message) {
|
|
|
6526
6665
|
const action = getActions(piece)[request.actionName];
|
|
6527
6666
|
if (!action) throw new Error(`No action "${request.actionName}" in ${pieceRefKey(request)}`);
|
|
6528
6667
|
assertRunnable(piece, piece.displayName, request.auth);
|
|
6529
|
-
const files = request.stagingDir ? new StagedFilesService(request.stagingDir) : new DataUriFilesService();
|
|
6668
|
+
const files = request.stagingDir ? new StagedFilesService(request.stagingDir, request.uploadFiles ? (file) => callHost(FILES_UPLOAD, file) : void 0) : new DataUriFilesService();
|
|
6530
6669
|
const durableStore = request.durableStore ? new RemoteKeyValueStore() : void 0;
|
|
6531
6670
|
const liveOutput = request.liveOutput ? new RemoteOutput() : void 0;
|
|
6532
6671
|
const session = await timed("reactor.open", () => openWorkerReactor(request.reactor, action.requireReactor));
|
|
@@ -6545,7 +6684,7 @@ async function runAction(message, action, services) {
|
|
|
6545
6684
|
const { request } = message;
|
|
6546
6685
|
const { files, durableStore, liveOutput, reactor } = services;
|
|
6547
6686
|
const restoreConsole = request.captureLogs ? captureConsole() : void 0;
|
|
6548
|
-
const { context, touched } = buildActionContext({
|
|
6687
|
+
const { context, touched, paused, response, stopped } = buildActionContext({
|
|
6549
6688
|
propsValue: await preparePropsValue(`action "${request.actionName}"`, action.props, request.propsValue, stagedInputOptions(request.stagedInputs)),
|
|
6550
6689
|
auth: request.auth,
|
|
6551
6690
|
store: durableStore ?? (request.storeScope ? storeForScope(request.storeScope) : void 0),
|
|
@@ -6555,6 +6694,9 @@ async function runAction(message, action, services) {
|
|
|
6555
6694
|
...reactor,
|
|
6556
6695
|
resumePayload: request.resumePayload,
|
|
6557
6696
|
executionType: request.executionType,
|
|
6697
|
+
canPause: request.canPause,
|
|
6698
|
+
...request.canPause ? { waitpoints: { create: (call) => callHost(WAITPOINT_CREATE, call) } } : {},
|
|
6699
|
+
...request.resumeBaseUrl ? { resumeBaseUrl: request.resumeBaseUrl } : {},
|
|
6558
6700
|
identity: request.identity
|
|
6559
6701
|
});
|
|
6560
6702
|
let output;
|
|
@@ -6569,6 +6711,9 @@ async function runAction(message, action, services) {
|
|
|
6569
6711
|
id: message.id,
|
|
6570
6712
|
type: "result",
|
|
6571
6713
|
output: jsonSafe(output),
|
|
6714
|
+
...paused() ? { paused: paused() } : {},
|
|
6715
|
+
...response() ? { response: response() } : {},
|
|
6716
|
+
...stopped() ? { stopped: true } : {},
|
|
6572
6717
|
...files instanceof StagedFilesService && files.staged().length > 0 ? { files: files.staged() } : {},
|
|
6573
6718
|
touched: [...touched],
|
|
6574
6719
|
tlsPoisoned: consumeTlsFlag()
|