@powerhousedao/reactor-workflow 6.2.3-dev.83 → 6.2.3-dev.85
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 +206 -38
- package/dist/index.d.ts +263 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1786 -171
- package/dist/index.js.map +1 -1
- package/dist/{piece-registry-ByALLpvA.d.ts → piece-registry-DNIk31Vv.d.ts} +82 -3
- package/dist/piece-registry-DNIk31Vv.d.ts.map +1 -0
- package/dist/{telemetry-5AAX-Pst.js → telemetry-B5OOpfCS.js} +708 -29
- package/dist/telemetry-B5OOpfCS.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-5AAX-Pst.js.map +0 -1
|
@@ -7,13 +7,13 @@ import { promisify } from "node:util";
|
|
|
7
7
|
import { gunzip } from "node:zlib";
|
|
8
8
|
import { childLogger } from "document-model";
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
|
-
import { BRANCH_PORTS, CORE_PIECE_NAME, CORE_PIECE_NAME as CORE_PIECE_NAME$1, NEXT_PORT, PIECE_ACTION_PORTS, SCHEDULE_MODES, SCHEDULE_UNIT_MS, TRIGGER_PORTS, checkTriggerStrategy, referenceDocuments, undeclaredPortEdges } from "@powerhousedao/pieces-framework/workflow";
|
|
10
|
+
import { BRANCH_PORTS, CORE_PIECE_NAME, CORE_PIECE_NAME as CORE_PIECE_NAME$1, NEXT_PORT, PIECE_ACTION_PORTS, SCHEDULE_MODES, SCHEDULE_UNIT_MS, STOP_PORTS, TRIGGER_PORTS, checkTriggerStrategy, referenceDocuments, undeclaredPortEdges } from "@powerhousedao/pieces-framework/workflow";
|
|
11
11
|
import { Cron } from "croner";
|
|
12
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
12
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
13
13
|
import { ssrfIpClassifier } from "@powerhousedao/pieces-framework/host";
|
|
14
14
|
import dns from "node:dns";
|
|
15
15
|
import net, { isIP } from "node:net";
|
|
16
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
16
|
+
import { AsyncLocalStorage, AsyncResource } from "node:async_hooks";
|
|
17
17
|
import os, { tmpdir, userInfo } from "node:os";
|
|
18
18
|
import { blockKey, isExactVersion } from "@powerhousedao/pieces-framework/block-type";
|
|
19
19
|
import { SpanStatusCode, context, metrics, trace } from "@opentelemetry/api";
|
|
@@ -785,6 +785,8 @@ const OUTPUT_UPDATE = "output.update";
|
|
|
785
785
|
const STORE_GET = "store.get";
|
|
786
786
|
const STORE_PUT = "store.put";
|
|
787
787
|
const STORE_DELETE = "store.delete";
|
|
788
|
+
const FILES_UPLOAD = "files.upload";
|
|
789
|
+
const WAITPOINT_CREATE = "waitpoint.create";
|
|
788
790
|
//#endregion
|
|
789
791
|
//#region src/pieces/activepieces/worker/host-call.ts
|
|
790
792
|
const DEFAULT_HOST_CALL_TIMEOUT_MS = 1e4;
|
|
@@ -1072,11 +1074,11 @@ function createIpcTransport(worker, requestId) {
|
|
|
1072
1074
|
});
|
|
1073
1075
|
},
|
|
1074
1076
|
onMessage(listener) {
|
|
1075
|
-
const handler = (value) => {
|
|
1077
|
+
const handler = AsyncResource.bind((value) => {
|
|
1076
1078
|
if (closed || !isReactorRpcEnvelope(value, requestId)) return;
|
|
1077
1079
|
if (!isRpcMessage(value.message)) return;
|
|
1078
1080
|
listener(value.message);
|
|
1079
|
-
};
|
|
1081
|
+
});
|
|
1080
1082
|
worker.on("message", handler);
|
|
1081
1083
|
const detach = () => {
|
|
1082
1084
|
worker.off("message", handler);
|
|
@@ -1411,6 +1413,9 @@ var PieceWorker = class {
|
|
|
1411
1413
|
this.noteReply(response);
|
|
1412
1414
|
if (response.type === "result") resolve({
|
|
1413
1415
|
output: response.output,
|
|
1416
|
+
...response.paused ? { paused: response.paused } : {},
|
|
1417
|
+
...response.response ? { response: response.response } : {},
|
|
1418
|
+
...response.stopped ? { stopped: true } : {},
|
|
1414
1419
|
touched: response.touched,
|
|
1415
1420
|
tlsPoisoned: response.tlsPoisoned,
|
|
1416
1421
|
files: response.files,
|
|
@@ -1430,14 +1435,14 @@ var PieceWorker = class {
|
|
|
1430
1435
|
cleanup();
|
|
1431
1436
|
reject(new PieceWorkerExitError(code, signal));
|
|
1432
1437
|
};
|
|
1433
|
-
const onHostCall = (value) => {
|
|
1438
|
+
const onHostCall = AsyncResource.bind((value) => {
|
|
1434
1439
|
const message = value;
|
|
1435
1440
|
if (message.type === "host-call") {
|
|
1436
1441
|
this.serveHostCall(worker, message, taps.hostCalls);
|
|
1437
1442
|
return;
|
|
1438
1443
|
}
|
|
1439
1444
|
if (message.type === "host-notify") serveNotify(message, taps.notifications);
|
|
1440
|
-
};
|
|
1445
|
+
});
|
|
1441
1446
|
const cleanup = () => {
|
|
1442
1447
|
reactor?.stop();
|
|
1443
1448
|
reactor = void 0;
|
|
@@ -2223,7 +2228,7 @@ function asList(value, side) {
|
|
|
2223
2228
|
if (Array.isArray(value)) return value;
|
|
2224
2229
|
throw new BranchConfigError(`${side} must be a list, got ${describe(value)}`);
|
|
2225
2230
|
}
|
|
2226
|
-
const blank = (value) => value === void 0 || value === null || value === "";
|
|
2231
|
+
const blank$1 = (value) => value === void 0 || value === null || value === "";
|
|
2227
2232
|
function textOp(label, test) {
|
|
2228
2233
|
return {
|
|
2229
2234
|
label,
|
|
@@ -2301,8 +2306,8 @@ const BRANCH_OPERATORS = {
|
|
|
2301
2306
|
},
|
|
2302
2307
|
LIST_IS_EMPTY: unary("List is empty", "list", (v) => asList(v, "left").length === 0),
|
|
2303
2308
|
LIST_IS_NOT_EMPTY: unary("List is not empty", "list", (v) => asList(v, "left").length > 0),
|
|
2304
|
-
EXISTS: unary("Exists", "any", (v) => !blank(v)),
|
|
2305
|
-
DOES_NOT_EXIST: unary("Does not exist", "any", blank)
|
|
2309
|
+
EXISTS: unary("Exists", "any", (v) => !blank$1(v)),
|
|
2310
|
+
DOES_NOT_EXIST: unary("Does not exist", "any", blank$1)
|
|
2306
2311
|
};
|
|
2307
2312
|
const EXISTENCE_OPERATORS = /* @__PURE__ */ new Set(["EXISTS", "DOES_NOT_EXIST"]);
|
|
2308
2313
|
const OPERATORS = BRANCH_OPERATORS;
|
|
@@ -2339,6 +2344,24 @@ function resolveStepInput(step, scope) {
|
|
|
2339
2344
|
assertNoUnavailableValue(input);
|
|
2340
2345
|
return input;
|
|
2341
2346
|
}
|
|
2347
|
+
function resolveResumedCoreInput(step, scope) {
|
|
2348
|
+
try {
|
|
2349
|
+
return resolveStepInput(step, scope);
|
|
2350
|
+
} catch (error) {
|
|
2351
|
+
if (!(error instanceof UnavailableValueError)) throw error;
|
|
2352
|
+
}
|
|
2353
|
+
const { config } = step;
|
|
2354
|
+
if (config === null || typeof config !== "object" || Array.isArray(config)) return {};
|
|
2355
|
+
const input = {};
|
|
2356
|
+
for (const [key, value] of Object.entries(config)) try {
|
|
2357
|
+
const resolved = resolveExpressions(value, scope);
|
|
2358
|
+
assertNoUnavailableValue(resolved);
|
|
2359
|
+
input[key] = resolved;
|
|
2360
|
+
} catch (error) {
|
|
2361
|
+
if (!(error instanceof UnavailableValueError)) throw error;
|
|
2362
|
+
}
|
|
2363
|
+
return input;
|
|
2364
|
+
}
|
|
2342
2365
|
function resolveStepInputRaw(step, scope) {
|
|
2343
2366
|
const { config } = step;
|
|
2344
2367
|
if (step.pieceName !== CORE_PIECE_NAME || step.actionName !== "branch" || config === null || typeof config !== "object" || Array.isArray(config) || !Object.hasOwn(config, "left")) return resolveExpressions(config, scope);
|
|
@@ -2928,23 +2951,463 @@ const manualTrigger = createTrigger({
|
|
|
2928
2951
|
description: "Fires only when something asks it to, with the fire mutation. The trigger to use for a workflow driven by a test or a script.",
|
|
2929
2952
|
type: TriggerStrategy.MANUAL,
|
|
2930
2953
|
requireAuth: false,
|
|
2931
|
-
props: {
|
|
2954
|
+
props: { inputs: Property.Array({
|
|
2955
|
+
displayName: "Inputs",
|
|
2956
|
+
description: "Fields a run asks for. The editor's Run shows them as a form; a fire missing a required field, or with one of the wrong type, is refused.",
|
|
2957
|
+
required: false,
|
|
2958
|
+
properties: {
|
|
2959
|
+
displayName: Property.ShortText({
|
|
2960
|
+
displayName: "Field Name",
|
|
2961
|
+
placeholder: "e.g. Email address",
|
|
2962
|
+
required: true
|
|
2963
|
+
}),
|
|
2964
|
+
name: Property.ShortText({
|
|
2965
|
+
displayName: "Payload Key",
|
|
2966
|
+
description: "Read as {{trigger.payload.<key>}}.",
|
|
2967
|
+
placeholder: "e.g. email",
|
|
2968
|
+
required: true
|
|
2969
|
+
}),
|
|
2970
|
+
type: Property.StaticDropdown({
|
|
2971
|
+
displayName: "Field Type",
|
|
2972
|
+
required: true,
|
|
2973
|
+
defaultValue: "text",
|
|
2974
|
+
options: options([
|
|
2975
|
+
["text", "Text"],
|
|
2976
|
+
["text_area", "Long text"],
|
|
2977
|
+
["number", "Number"],
|
|
2978
|
+
["toggle", "Checkbox"],
|
|
2979
|
+
["date", "Date"],
|
|
2980
|
+
["dropdown", "Dropdown"],
|
|
2981
|
+
["json", "JSON"]
|
|
2982
|
+
])
|
|
2983
|
+
}),
|
|
2984
|
+
options: withHints(Property.LongText({
|
|
2985
|
+
displayName: "Options",
|
|
2986
|
+
description: "One per line: a value, or Label = value to show a label and send the value.",
|
|
2987
|
+
required: true
|
|
2988
|
+
}), shownWhen("type", ["dropdown"])),
|
|
2989
|
+
description: Property.ShortText({
|
|
2990
|
+
displayName: "Field Description",
|
|
2991
|
+
placeholder: "Shown under the field",
|
|
2992
|
+
required: false
|
|
2993
|
+
}),
|
|
2994
|
+
defaultValue: Property.ShortText({
|
|
2995
|
+
displayName: "Default Value",
|
|
2996
|
+
description: "As text: 42, true, 2026-01-31, or JSON.",
|
|
2997
|
+
required: false
|
|
2998
|
+
}),
|
|
2999
|
+
required: Property.Checkbox({
|
|
3000
|
+
displayName: "Required",
|
|
3001
|
+
defaultValue: false,
|
|
3002
|
+
required: false
|
|
3003
|
+
})
|
|
3004
|
+
}
|
|
3005
|
+
}) },
|
|
2932
3006
|
sampleData: null,
|
|
2933
3007
|
...hooks("manual")
|
|
2934
3008
|
});
|
|
2935
3009
|
//#endregion
|
|
3010
|
+
//#region src/pieces/core/context.ts
|
|
3011
|
+
var CoreCannotPauseError = class extends Error {
|
|
3012
|
+
constructor(block) {
|
|
3013
|
+
super(`${block} suspends the run, which only a workflow run can do, not a step test`);
|
|
3014
|
+
this.name = "RunCannotPauseError";
|
|
3015
|
+
}
|
|
3016
|
+
};
|
|
3017
|
+
//#endregion
|
|
3018
|
+
//#region src/pieces/core/waits.ts
|
|
3019
|
+
const UNIT_MS = {
|
|
3020
|
+
seconds: 1e3,
|
|
3021
|
+
minutes: 6e4,
|
|
3022
|
+
hours: 36e5,
|
|
3023
|
+
days: 864e5
|
|
3024
|
+
};
|
|
3025
|
+
const unitOptions = Object.keys(UNIT_MS).map((unit) => ({
|
|
3026
|
+
value: unit,
|
|
3027
|
+
label: unit[0].toUpperCase() + unit.slice(1)
|
|
3028
|
+
}));
|
|
3029
|
+
function durationMs(amount, unit, label) {
|
|
3030
|
+
if (amount === void 0 || amount === null || amount === "") return;
|
|
3031
|
+
const value = Number(amount);
|
|
3032
|
+
if (!Number.isFinite(value) || value < 0) throw new Error(`${label}: ${JSON.stringify(amount)} is not a duration`);
|
|
3033
|
+
if (typeof unit !== "string" || !Object.hasOwn(UNIT_MS, unit)) throw new Error(`${label}: unknown unit ${JSON.stringify(unit)}`);
|
|
3034
|
+
return value * UNIT_MS[unit];
|
|
3035
|
+
}
|
|
3036
|
+
function context$2(ctx) {
|
|
3037
|
+
return ctx;
|
|
3038
|
+
}
|
|
3039
|
+
function assertCanPause(ctx, block) {
|
|
3040
|
+
if (!ctx.run.canPause) throw new CoreCannotPauseError(block);
|
|
3041
|
+
}
|
|
3042
|
+
const delayAction = withPorts(createAction({
|
|
3043
|
+
name: "delay",
|
|
3044
|
+
displayName: "Delay",
|
|
3045
|
+
description: "Suspends the run for a while, or until a date, then carries on. The run holds no worker while it waits.",
|
|
3046
|
+
requireAuth: false,
|
|
3047
|
+
props: {
|
|
3048
|
+
mode: Property.StaticDropdown({
|
|
3049
|
+
displayName: "Mode",
|
|
3050
|
+
required: true,
|
|
3051
|
+
defaultValue: "for",
|
|
3052
|
+
options: { options: [{
|
|
3053
|
+
value: "for",
|
|
3054
|
+
label: "Delay for"
|
|
3055
|
+
}, {
|
|
3056
|
+
value: "until",
|
|
3057
|
+
label: "Delay until"
|
|
3058
|
+
}] }
|
|
3059
|
+
}),
|
|
3060
|
+
amount: withHints(Property.Number({
|
|
3061
|
+
displayName: "Amount",
|
|
3062
|
+
required: true
|
|
3063
|
+
}), shownWhen("mode", ["for"])),
|
|
3064
|
+
unit: withHints(Property.StaticDropdown({
|
|
3065
|
+
displayName: "Unit",
|
|
3066
|
+
required: true,
|
|
3067
|
+
defaultValue: "minutes",
|
|
3068
|
+
options: { options: unitOptions }
|
|
3069
|
+
}), shownWhen("mode", ["for"])),
|
|
3070
|
+
until: withHints(Property.DateTime({
|
|
3071
|
+
displayName: "Until",
|
|
3072
|
+
description: "ISO 8601 date and time; a past one does not wait.",
|
|
3073
|
+
required: true
|
|
3074
|
+
}), shownWhen("mode", ["until"]))
|
|
3075
|
+
},
|
|
3076
|
+
run: async (raw) => {
|
|
3077
|
+
const ctx = context$2(raw);
|
|
3078
|
+
if (ctx.executionType === "RESUME") return { resumedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3079
|
+
const { mode, amount, unit, until } = ctx.propsValue;
|
|
3080
|
+
let resumeAt;
|
|
3081
|
+
if (mode === "until") {
|
|
3082
|
+
resumeAt = typeof until === "string" ? Date.parse(until) : NaN;
|
|
3083
|
+
if (Number.isNaN(resumeAt)) throw new Error(`Delay: ${JSON.stringify(until)} is not a date and time`);
|
|
3084
|
+
} else {
|
|
3085
|
+
const ms = durationMs(amount, unit, "Delay");
|
|
3086
|
+
if (ms === void 0) throw new Error("Delay: an amount is required");
|
|
3087
|
+
resumeAt = Date.now() + ms;
|
|
3088
|
+
}
|
|
3089
|
+
if (resumeAt <= Date.now()) return { resumedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3090
|
+
assertCanPause(ctx, "Delay");
|
|
3091
|
+
const resumeDateTime = new Date(resumeAt).toISOString();
|
|
3092
|
+
const waitpoint = await ctx.run.createWaitpoint({
|
|
3093
|
+
type: "DELAY",
|
|
3094
|
+
resumeDateTime
|
|
3095
|
+
});
|
|
3096
|
+
ctx.run.waitForWaitpoint(waitpoint.id);
|
|
3097
|
+
return { resumeAt: resumeDateTime };
|
|
3098
|
+
}
|
|
3099
|
+
}), {
|
|
3100
|
+
ports: PIECE_ACTION_PORTS,
|
|
3101
|
+
portOf: () => NEXT_PORT
|
|
3102
|
+
});
|
|
3103
|
+
const REASON_RULES = [
|
|
3104
|
+
"none",
|
|
3105
|
+
"reject",
|
|
3106
|
+
"both"
|
|
3107
|
+
];
|
|
3108
|
+
function text(value, fallback) {
|
|
3109
|
+
return typeof value === "string" && value.trim() ? value : fallback;
|
|
3110
|
+
}
|
|
3111
|
+
function approvers(value) {
|
|
3112
|
+
const list = Array.isArray(value) ? value : typeof value === "string" ? value.split(/[\s,]+/) : [];
|
|
3113
|
+
return [...new Set(list.map((entry) => String(entry).trim()).filter(Boolean))];
|
|
3114
|
+
}
|
|
3115
|
+
function approvalDecision(payload) {
|
|
3116
|
+
const record = payload ?? {};
|
|
3117
|
+
const body = record.body && typeof record.body === "object" ? record.body : {};
|
|
3118
|
+
const query = record.queryParams ?? {};
|
|
3119
|
+
return {
|
|
3120
|
+
approved: typeof body.approved === "boolean" ? body.approved : query.action === "approve",
|
|
3121
|
+
reason: [body.reason, query.reason].find((value) => typeof value === "string" && value !== "") ?? null,
|
|
3122
|
+
decidedBy: typeof body.decidedBy === "string" ? body.decidedBy : null,
|
|
3123
|
+
decidedAt: typeof body.decidedAt === "string" ? body.decidedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
3124
|
+
};
|
|
3125
|
+
}
|
|
3126
|
+
const approvalAction = withPorts(createAction({
|
|
3127
|
+
name: "approval",
|
|
3128
|
+
displayName: "Request approval",
|
|
3129
|
+
description: "Suspends the run until someone approves or rejects it in the workflow editor. The decision is the step's output.",
|
|
3130
|
+
requireAuth: false,
|
|
3131
|
+
props: {
|
|
3132
|
+
title: Property.ShortText({
|
|
3133
|
+
displayName: "Title",
|
|
3134
|
+
required: true
|
|
3135
|
+
}),
|
|
3136
|
+
body: Property.LongText({
|
|
3137
|
+
displayName: "Details",
|
|
3138
|
+
description: "Markdown shown to the approver; expressions are filled in when the run pauses.",
|
|
3139
|
+
required: false
|
|
3140
|
+
}),
|
|
3141
|
+
approveLabel: Property.ShortText({
|
|
3142
|
+
displayName: "Approve label",
|
|
3143
|
+
required: false,
|
|
3144
|
+
defaultValue: "Approve"
|
|
3145
|
+
}),
|
|
3146
|
+
rejectLabel: Property.ShortText({
|
|
3147
|
+
displayName: "Reject label",
|
|
3148
|
+
required: false,
|
|
3149
|
+
defaultValue: "Reject"
|
|
3150
|
+
}),
|
|
3151
|
+
reasonRequiredOn: Property.StaticDropdown({
|
|
3152
|
+
displayName: "Reason required",
|
|
3153
|
+
required: false,
|
|
3154
|
+
defaultValue: "none",
|
|
3155
|
+
options: { options: [
|
|
3156
|
+
{
|
|
3157
|
+
value: "none",
|
|
3158
|
+
label: "Never"
|
|
3159
|
+
},
|
|
3160
|
+
{
|
|
3161
|
+
value: "reject",
|
|
3162
|
+
label: "On reject"
|
|
3163
|
+
},
|
|
3164
|
+
{
|
|
3165
|
+
value: "both",
|
|
3166
|
+
label: "Always"
|
|
3167
|
+
}
|
|
3168
|
+
] }
|
|
3169
|
+
}),
|
|
3170
|
+
approvers: Property.Array({
|
|
3171
|
+
displayName: "Approvers",
|
|
3172
|
+
description: "DIDs or addresses allowed to decide in the editor; empty lets anyone who can edit the workflow.",
|
|
3173
|
+
required: false
|
|
3174
|
+
}),
|
|
3175
|
+
expiresAfter: Property.Number({
|
|
3176
|
+
displayName: "Expires after",
|
|
3177
|
+
description: "Ends the run if nobody decides in time; the workflow's maxSuspensionDays still applies.",
|
|
3178
|
+
required: false
|
|
3179
|
+
}),
|
|
3180
|
+
expiresUnit: Property.StaticDropdown({
|
|
3181
|
+
displayName: "Expiry unit",
|
|
3182
|
+
required: false,
|
|
3183
|
+
defaultValue: "days",
|
|
3184
|
+
options: { options: unitOptions }
|
|
3185
|
+
})
|
|
3186
|
+
},
|
|
3187
|
+
run: async (raw) => {
|
|
3188
|
+
const ctx = context$2(raw);
|
|
3189
|
+
if (ctx.executionType === "RESUME") return approvalDecision(ctx.resumePayload);
|
|
3190
|
+
assertCanPause(ctx, "Request approval");
|
|
3191
|
+
const props = ctx.propsValue;
|
|
3192
|
+
const rule = REASON_RULES.includes(props.reasonRequiredOn) ? props.reasonRequiredOn : "none";
|
|
3193
|
+
const approval = {
|
|
3194
|
+
title: text(props.title, "Approval"),
|
|
3195
|
+
body: typeof props.body === "string" && props.body ? props.body : null,
|
|
3196
|
+
approveLabel: text(props.approveLabel, "Approve"),
|
|
3197
|
+
rejectLabel: text(props.rejectLabel, "Reject"),
|
|
3198
|
+
reasonRequiredOn: rule,
|
|
3199
|
+
approvers: approvers(props.approvers)
|
|
3200
|
+
};
|
|
3201
|
+
const expiresMs = durationMs(props.expiresAfter, props.expiresUnit ?? "days", "Request approval");
|
|
3202
|
+
const waitpoint = await ctx.run.createWaitpoint({
|
|
3203
|
+
type: "WEBHOOK",
|
|
3204
|
+
approval,
|
|
3205
|
+
...expiresMs ? { expiresAt: new Date(Date.now() + expiresMs).toISOString() } : {}
|
|
3206
|
+
});
|
|
3207
|
+
ctx.run.waitForWaitpoint(waitpoint.id);
|
|
3208
|
+
return {};
|
|
3209
|
+
}
|
|
3210
|
+
}), {
|
|
3211
|
+
ports: PIECE_ACTION_PORTS,
|
|
3212
|
+
portOf: () => NEXT_PORT
|
|
3213
|
+
});
|
|
3214
|
+
//#endregion
|
|
3215
|
+
//#region src/pieces/core/responses.ts
|
|
3216
|
+
const RESUME_URL_HEADER = "x-resume-webhook-url";
|
|
3217
|
+
const REDIRECT_STATUS = 302;
|
|
3218
|
+
function responseProps(bodyRequired) {
|
|
3219
|
+
return {
|
|
3220
|
+
responseType: Property.StaticDropdown({
|
|
3221
|
+
displayName: "Response type",
|
|
3222
|
+
required: false,
|
|
3223
|
+
defaultValue: "json",
|
|
3224
|
+
options: { options: [
|
|
3225
|
+
{
|
|
3226
|
+
value: "json",
|
|
3227
|
+
label: "JSON"
|
|
3228
|
+
},
|
|
3229
|
+
{
|
|
3230
|
+
value: "raw",
|
|
3231
|
+
label: "Raw"
|
|
3232
|
+
},
|
|
3233
|
+
{
|
|
3234
|
+
value: "redirect",
|
|
3235
|
+
label: "Redirect"
|
|
3236
|
+
}
|
|
3237
|
+
] }
|
|
3238
|
+
}),
|
|
3239
|
+
status: withHints(Property.Number({
|
|
3240
|
+
displayName: "Status",
|
|
3241
|
+
description: "HTTP status; 200 when blank.",
|
|
3242
|
+
required: false
|
|
3243
|
+
}), shownWhen("responseType", ["json", "raw"])),
|
|
3244
|
+
headers: withHints(Property.Object({
|
|
3245
|
+
displayName: "Headers",
|
|
3246
|
+
required: false
|
|
3247
|
+
}), shownWhen("responseType", ["json", "raw"])),
|
|
3248
|
+
body: withHints(Property.Json({
|
|
3249
|
+
displayName: "JSON body",
|
|
3250
|
+
required: bodyRequired
|
|
3251
|
+
}), shownWhen("responseType", ["json"])),
|
|
3252
|
+
text: withHints(Property.LongText({
|
|
3253
|
+
displayName: "Raw body",
|
|
3254
|
+
required: bodyRequired
|
|
3255
|
+
}), shownWhen("responseType", ["raw"])),
|
|
3256
|
+
redirectUrl: withHints(Property.ShortText({
|
|
3257
|
+
displayName: "Redirect URL",
|
|
3258
|
+
required: true
|
|
3259
|
+
}), shownWhen("responseType", ["redirect"]))
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
const blank = (value) => value === void 0 || value === null || value === "" || typeof value === "object" && Object.keys(value).length === 0;
|
|
3263
|
+
function jsonBody(value, block) {
|
|
3264
|
+
if (typeof value !== "string") return value;
|
|
3265
|
+
try {
|
|
3266
|
+
return JSON.parse(value);
|
|
3267
|
+
} catch {
|
|
3268
|
+
throw new Error(`${block}: the JSON body is not valid JSON`);
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
function headerMap(value) {
|
|
3272
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
3273
|
+
const headers = {};
|
|
3274
|
+
for (const [name, entry] of Object.entries(value)) if (typeof entry === "string" || typeof entry === "number") headers[name] = String(entry);
|
|
3275
|
+
return headers;
|
|
3276
|
+
}
|
|
3277
|
+
function withProtocol(url) {
|
|
3278
|
+
return /^https?:\/\//i.test(url) ? url : `https://${url}`;
|
|
3279
|
+
}
|
|
3280
|
+
function configuredResponse(props, block) {
|
|
3281
|
+
const type = blank(props.responseType) ? "json" : props.responseType;
|
|
3282
|
+
if (type === "redirect") {
|
|
3283
|
+
if (typeof props.redirectUrl !== "string" || !props.redirectUrl.trim()) throw new Error(`${block}: a redirect URL is required`);
|
|
3284
|
+
const location = withProtocol(props.redirectUrl.trim());
|
|
3285
|
+
return {
|
|
3286
|
+
status: REDIRECT_STATUS,
|
|
3287
|
+
headers: { location },
|
|
3288
|
+
body: location
|
|
3289
|
+
};
|
|
3290
|
+
}
|
|
3291
|
+
const raw = type === "raw";
|
|
3292
|
+
const given = raw ? props.text : props.body;
|
|
3293
|
+
if (blank(given) && blank(props.status) && blank(props.headers)) return;
|
|
3294
|
+
return {
|
|
3295
|
+
status: blank(props.status) ? 200 : Number(props.status),
|
|
3296
|
+
headers: headerMap(props.headers),
|
|
3297
|
+
...blank(given) ? {} : { body: raw ? String(given) : jsonBody(given, block) }
|
|
3298
|
+
};
|
|
3299
|
+
}
|
|
3300
|
+
function context$1(ctx) {
|
|
3301
|
+
return ctx;
|
|
3302
|
+
}
|
|
3303
|
+
const stopAction = withPorts(createAction({
|
|
3304
|
+
name: "stop",
|
|
3305
|
+
displayName: "Stop run",
|
|
3306
|
+
description: "Ends the run successfully without running further steps. In a run that holds a request (a sync webhook or a /sync resume) it answers with the response set here, or 200 with {} when none is.",
|
|
3307
|
+
requireAuth: false,
|
|
3308
|
+
props: responseProps(false),
|
|
3309
|
+
run: (raw) => {
|
|
3310
|
+
const ctx = context$1(raw);
|
|
3311
|
+
const response = configuredResponse(ctx.propsValue, "Stop run");
|
|
3312
|
+
ctx.run.stop(response ? { response } : void 0);
|
|
3313
|
+
return Promise.resolve(response ? { response } : {});
|
|
3314
|
+
}
|
|
3315
|
+
}), {
|
|
3316
|
+
ports: STOP_PORTS,
|
|
3317
|
+
portOf: () => NEXT_PORT
|
|
3318
|
+
});
|
|
3319
|
+
function withResumeUrl(response, url, inBody) {
|
|
3320
|
+
const body = response.body ?? {};
|
|
3321
|
+
const object = typeof body === "object" && !Array.isArray(body);
|
|
3322
|
+
return {
|
|
3323
|
+
...response,
|
|
3324
|
+
headers: {
|
|
3325
|
+
...response.headers,
|
|
3326
|
+
[RESUME_URL_HEADER]: url
|
|
3327
|
+
},
|
|
3328
|
+
...inBody && object ? { body: {
|
|
3329
|
+
...body,
|
|
3330
|
+
resumeUrl: url
|
|
3331
|
+
} } : {}
|
|
3332
|
+
};
|
|
3333
|
+
}
|
|
3334
|
+
function resumeRequest(payload) {
|
|
3335
|
+
const record = payload ?? {};
|
|
3336
|
+
return {
|
|
3337
|
+
body: record.body ?? null,
|
|
3338
|
+
headers: record.headers ?? {},
|
|
3339
|
+
queryParams: record.queryParams ?? {}
|
|
3340
|
+
};
|
|
3341
|
+
}
|
|
3342
|
+
const waitForWebhookAction = withPorts(createAction({
|
|
3343
|
+
name: "waitForWebhook",
|
|
3344
|
+
displayName: "Respond and wait for webhook",
|
|
3345
|
+
description: `Answers the request the run holds with this response and the step's resume URL (in the ${RESUME_URL_HEADER} header, and in a JSON body when asked), then suspends the run until that URL is called. The resuming request's body, headers and query are the step's output.`,
|
|
3346
|
+
requireAuth: false,
|
|
3347
|
+
props: {
|
|
3348
|
+
...responseProps(false),
|
|
3349
|
+
includeResumeUrl: withHints(Property.Checkbox({
|
|
3350
|
+
displayName: "Add resumeUrl to the body",
|
|
3351
|
+
description: "Adds a resumeUrl field to a JSON object body. POST to it to resume; append /sync to wait for the run's answer.",
|
|
3352
|
+
required: false,
|
|
3353
|
+
defaultValue: true
|
|
3354
|
+
}), shownWhen("responseType", ["json"])),
|
|
3355
|
+
expiresAfter: Property.Number({
|
|
3356
|
+
displayName: "Expires after",
|
|
3357
|
+
description: "Ends the run if nobody calls the URL in time; the workflow's maxSuspensionDays still applies.",
|
|
3358
|
+
required: false
|
|
3359
|
+
}),
|
|
3360
|
+
expiresUnit: Property.StaticDropdown({
|
|
3361
|
+
displayName: "Expiry unit",
|
|
3362
|
+
required: false,
|
|
3363
|
+
defaultValue: "days",
|
|
3364
|
+
options: { options: unitOptions }
|
|
3365
|
+
})
|
|
3366
|
+
},
|
|
3367
|
+
run: async (raw) => {
|
|
3368
|
+
const ctx = context$1(raw);
|
|
3369
|
+
if (ctx.executionType === "RESUME") return resumeRequest(ctx.resumePayload);
|
|
3370
|
+
const block = "Respond and wait for webhook";
|
|
3371
|
+
if (!ctx.run.canPause) throw new CoreCannotPauseError(block);
|
|
3372
|
+
const props = ctx.propsValue;
|
|
3373
|
+
const response = configuredResponse(props, block) ?? {
|
|
3374
|
+
status: 200,
|
|
3375
|
+
headers: {}
|
|
3376
|
+
};
|
|
3377
|
+
const inBody = (blank(props.responseType) || props.responseType === "json") && props.includeResumeUrl !== false;
|
|
3378
|
+
const expiresMs = durationMs(props.expiresAfter, props.expiresUnit ?? "days", block);
|
|
3379
|
+
const waitpoint = await ctx.run.createWaitpoint({
|
|
3380
|
+
type: "WEBHOOK",
|
|
3381
|
+
responseToSend: (url) => withResumeUrl(response, url, inBody),
|
|
3382
|
+
...expiresMs ? { expiresAt: new Date(Date.now() + expiresMs).toISOString() } : {}
|
|
3383
|
+
});
|
|
3384
|
+
ctx.run.waitForWaitpoint(waitpoint.id);
|
|
3385
|
+
return { resumeUrl: waitpoint.resumeUrl };
|
|
3386
|
+
}
|
|
3387
|
+
}), {
|
|
3388
|
+
ports: PIECE_ACTION_PORTS,
|
|
3389
|
+
portOf: () => NEXT_PORT
|
|
3390
|
+
});
|
|
3391
|
+
//#endregion
|
|
2936
3392
|
//#region src/pieces/core/version.ts
|
|
2937
|
-
const CORE_PIECE_VERSION = "6.2.3-dev.
|
|
3393
|
+
const CORE_PIECE_VERSION = "6.2.3-dev.85";
|
|
2938
3394
|
//#endregion
|
|
2939
3395
|
//#region src/pieces/core/index.ts
|
|
2940
3396
|
const corePiece = createPiece({
|
|
2941
3397
|
displayName: "Core",
|
|
2942
|
-
description: "The engine's own blocks: branching, assertions, and the triggers that belong to no service.",
|
|
3398
|
+
description: "The engine's own blocks: branching, assertions, delays, approvals, stopping and webhook replies, and the triggers that belong to no service.",
|
|
2943
3399
|
logoUrl: "",
|
|
2944
3400
|
authors: ["powerhouse"],
|
|
2945
3401
|
auth: void 0,
|
|
2946
3402
|
categories: [PieceCategory.CORE],
|
|
2947
|
-
actions: [
|
|
3403
|
+
actions: [
|
|
3404
|
+
branchAction,
|
|
3405
|
+
assertAction,
|
|
3406
|
+
delayAction,
|
|
3407
|
+
approvalAction,
|
|
3408
|
+
stopAction,
|
|
3409
|
+
waitForWebhookAction
|
|
3410
|
+
],
|
|
2948
3411
|
triggers: [
|
|
2949
3412
|
scheduleTrigger,
|
|
2950
3413
|
webhookTrigger,
|
|
@@ -2999,10 +3462,56 @@ var UnknownBuiltinActionError = class extends Error {
|
|
|
2999
3462
|
this.name = "UnknownBuiltinActionError";
|
|
3000
3463
|
}
|
|
3001
3464
|
};
|
|
3002
|
-
|
|
3465
|
+
function resolvedCall(call, resumeBaseUrl) {
|
|
3466
|
+
const { responseToSend, ...rest } = call;
|
|
3467
|
+
if (typeof responseToSend !== "function") return responseToSend ? {
|
|
3468
|
+
...rest,
|
|
3469
|
+
responseToSend
|
|
3470
|
+
} : rest;
|
|
3471
|
+
if (!resumeBaseUrl) return rest;
|
|
3472
|
+
const token = randomBytes(32).toString("base64url");
|
|
3473
|
+
const url = `${resumeBaseUrl.replace(/\/+$/, "")}/${token}`;
|
|
3474
|
+
return {
|
|
3475
|
+
...rest,
|
|
3476
|
+
responseToSend: responseToSend(url),
|
|
3477
|
+
token
|
|
3478
|
+
};
|
|
3479
|
+
}
|
|
3480
|
+
async function runBuiltinAction(builtin, actionName, propsValue, options = {}) {
|
|
3003
3481
|
const action = getActions(builtin.piece)[actionName];
|
|
3004
3482
|
if (!action || typeof action.run !== "function") throw new UnknownBuiltinActionError(builtin.name, actionName);
|
|
3005
|
-
|
|
3483
|
+
let paused;
|
|
3484
|
+
let stopped;
|
|
3485
|
+
const { waitpoints, resume } = options;
|
|
3486
|
+
const context = {
|
|
3487
|
+
propsValue,
|
|
3488
|
+
executionType: resume ? "RESUME" : "BEGIN",
|
|
3489
|
+
...resume ? { resumePayload: resume.payload } : {},
|
|
3490
|
+
run: {
|
|
3491
|
+
canPause: waitpoints !== void 0,
|
|
3492
|
+
createWaitpoint: (call) => {
|
|
3493
|
+
if (!waitpoints) throw new CoreCannotPauseError(actionName);
|
|
3494
|
+
return waitpoints.create(resolvedCall(call, waitpoints.resumeBaseUrl));
|
|
3495
|
+
},
|
|
3496
|
+
waitForWaitpoint: (waitpointId) => {
|
|
3497
|
+
if (!waitpoints) throw new CoreCannotPauseError(actionName);
|
|
3498
|
+
paused = { waitpointId };
|
|
3499
|
+
},
|
|
3500
|
+
stop: (params) => {
|
|
3501
|
+
stopped = jsonSafe(params?.response ?? {}) ?? {};
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3504
|
+
};
|
|
3505
|
+
const output = await action.run(context);
|
|
3506
|
+
if (paused) return {
|
|
3507
|
+
output,
|
|
3508
|
+
paused
|
|
3509
|
+
};
|
|
3510
|
+
if (stopped) return {
|
|
3511
|
+
output,
|
|
3512
|
+
response: stopped,
|
|
3513
|
+
stopped: true
|
|
3514
|
+
};
|
|
3006
3515
|
return {
|
|
3007
3516
|
output,
|
|
3008
3517
|
...isPorted(action) ? { port: action.portOf(output) } : {}
|
|
@@ -3086,6 +3595,27 @@ function storeHandlers(port) {
|
|
|
3086
3595
|
};
|
|
3087
3596
|
}
|
|
3088
3597
|
const logger$1 = childLogger(["workflow", "piece-staging"]);
|
|
3598
|
+
function waitpointHandlers(port, execution, parsed, created) {
|
|
3599
|
+
return { [WAITPOINT_CREATE]: async (payload) => {
|
|
3600
|
+
const call = payload;
|
|
3601
|
+
const waitpoint = await port.create({
|
|
3602
|
+
...waitpointRequest(execution, parsed),
|
|
3603
|
+
type: call.type,
|
|
3604
|
+
...call.resumeDateTime !== void 0 ? { resumeDateTime: call.resumeDateTime } : {},
|
|
3605
|
+
...call.responseToSend !== void 0 ? { responseToSend: call.responseToSend } : {}
|
|
3606
|
+
});
|
|
3607
|
+
created.add(waitpoint.id);
|
|
3608
|
+
return waitpoint;
|
|
3609
|
+
} };
|
|
3610
|
+
}
|
|
3611
|
+
function waitpointRequest(execution, parsed) {
|
|
3612
|
+
return {
|
|
3613
|
+
stepId: execution.step.id,
|
|
3614
|
+
stepKey: execution.step.key,
|
|
3615
|
+
pieceName: parsed.packageName,
|
|
3616
|
+
blockName: parsed.name
|
|
3617
|
+
};
|
|
3618
|
+
}
|
|
3089
3619
|
function stepTaps(options, execution, values) {
|
|
3090
3620
|
const { onPieceLog, onPartialOutput } = options;
|
|
3091
3621
|
if (!onPieceLog && !onPartialOutput) return void 0;
|
|
@@ -3159,13 +3689,26 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3159
3689
|
try {
|
|
3160
3690
|
const builtin = builtinPiece(parsed.packageName);
|
|
3161
3691
|
return {
|
|
3162
|
-
...builtin ? await runBuiltinAction(builtin, parsed.name, execution.config) : await this.run(execution, parsed),
|
|
3692
|
+
...builtin ? await runBuiltinAction(builtin, parsed.name, execution.config, this.builtinOptions(execution, parsed)) : await this.run(execution, parsed),
|
|
3163
3693
|
resolution
|
|
3164
3694
|
};
|
|
3165
3695
|
} catch (error) {
|
|
3166
3696
|
throw withResolution(error, resolution);
|
|
3167
3697
|
}
|
|
3168
3698
|
}
|
|
3699
|
+
builtinOptions(execution, parsed) {
|
|
3700
|
+
const port = this.options.stepTest?.() ?? false ? void 0 : this.options.waitpoints?.();
|
|
3701
|
+
return {
|
|
3702
|
+
...port ? { waitpoints: {
|
|
3703
|
+
create: (call) => port.create({
|
|
3704
|
+
...waitpointRequest(execution, parsed),
|
|
3705
|
+
...call
|
|
3706
|
+
}),
|
|
3707
|
+
...port.resumeBaseUrl ? { resumeBaseUrl: port.resumeBaseUrl } : {}
|
|
3708
|
+
} } : {},
|
|
3709
|
+
...execution.resume ? { resume: execution.resume } : {}
|
|
3710
|
+
};
|
|
3711
|
+
}
|
|
3169
3712
|
async run(execution, parsed) {
|
|
3170
3713
|
const stagingDir = this.options.stagingRoot ? path.join(this.options.stagingRoot, randomUUID()) : void 0;
|
|
3171
3714
|
const runSecrets = execution.redactValues ?? [];
|
|
@@ -3194,6 +3737,15 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3194
3737
|
const pieceStore = this.options.pieceStore;
|
|
3195
3738
|
const notifications = stepTaps(this.options, execution, redactValues);
|
|
3196
3739
|
const egress = this.options.egress === void 0 ? DEFAULT_EGRESS_POLICY : this.options.egress;
|
|
3740
|
+
const uploads = this.uploadHandlers(stagingDir, signal);
|
|
3741
|
+
const stepTest = this.options.stepTest?.() ?? false;
|
|
3742
|
+
const waitpoints = stepTest ? void 0 : this.options.waitpoints?.();
|
|
3743
|
+
const created = /* @__PURE__ */ new Set();
|
|
3744
|
+
const hostCalls = pieceStore || uploads || waitpoints ? {
|
|
3745
|
+
...pieceStore ? storeHandlers(pieceStore) : {},
|
|
3746
|
+
...uploads,
|
|
3747
|
+
...waitpoints ? waitpointHandlers(waitpoints, execution, parsed, created) : {}
|
|
3748
|
+
} : void 0;
|
|
3197
3749
|
const reactorTap = await this.options.reactorAccess?.({
|
|
3198
3750
|
block: parsed,
|
|
3199
3751
|
reactorConnectionId: execution.reactorConnectionId
|
|
@@ -3208,8 +3760,15 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3208
3760
|
stepName: execution.step.key
|
|
3209
3761
|
},
|
|
3210
3762
|
...redactValues.length > 0 ? { redactValues } : {},
|
|
3211
|
-
...
|
|
3763
|
+
...stepTest ? { stepTest: true } : {},
|
|
3764
|
+
...waitpoints ? { canPause: true } : {},
|
|
3765
|
+
...waitpoints?.resumeBaseUrl ? { resumeBaseUrl: waitpoints.resumeBaseUrl } : {},
|
|
3766
|
+
...execution.resume ? {
|
|
3767
|
+
executionType: "RESUME",
|
|
3768
|
+
resumePayload: execution.resume.payload
|
|
3769
|
+
} : {},
|
|
3212
3770
|
...stagingDir ? { stagingDir } : {},
|
|
3771
|
+
...uploads ? { uploadFiles: true } : {},
|
|
3213
3772
|
...stagedInputs ? { stagedInputs } : {},
|
|
3214
3773
|
...pieceStore ? { durableStore: true } : {},
|
|
3215
3774
|
...this.options.onPieceLog ? { captureLogs: true } : {},
|
|
@@ -3218,13 +3777,31 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3218
3777
|
}, {
|
|
3219
3778
|
...remainingMs ? { timeoutMs: remainingMs } : {},
|
|
3220
3779
|
hostCallTimeoutMs: hostCallTimeoutForStep(timeoutMs),
|
|
3221
|
-
...
|
|
3780
|
+
...hostCalls ? { hostCalls } : {},
|
|
3222
3781
|
...notifications ? { notifications } : {},
|
|
3223
3782
|
...reactorTap ? { reactor: reactorTap } : {}
|
|
3224
3783
|
});
|
|
3784
|
+
const output = await this.ingestFiles(result.output, result.files, stagingDir, signal);
|
|
3785
|
+
const answer = {
|
|
3786
|
+
...result.response ? { response: result.response } : {},
|
|
3787
|
+
...result.stopped ? { stopped: true } : {}
|
|
3788
|
+
};
|
|
3789
|
+
if (!result.paused) return {
|
|
3790
|
+
output,
|
|
3791
|
+
redactValues,
|
|
3792
|
+
...answer
|
|
3793
|
+
};
|
|
3794
|
+
if (!waitpoints) throw new Error("The step paused a run that cannot pause");
|
|
3795
|
+
if ("waitpointId" in result.paused && !created.has(result.paused.waitpointId)) throw new Error(`waitForWaitpoint: the step waited on waitpoint "${result.paused.waitpointId}", which it did not create; a step can only wait on a waitpoint its own createWaitpoint returned`);
|
|
3796
|
+
const waitpointId = "waitpointId" in result.paused ? result.paused.waitpointId : (await waitpoints.create({
|
|
3797
|
+
...waitpointRequest(execution, parsed),
|
|
3798
|
+
...result.paused.pause,
|
|
3799
|
+
...result.paused.token ? { token: result.paused.token } : {}
|
|
3800
|
+
})).id;
|
|
3225
3801
|
return {
|
|
3226
|
-
output
|
|
3227
|
-
redactValues
|
|
3802
|
+
output,
|
|
3803
|
+
redactValues,
|
|
3804
|
+
paused: { waitpointId }
|
|
3228
3805
|
};
|
|
3229
3806
|
} catch (error) {
|
|
3230
3807
|
throw redactThrown(error, redactValues);
|
|
@@ -3290,6 +3867,20 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3290
3867
|
});
|
|
3291
3868
|
return meta;
|
|
3292
3869
|
}
|
|
3870
|
+
uploadHandlers(stagingDir, signal) {
|
|
3871
|
+
const port = this.options.attachments;
|
|
3872
|
+
if (!stagingDir || !port) return void 0;
|
|
3873
|
+
return { [FILES_UPLOAD]: async (payload) => {
|
|
3874
|
+
const file = payload;
|
|
3875
|
+
const size = await this.checkStagedFile(file, stagingDir);
|
|
3876
|
+
return port.write({
|
|
3877
|
+
path: path.resolve(file.path),
|
|
3878
|
+
fileName: file.fileName,
|
|
3879
|
+
size,
|
|
3880
|
+
contentType: file.contentType
|
|
3881
|
+
}, signal);
|
|
3882
|
+
} };
|
|
3883
|
+
}
|
|
3293
3884
|
async checkStagedFile(file, stagingDir) {
|
|
3294
3885
|
if (!stagingDir) throw new Error(`Refusing to ingest "${file.fileName}": no staging directory`);
|
|
3295
3886
|
const root = await realpath(stagingDir);
|
|
@@ -3480,6 +4071,20 @@ function actionRetryPolicy(retry) {
|
|
|
3480
4071
|
...declared
|
|
3481
4072
|
});
|
|
3482
4073
|
}
|
|
4074
|
+
function lazyEntry(read) {
|
|
4075
|
+
let value;
|
|
4076
|
+
let done = false;
|
|
4077
|
+
return Object.defineProperty({}, "output", {
|
|
4078
|
+
enumerable: true,
|
|
4079
|
+
get: () => {
|
|
4080
|
+
if (!done) {
|
|
4081
|
+
value = read();
|
|
4082
|
+
done = true;
|
|
4083
|
+
}
|
|
4084
|
+
return value;
|
|
4085
|
+
}
|
|
4086
|
+
});
|
|
4087
|
+
}
|
|
3483
4088
|
function deadPortWarnings(definition, declaredPorts) {
|
|
3484
4089
|
const blocks = new Map(definition.steps.map((step) => [step.id, {
|
|
3485
4090
|
key: step.key,
|
|
@@ -3530,7 +4135,9 @@ async function runWorkflow(options) {
|
|
|
3530
4135
|
let runFailed;
|
|
3531
4136
|
let runCancelled;
|
|
3532
4137
|
let runFailedName;
|
|
3533
|
-
let
|
|
4138
|
+
let runWaiting;
|
|
4139
|
+
let runStopped = false;
|
|
4140
|
+
let executedCount = options.firstOrdinal ?? 0;
|
|
3534
4141
|
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => {
|
|
3535
4142
|
setTimeout(resolve, ms).unref();
|
|
3536
4143
|
}));
|
|
@@ -3607,7 +4214,27 @@ async function runWorkflow(options) {
|
|
|
3607
4214
|
scope.steps[step.key] = { output: null };
|
|
3608
4215
|
decideOutgoing(step.id, "next");
|
|
3609
4216
|
};
|
|
4217
|
+
const carryStep = (step, carried) => {
|
|
4218
|
+
const failed = carried.status === "FAILED";
|
|
4219
|
+
const port = carried.port ?? (failed ? "error" : "next");
|
|
4220
|
+
records.set(step.id, {
|
|
4221
|
+
stepId: step.id,
|
|
4222
|
+
key: step.key,
|
|
4223
|
+
pieceName: step.pieceName,
|
|
4224
|
+
blockName: step.actionName,
|
|
4225
|
+
status: carried.status,
|
|
4226
|
+
port,
|
|
4227
|
+
carried: true
|
|
4228
|
+
});
|
|
4229
|
+
scope.steps[step.key] = failed ? { error: carried.error ?? "" } : lazyEntry(carried.output);
|
|
4230
|
+
decideOutgoing(step.id, port);
|
|
4231
|
+
};
|
|
3610
4232
|
const executeStep = async (step) => {
|
|
4233
|
+
const carried = options.carriedSteps?.get(step.id);
|
|
4234
|
+
if (carried) {
|
|
4235
|
+
carryStep(step, carried);
|
|
4236
|
+
return;
|
|
4237
|
+
}
|
|
3611
4238
|
if (step.skip === true) {
|
|
3612
4239
|
await passStep(step);
|
|
3613
4240
|
return;
|
|
@@ -3645,8 +4272,9 @@ async function runWorkflow(options) {
|
|
|
3645
4272
|
const maxAttempts = retry?.maxAttempts ?? 1;
|
|
3646
4273
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3647
4274
|
let input;
|
|
4275
|
+
const resumedCore = options.resume?.stepId === step.id && step.pieceName === CORE_PIECE_NAME;
|
|
3648
4276
|
try {
|
|
3649
|
-
input = resolveStepInput(step, scope);
|
|
4277
|
+
input = resumedCore ? resolveResumedCoreInput(step, scope) : resolveStepInput(step, scope);
|
|
3650
4278
|
checkDynamicProperties(input, step.propertySettings);
|
|
3651
4279
|
} catch (error) {
|
|
3652
4280
|
await endStep(step, {
|
|
@@ -3667,10 +4295,34 @@ async function runWorkflow(options) {
|
|
|
3667
4295
|
reactorConnectionId: step.reactorConnectionId,
|
|
3668
4296
|
step,
|
|
3669
4297
|
...runSecrets.length > 0 ? { redactValues: runSecrets } : {},
|
|
3670
|
-
...defaultTimeout
|
|
4298
|
+
...defaultTimeout,
|
|
4299
|
+
...options.resume?.stepId === step.id ? { resume: { payload: options.resume.payload } } : {}
|
|
3671
4300
|
});
|
|
3672
4301
|
const port = result.port ?? "next";
|
|
3673
4302
|
const values = [...runSecrets, ...result.redactValues ?? []];
|
|
4303
|
+
if (result.response) options.onRespond?.(result.response);
|
|
4304
|
+
if (result.paused) {
|
|
4305
|
+
const record = {
|
|
4306
|
+
stepId: step.id,
|
|
4307
|
+
key: step.key,
|
|
4308
|
+
pieceName: step.pieceName,
|
|
4309
|
+
blockName: step.actionName,
|
|
4310
|
+
status: "WAITING",
|
|
4311
|
+
input: journaled(input, values),
|
|
4312
|
+
output: journaled(referenceDocuments(result.output), values),
|
|
4313
|
+
startedAt,
|
|
4314
|
+
...withPiece(pieceRecord(result.resolution)),
|
|
4315
|
+
configHash: stepConfigHash(step),
|
|
4316
|
+
...attempts
|
|
4317
|
+
};
|
|
4318
|
+
records.set(step.id, record);
|
|
4319
|
+
await journal(record);
|
|
4320
|
+
runWaiting = {
|
|
4321
|
+
stepId: step.id,
|
|
4322
|
+
waitpointId: result.paused.waitpointId
|
|
4323
|
+
};
|
|
4324
|
+
return;
|
|
4325
|
+
}
|
|
3674
4326
|
const record = {
|
|
3675
4327
|
stepId: step.id,
|
|
3676
4328
|
key: step.key,
|
|
@@ -3689,6 +4341,10 @@ async function runWorkflow(options) {
|
|
|
3689
4341
|
records.set(step.id, record);
|
|
3690
4342
|
await journal(record);
|
|
3691
4343
|
scope.steps[step.key] = { output: result.output };
|
|
4344
|
+
if (result.stopped) {
|
|
4345
|
+
runStopped = true;
|
|
4346
|
+
return;
|
|
4347
|
+
}
|
|
3692
4348
|
decideOutgoing(step.id, port);
|
|
3693
4349
|
return;
|
|
3694
4350
|
} catch (error) {
|
|
@@ -3794,8 +4450,9 @@ async function runWorkflow(options) {
|
|
|
3794
4450
|
runCancelled ??= outOfTime();
|
|
3795
4451
|
return runCancelled !== void 0;
|
|
3796
4452
|
};
|
|
4453
|
+
const stopped = () => Boolean(runFailed || runCancelled || runWaiting || runStopped);
|
|
3797
4454
|
let progressed = true;
|
|
3798
|
-
while (progressed && !
|
|
4455
|
+
while (progressed && !stopped()) {
|
|
3799
4456
|
progressed = false;
|
|
3800
4457
|
for (const step of definition.steps) {
|
|
3801
4458
|
if (records.has(step.id)) continue;
|
|
@@ -3804,7 +4461,7 @@ async function runWorkflow(options) {
|
|
|
3804
4461
|
if (expiredBeforeStep()) break;
|
|
3805
4462
|
await executeStep(step);
|
|
3806
4463
|
progressed = true;
|
|
3807
|
-
if (
|
|
4464
|
+
if (stopped()) break;
|
|
3808
4465
|
continue;
|
|
3809
4466
|
}
|
|
3810
4467
|
if (inbound.length === 0) continue;
|
|
@@ -3814,9 +4471,18 @@ async function runWorkflow(options) {
|
|
|
3814
4471
|
await executeStep(step);
|
|
3815
4472
|
} else skipStep(step);
|
|
3816
4473
|
progressed = true;
|
|
3817
|
-
if (
|
|
4474
|
+
if (stopped()) break;
|
|
3818
4475
|
}
|
|
3819
4476
|
}
|
|
4477
|
+
if (runWaiting && !runFailed && !runCancelled) {
|
|
4478
|
+
const warnings = options.declaredPorts ? deadPortWarnings(definition, options.declaredPorts) : [];
|
|
4479
|
+
return {
|
|
4480
|
+
status: "WAITING",
|
|
4481
|
+
steps: definition.steps.filter((step) => records.has(step.id)).map((step) => records.get(step.id)),
|
|
4482
|
+
waiting: runWaiting,
|
|
4483
|
+
...warnings.length > 0 ? { warnings } : {}
|
|
4484
|
+
};
|
|
4485
|
+
}
|
|
3820
4486
|
for (const step of definition.steps) if (!records.has(step.id)) skipStep(step);
|
|
3821
4487
|
const steps = definition.steps.map((step) => records.get(step.id));
|
|
3822
4488
|
const warnings = options.declaredPorts ? deadPortWarnings(definition, options.declaredPorts) : [];
|
|
@@ -3898,6 +4564,7 @@ var WorkflowTelemetry = class {
|
|
|
3898
4564
|
stepDuration;
|
|
3899
4565
|
phaseDuration;
|
|
3900
4566
|
dispatcherGauges;
|
|
4567
|
+
suspendedGauge;
|
|
3901
4568
|
poolGauges;
|
|
3902
4569
|
constructor(options = {}) {
|
|
3903
4570
|
this.tracer = options.tracer ?? trace.getTracer("@powerhousedao/reactor-workflow");
|
|
@@ -4027,6 +4694,18 @@ var WorkflowTelemetry = class {
|
|
|
4027
4694
|
this.meter.addBatchObservableCallback(callback, observables);
|
|
4028
4695
|
return () => this.meter.removeBatchObservableCallback(callback, observables);
|
|
4029
4696
|
}
|
|
4697
|
+
observeSuspended(count) {
|
|
4698
|
+
this.suspendedGauge ??= this.meter.createObservableGauge("workflow.runs.suspended", {
|
|
4699
|
+
description: "Runs suspended on a waitpoint",
|
|
4700
|
+
unit: "{run}"
|
|
4701
|
+
});
|
|
4702
|
+
const gauge = this.suspendedGauge;
|
|
4703
|
+
const callback = (result) => {
|
|
4704
|
+
result.observe(count());
|
|
4705
|
+
};
|
|
4706
|
+
gauge.addCallback(callback);
|
|
4707
|
+
return () => gauge.removeCallback(callback);
|
|
4708
|
+
}
|
|
4030
4709
|
createPoolGauges() {
|
|
4031
4710
|
const gauge = (name, description) => this.meter.createObservableGauge(name, {
|
|
4032
4711
|
description,
|
|
@@ -4168,6 +4847,6 @@ function tracedMethods(target, telemetry, prefix, parent, nested = []) {
|
|
|
4168
4847
|
} });
|
|
4169
4848
|
}
|
|
4170
4849
|
//#endregion
|
|
4171
|
-
export {
|
|
4850
|
+
export { containsRedactedMarker as $, AttachmentCache as A, SecretCreatorMismatchError as B, blockLabel as C, isIndeterminateError as Ct, describeBuiltinPiece as D, builtinPiece as E, shapeConnection as F, secretRefFromId as G, SecretNotFoundError as H, resolveStepInput as I, PieceWorkerPool as J, stepBlock as K, expressionsIn as L, StaticConnectionResolver as M, declaredConnectionIds as N, CORE_PIECE_NAME$1 as O, declaredReactorConnectionIds as P, PieceWorkerTimeoutError as Q, unavailableValue as R, storeHandlers as S, setPieceRegistryUrl as St, blockPorts as T, SecretOwnerMismatchError as U, SecretDeletedError as V, parseSecretRef as W, PieceWorkerDisposedError as X, PieceWorker as Y, PieceWorkerError as Z, effectiveRetryPolicy as _, unsupportedTrigger as _t, PieceRegistry as a, isPrivateAddress as at, isHostBound as b, npmRegistryBaseUrl as bt, packagePieces as c, FileTooLargeError as ct, runWorkflow as d, pieceModuleRef as dt, redact as et, canonicalJson as f, sourcedResolver as ft, checkDynamicProperties as g, unsupportedAuth as gt, DynamicPropertiesError as h, authMethodFor as ht, tracedSteps as i, DEFAULT_EGRESS_POLICY as it, BoundConnectionResolver as j, CORE_PIECE_VERSION as k, RUN_DEADLINE_ERROR_NAME as l, maxFileBytes as lt, stepConfigHash as m, UnsupportedPieceFeatureError as mt, WorkflowTelemetry as n, rememberSecrets as nt, installedPiece as o, parseAddress as ot, hashOf as p, buildDescriptor as pt, triggerBlock as q, tracedMethods as r, secretsFor as rt, installedPieces as s, extractDedupeKey as st, TELEMETRY_SCOPE as t, redactMessage as tt, errorNameOf as u, bundleResolver as ut, ActivepiecesBlockExecutor as v, ensurePieceBundle as vt, unpinnedNote as w, resolvedBlock as x, pieceRegistrySource as xt, CompositeBlockExecutor as y, fetchPieceBundle as yt, InMemorySecretProvider as z };
|
|
4172
4851
|
|
|
4173
|
-
//# sourceMappingURL=telemetry-
|
|
4852
|
+
//# sourceMappingURL=telemetry-B5OOpfCS.js.map
|