@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
|
@@ -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;
|
|
@@ -1655,6 +1660,24 @@ var PieceWorkerPool = class {
|
|
|
1655
1660
|
waiting: this.waiters.run.length
|
|
1656
1661
|
};
|
|
1657
1662
|
}
|
|
1663
|
+
memoryStats() {
|
|
1664
|
+
let childRssTotal = 0;
|
|
1665
|
+
let childRssMax = 0;
|
|
1666
|
+
let childHeapUsedTotal = 0;
|
|
1667
|
+
for (const child of this.children) {
|
|
1668
|
+
const memory = child.worker.health?.().memory;
|
|
1669
|
+
if (!memory) continue;
|
|
1670
|
+
childRssTotal += memory.rss;
|
|
1671
|
+
childRssMax = Math.max(childRssMax, memory.rss);
|
|
1672
|
+
childHeapUsedTotal += memory.heapUsed;
|
|
1673
|
+
}
|
|
1674
|
+
return {
|
|
1675
|
+
children: this.children.size,
|
|
1676
|
+
childRssTotal,
|
|
1677
|
+
childRssMax,
|
|
1678
|
+
childHeapUsedTotal
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1658
1681
|
dispose() {
|
|
1659
1682
|
if (this.disposed) return;
|
|
1660
1683
|
this.disposed = true;
|
|
@@ -2223,7 +2246,7 @@ function asList(value, side) {
|
|
|
2223
2246
|
if (Array.isArray(value)) return value;
|
|
2224
2247
|
throw new BranchConfigError(`${side} must be a list, got ${describe(value)}`);
|
|
2225
2248
|
}
|
|
2226
|
-
const blank = (value) => value === void 0 || value === null || value === "";
|
|
2249
|
+
const blank$1 = (value) => value === void 0 || value === null || value === "";
|
|
2227
2250
|
function textOp(label, test) {
|
|
2228
2251
|
return {
|
|
2229
2252
|
label,
|
|
@@ -2301,8 +2324,8 @@ const BRANCH_OPERATORS = {
|
|
|
2301
2324
|
},
|
|
2302
2325
|
LIST_IS_EMPTY: unary("List is empty", "list", (v) => asList(v, "left").length === 0),
|
|
2303
2326
|
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)
|
|
2327
|
+
EXISTS: unary("Exists", "any", (v) => !blank$1(v)),
|
|
2328
|
+
DOES_NOT_EXIST: unary("Does not exist", "any", blank$1)
|
|
2306
2329
|
};
|
|
2307
2330
|
const EXISTENCE_OPERATORS = /* @__PURE__ */ new Set(["EXISTS", "DOES_NOT_EXIST"]);
|
|
2308
2331
|
const OPERATORS = BRANCH_OPERATORS;
|
|
@@ -2339,6 +2362,24 @@ function resolveStepInput(step, scope) {
|
|
|
2339
2362
|
assertNoUnavailableValue(input);
|
|
2340
2363
|
return input;
|
|
2341
2364
|
}
|
|
2365
|
+
function resolveResumedCoreInput(step, scope) {
|
|
2366
|
+
try {
|
|
2367
|
+
return resolveStepInput(step, scope);
|
|
2368
|
+
} catch (error) {
|
|
2369
|
+
if (!(error instanceof UnavailableValueError)) throw error;
|
|
2370
|
+
}
|
|
2371
|
+
const { config } = step;
|
|
2372
|
+
if (config === null || typeof config !== "object" || Array.isArray(config)) return {};
|
|
2373
|
+
const input = {};
|
|
2374
|
+
for (const [key, value] of Object.entries(config)) try {
|
|
2375
|
+
const resolved = resolveExpressions(value, scope);
|
|
2376
|
+
assertNoUnavailableValue(resolved);
|
|
2377
|
+
input[key] = resolved;
|
|
2378
|
+
} catch (error) {
|
|
2379
|
+
if (!(error instanceof UnavailableValueError)) throw error;
|
|
2380
|
+
}
|
|
2381
|
+
return input;
|
|
2382
|
+
}
|
|
2342
2383
|
function resolveStepInputRaw(step, scope) {
|
|
2343
2384
|
const { config } = step;
|
|
2344
2385
|
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);
|
|
@@ -2984,18 +3025,407 @@ const manualTrigger = createTrigger({
|
|
|
2984
3025
|
...hooks("manual")
|
|
2985
3026
|
});
|
|
2986
3027
|
//#endregion
|
|
3028
|
+
//#region src/pieces/core/context.ts
|
|
3029
|
+
var CoreCannotPauseError = class extends Error {
|
|
3030
|
+
constructor(block) {
|
|
3031
|
+
super(`${block} suspends the run, which only a workflow run can do, not a step test`);
|
|
3032
|
+
this.name = "RunCannotPauseError";
|
|
3033
|
+
}
|
|
3034
|
+
};
|
|
3035
|
+
//#endregion
|
|
3036
|
+
//#region src/pieces/core/waits.ts
|
|
3037
|
+
const UNIT_MS = {
|
|
3038
|
+
seconds: 1e3,
|
|
3039
|
+
minutes: 6e4,
|
|
3040
|
+
hours: 36e5,
|
|
3041
|
+
days: 864e5
|
|
3042
|
+
};
|
|
3043
|
+
const unitOptions = Object.keys(UNIT_MS).map((unit) => ({
|
|
3044
|
+
value: unit,
|
|
3045
|
+
label: unit[0].toUpperCase() + unit.slice(1)
|
|
3046
|
+
}));
|
|
3047
|
+
function durationMs(amount, unit, label) {
|
|
3048
|
+
if (amount === void 0 || amount === null || amount === "") return;
|
|
3049
|
+
const value = Number(amount);
|
|
3050
|
+
if (!Number.isFinite(value) || value < 0) throw new Error(`${label}: ${JSON.stringify(amount)} is not a duration`);
|
|
3051
|
+
if (typeof unit !== "string" || !Object.hasOwn(UNIT_MS, unit)) throw new Error(`${label}: unknown unit ${JSON.stringify(unit)}`);
|
|
3052
|
+
return value * UNIT_MS[unit];
|
|
3053
|
+
}
|
|
3054
|
+
function context$2(ctx) {
|
|
3055
|
+
return ctx;
|
|
3056
|
+
}
|
|
3057
|
+
function assertCanPause(ctx, block) {
|
|
3058
|
+
if (!ctx.run.canPause) throw new CoreCannotPauseError(block);
|
|
3059
|
+
}
|
|
3060
|
+
const delayAction = withPorts(createAction({
|
|
3061
|
+
name: "delay",
|
|
3062
|
+
displayName: "Delay",
|
|
3063
|
+
description: "Suspends the run for a while, or until a date, then carries on. The run holds no worker while it waits.",
|
|
3064
|
+
requireAuth: false,
|
|
3065
|
+
props: {
|
|
3066
|
+
mode: Property.StaticDropdown({
|
|
3067
|
+
displayName: "Mode",
|
|
3068
|
+
required: true,
|
|
3069
|
+
defaultValue: "for",
|
|
3070
|
+
options: { options: [{
|
|
3071
|
+
value: "for",
|
|
3072
|
+
label: "Delay for"
|
|
3073
|
+
}, {
|
|
3074
|
+
value: "until",
|
|
3075
|
+
label: "Delay until"
|
|
3076
|
+
}] }
|
|
3077
|
+
}),
|
|
3078
|
+
amount: withHints(Property.Number({
|
|
3079
|
+
displayName: "Amount",
|
|
3080
|
+
required: true
|
|
3081
|
+
}), shownWhen("mode", ["for"])),
|
|
3082
|
+
unit: withHints(Property.StaticDropdown({
|
|
3083
|
+
displayName: "Unit",
|
|
3084
|
+
required: true,
|
|
3085
|
+
defaultValue: "minutes",
|
|
3086
|
+
options: { options: unitOptions }
|
|
3087
|
+
}), shownWhen("mode", ["for"])),
|
|
3088
|
+
until: withHints(Property.DateTime({
|
|
3089
|
+
displayName: "Until",
|
|
3090
|
+
description: "ISO 8601 date and time; a past one does not wait.",
|
|
3091
|
+
required: true
|
|
3092
|
+
}), shownWhen("mode", ["until"]))
|
|
3093
|
+
},
|
|
3094
|
+
run: async (raw) => {
|
|
3095
|
+
const ctx = context$2(raw);
|
|
3096
|
+
if (ctx.executionType === "RESUME") return { resumedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3097
|
+
const { mode, amount, unit, until } = ctx.propsValue;
|
|
3098
|
+
let resumeAt;
|
|
3099
|
+
if (mode === "until") {
|
|
3100
|
+
resumeAt = typeof until === "string" ? Date.parse(until) : NaN;
|
|
3101
|
+
if (Number.isNaN(resumeAt)) throw new Error(`Delay: ${JSON.stringify(until)} is not a date and time`);
|
|
3102
|
+
} else {
|
|
3103
|
+
const ms = durationMs(amount, unit, "Delay");
|
|
3104
|
+
if (ms === void 0) throw new Error("Delay: an amount is required");
|
|
3105
|
+
resumeAt = Date.now() + ms;
|
|
3106
|
+
}
|
|
3107
|
+
if (resumeAt <= Date.now()) return { resumedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3108
|
+
assertCanPause(ctx, "Delay");
|
|
3109
|
+
const resumeDateTime = new Date(resumeAt).toISOString();
|
|
3110
|
+
const waitpoint = await ctx.run.createWaitpoint({
|
|
3111
|
+
type: "DELAY",
|
|
3112
|
+
resumeDateTime
|
|
3113
|
+
});
|
|
3114
|
+
ctx.run.waitForWaitpoint(waitpoint.id);
|
|
3115
|
+
return { resumeAt: resumeDateTime };
|
|
3116
|
+
}
|
|
3117
|
+
}), {
|
|
3118
|
+
ports: PIECE_ACTION_PORTS,
|
|
3119
|
+
portOf: () => NEXT_PORT
|
|
3120
|
+
});
|
|
3121
|
+
const REASON_RULES = [
|
|
3122
|
+
"none",
|
|
3123
|
+
"reject",
|
|
3124
|
+
"both"
|
|
3125
|
+
];
|
|
3126
|
+
function text(value, fallback) {
|
|
3127
|
+
return typeof value === "string" && value.trim() ? value : fallback;
|
|
3128
|
+
}
|
|
3129
|
+
function approvers(value) {
|
|
3130
|
+
const list = Array.isArray(value) ? value : typeof value === "string" ? value.split(/[\s,]+/) : [];
|
|
3131
|
+
return [...new Set(list.map((entry) => String(entry).trim()).filter(Boolean))];
|
|
3132
|
+
}
|
|
3133
|
+
function approvalDecision(payload) {
|
|
3134
|
+
const record = payload ?? {};
|
|
3135
|
+
const body = record.body && typeof record.body === "object" ? record.body : {};
|
|
3136
|
+
const query = record.queryParams ?? {};
|
|
3137
|
+
return {
|
|
3138
|
+
approved: typeof body.approved === "boolean" ? body.approved : query.action === "approve",
|
|
3139
|
+
reason: [body.reason, query.reason].find((value) => typeof value === "string" && value !== "") ?? null,
|
|
3140
|
+
decidedBy: typeof body.decidedBy === "string" ? body.decidedBy : null,
|
|
3141
|
+
decidedAt: typeof body.decidedAt === "string" ? body.decidedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
3142
|
+
};
|
|
3143
|
+
}
|
|
3144
|
+
const approvalAction = withPorts(createAction({
|
|
3145
|
+
name: "approval",
|
|
3146
|
+
displayName: "Request approval",
|
|
3147
|
+
description: "Suspends the run until someone approves or rejects it in the workflow editor. The decision is the step's output.",
|
|
3148
|
+
requireAuth: false,
|
|
3149
|
+
props: {
|
|
3150
|
+
title: Property.ShortText({
|
|
3151
|
+
displayName: "Title",
|
|
3152
|
+
required: true
|
|
3153
|
+
}),
|
|
3154
|
+
body: Property.LongText({
|
|
3155
|
+
displayName: "Details",
|
|
3156
|
+
description: "Markdown shown to the approver; expressions are filled in when the run pauses.",
|
|
3157
|
+
required: false
|
|
3158
|
+
}),
|
|
3159
|
+
approveLabel: Property.ShortText({
|
|
3160
|
+
displayName: "Approve label",
|
|
3161
|
+
required: false,
|
|
3162
|
+
defaultValue: "Approve"
|
|
3163
|
+
}),
|
|
3164
|
+
rejectLabel: Property.ShortText({
|
|
3165
|
+
displayName: "Reject label",
|
|
3166
|
+
required: false,
|
|
3167
|
+
defaultValue: "Reject"
|
|
3168
|
+
}),
|
|
3169
|
+
reasonRequiredOn: Property.StaticDropdown({
|
|
3170
|
+
displayName: "Reason required",
|
|
3171
|
+
required: false,
|
|
3172
|
+
defaultValue: "none",
|
|
3173
|
+
options: { options: [
|
|
3174
|
+
{
|
|
3175
|
+
value: "none",
|
|
3176
|
+
label: "Never"
|
|
3177
|
+
},
|
|
3178
|
+
{
|
|
3179
|
+
value: "reject",
|
|
3180
|
+
label: "On reject"
|
|
3181
|
+
},
|
|
3182
|
+
{
|
|
3183
|
+
value: "both",
|
|
3184
|
+
label: "Always"
|
|
3185
|
+
}
|
|
3186
|
+
] }
|
|
3187
|
+
}),
|
|
3188
|
+
approvers: Property.Array({
|
|
3189
|
+
displayName: "Approvers",
|
|
3190
|
+
description: "DIDs or addresses allowed to decide in the editor; empty lets anyone who can edit the workflow.",
|
|
3191
|
+
required: false
|
|
3192
|
+
}),
|
|
3193
|
+
expiresAfter: Property.Number({
|
|
3194
|
+
displayName: "Expires after",
|
|
3195
|
+
description: "Ends the run if nobody decides in time; the workflow's maxSuspensionDays still applies.",
|
|
3196
|
+
required: false
|
|
3197
|
+
}),
|
|
3198
|
+
expiresUnit: Property.StaticDropdown({
|
|
3199
|
+
displayName: "Expiry unit",
|
|
3200
|
+
required: false,
|
|
3201
|
+
defaultValue: "days",
|
|
3202
|
+
options: { options: unitOptions }
|
|
3203
|
+
})
|
|
3204
|
+
},
|
|
3205
|
+
run: async (raw) => {
|
|
3206
|
+
const ctx = context$2(raw);
|
|
3207
|
+
if (ctx.executionType === "RESUME") return approvalDecision(ctx.resumePayload);
|
|
3208
|
+
assertCanPause(ctx, "Request approval");
|
|
3209
|
+
const props = ctx.propsValue;
|
|
3210
|
+
const rule = REASON_RULES.includes(props.reasonRequiredOn) ? props.reasonRequiredOn : "none";
|
|
3211
|
+
const approval = {
|
|
3212
|
+
title: text(props.title, "Approval"),
|
|
3213
|
+
body: typeof props.body === "string" && props.body ? props.body : null,
|
|
3214
|
+
approveLabel: text(props.approveLabel, "Approve"),
|
|
3215
|
+
rejectLabel: text(props.rejectLabel, "Reject"),
|
|
3216
|
+
reasonRequiredOn: rule,
|
|
3217
|
+
approvers: approvers(props.approvers)
|
|
3218
|
+
};
|
|
3219
|
+
const expiresMs = durationMs(props.expiresAfter, props.expiresUnit ?? "days", "Request approval");
|
|
3220
|
+
const waitpoint = await ctx.run.createWaitpoint({
|
|
3221
|
+
type: "WEBHOOK",
|
|
3222
|
+
approval,
|
|
3223
|
+
...expiresMs ? { expiresAt: new Date(Date.now() + expiresMs).toISOString() } : {}
|
|
3224
|
+
});
|
|
3225
|
+
ctx.run.waitForWaitpoint(waitpoint.id);
|
|
3226
|
+
return {};
|
|
3227
|
+
}
|
|
3228
|
+
}), {
|
|
3229
|
+
ports: PIECE_ACTION_PORTS,
|
|
3230
|
+
portOf: () => NEXT_PORT
|
|
3231
|
+
});
|
|
3232
|
+
//#endregion
|
|
3233
|
+
//#region src/pieces/core/responses.ts
|
|
3234
|
+
const RESUME_URL_HEADER = "x-resume-webhook-url";
|
|
3235
|
+
const REDIRECT_STATUS = 302;
|
|
3236
|
+
function responseProps(bodyRequired) {
|
|
3237
|
+
return {
|
|
3238
|
+
responseType: Property.StaticDropdown({
|
|
3239
|
+
displayName: "Response type",
|
|
3240
|
+
required: false,
|
|
3241
|
+
defaultValue: "json",
|
|
3242
|
+
options: { options: [
|
|
3243
|
+
{
|
|
3244
|
+
value: "json",
|
|
3245
|
+
label: "JSON"
|
|
3246
|
+
},
|
|
3247
|
+
{
|
|
3248
|
+
value: "raw",
|
|
3249
|
+
label: "Raw"
|
|
3250
|
+
},
|
|
3251
|
+
{
|
|
3252
|
+
value: "redirect",
|
|
3253
|
+
label: "Redirect"
|
|
3254
|
+
}
|
|
3255
|
+
] }
|
|
3256
|
+
}),
|
|
3257
|
+
status: withHints(Property.Number({
|
|
3258
|
+
displayName: "Status",
|
|
3259
|
+
description: "HTTP status; 200 when blank.",
|
|
3260
|
+
required: false
|
|
3261
|
+
}), shownWhen("responseType", ["json", "raw"])),
|
|
3262
|
+
headers: withHints(Property.Object({
|
|
3263
|
+
displayName: "Headers",
|
|
3264
|
+
required: false
|
|
3265
|
+
}), shownWhen("responseType", ["json", "raw"])),
|
|
3266
|
+
body: withHints(Property.Json({
|
|
3267
|
+
displayName: "JSON body",
|
|
3268
|
+
required: bodyRequired
|
|
3269
|
+
}), shownWhen("responseType", ["json"])),
|
|
3270
|
+
text: withHints(Property.LongText({
|
|
3271
|
+
displayName: "Raw body",
|
|
3272
|
+
required: bodyRequired
|
|
3273
|
+
}), shownWhen("responseType", ["raw"])),
|
|
3274
|
+
redirectUrl: withHints(Property.ShortText({
|
|
3275
|
+
displayName: "Redirect URL",
|
|
3276
|
+
required: true
|
|
3277
|
+
}), shownWhen("responseType", ["redirect"]))
|
|
3278
|
+
};
|
|
3279
|
+
}
|
|
3280
|
+
const blank = (value) => value === void 0 || value === null || value === "" || typeof value === "object" && Object.keys(value).length === 0;
|
|
3281
|
+
function jsonBody(value, block) {
|
|
3282
|
+
if (typeof value !== "string") return value;
|
|
3283
|
+
try {
|
|
3284
|
+
return JSON.parse(value);
|
|
3285
|
+
} catch {
|
|
3286
|
+
throw new Error(`${block}: the JSON body is not valid JSON`);
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
function headerMap(value) {
|
|
3290
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
3291
|
+
const headers = {};
|
|
3292
|
+
for (const [name, entry] of Object.entries(value)) if (typeof entry === "string" || typeof entry === "number") headers[name] = String(entry);
|
|
3293
|
+
return headers;
|
|
3294
|
+
}
|
|
3295
|
+
function withProtocol(url) {
|
|
3296
|
+
return /^https?:\/\//i.test(url) ? url : `https://${url}`;
|
|
3297
|
+
}
|
|
3298
|
+
function configuredResponse(props, block) {
|
|
3299
|
+
const type = blank(props.responseType) ? "json" : props.responseType;
|
|
3300
|
+
if (type === "redirect") {
|
|
3301
|
+
if (typeof props.redirectUrl !== "string" || !props.redirectUrl.trim()) throw new Error(`${block}: a redirect URL is required`);
|
|
3302
|
+
const location = withProtocol(props.redirectUrl.trim());
|
|
3303
|
+
return {
|
|
3304
|
+
status: REDIRECT_STATUS,
|
|
3305
|
+
headers: { location },
|
|
3306
|
+
body: location
|
|
3307
|
+
};
|
|
3308
|
+
}
|
|
3309
|
+
const raw = type === "raw";
|
|
3310
|
+
const given = raw ? props.text : props.body;
|
|
3311
|
+
if (blank(given) && blank(props.status) && blank(props.headers)) return;
|
|
3312
|
+
return {
|
|
3313
|
+
status: blank(props.status) ? 200 : Number(props.status),
|
|
3314
|
+
headers: headerMap(props.headers),
|
|
3315
|
+
...blank(given) ? {} : { body: raw ? String(given) : jsonBody(given, block) }
|
|
3316
|
+
};
|
|
3317
|
+
}
|
|
3318
|
+
function context$1(ctx) {
|
|
3319
|
+
return ctx;
|
|
3320
|
+
}
|
|
3321
|
+
const stopAction = withPorts(createAction({
|
|
3322
|
+
name: "stop",
|
|
3323
|
+
displayName: "Stop run",
|
|
3324
|
+
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.",
|
|
3325
|
+
requireAuth: false,
|
|
3326
|
+
props: responseProps(false),
|
|
3327
|
+
run: (raw) => {
|
|
3328
|
+
const ctx = context$1(raw);
|
|
3329
|
+
const response = configuredResponse(ctx.propsValue, "Stop run");
|
|
3330
|
+
ctx.run.stop(response ? { response } : void 0);
|
|
3331
|
+
return Promise.resolve(response ? { response } : {});
|
|
3332
|
+
}
|
|
3333
|
+
}), {
|
|
3334
|
+
ports: STOP_PORTS,
|
|
3335
|
+
portOf: () => NEXT_PORT
|
|
3336
|
+
});
|
|
3337
|
+
function withResumeUrl(response, url, inBody) {
|
|
3338
|
+
const body = response.body ?? {};
|
|
3339
|
+
const object = typeof body === "object" && !Array.isArray(body);
|
|
3340
|
+
return {
|
|
3341
|
+
...response,
|
|
3342
|
+
headers: {
|
|
3343
|
+
...response.headers,
|
|
3344
|
+
[RESUME_URL_HEADER]: url
|
|
3345
|
+
},
|
|
3346
|
+
...inBody && object ? { body: {
|
|
3347
|
+
...body,
|
|
3348
|
+
resumeUrl: url
|
|
3349
|
+
} } : {}
|
|
3350
|
+
};
|
|
3351
|
+
}
|
|
3352
|
+
function resumeRequest(payload) {
|
|
3353
|
+
const record = payload ?? {};
|
|
3354
|
+
return {
|
|
3355
|
+
body: record.body ?? null,
|
|
3356
|
+
headers: record.headers ?? {},
|
|
3357
|
+
queryParams: record.queryParams ?? {}
|
|
3358
|
+
};
|
|
3359
|
+
}
|
|
3360
|
+
const waitForWebhookAction = withPorts(createAction({
|
|
3361
|
+
name: "waitForWebhook",
|
|
3362
|
+
displayName: "Respond and wait for webhook",
|
|
3363
|
+
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.`,
|
|
3364
|
+
requireAuth: false,
|
|
3365
|
+
props: {
|
|
3366
|
+
...responseProps(false),
|
|
3367
|
+
includeResumeUrl: withHints(Property.Checkbox({
|
|
3368
|
+
displayName: "Add resumeUrl to the body",
|
|
3369
|
+
description: "Adds a resumeUrl field to a JSON object body. POST to it to resume; append /sync to wait for the run's answer.",
|
|
3370
|
+
required: false,
|
|
3371
|
+
defaultValue: true
|
|
3372
|
+
}), shownWhen("responseType", ["json"])),
|
|
3373
|
+
expiresAfter: Property.Number({
|
|
3374
|
+
displayName: "Expires after",
|
|
3375
|
+
description: "Ends the run if nobody calls the URL in time; the workflow's maxSuspensionDays still applies.",
|
|
3376
|
+
required: false
|
|
3377
|
+
}),
|
|
3378
|
+
expiresUnit: Property.StaticDropdown({
|
|
3379
|
+
displayName: "Expiry unit",
|
|
3380
|
+
required: false,
|
|
3381
|
+
defaultValue: "days",
|
|
3382
|
+
options: { options: unitOptions }
|
|
3383
|
+
})
|
|
3384
|
+
},
|
|
3385
|
+
run: async (raw) => {
|
|
3386
|
+
const ctx = context$1(raw);
|
|
3387
|
+
if (ctx.executionType === "RESUME") return resumeRequest(ctx.resumePayload);
|
|
3388
|
+
const block = "Respond and wait for webhook";
|
|
3389
|
+
if (!ctx.run.canPause) throw new CoreCannotPauseError(block);
|
|
3390
|
+
const props = ctx.propsValue;
|
|
3391
|
+
const response = configuredResponse(props, block) ?? {
|
|
3392
|
+
status: 200,
|
|
3393
|
+
headers: {}
|
|
3394
|
+
};
|
|
3395
|
+
const inBody = (blank(props.responseType) || props.responseType === "json") && props.includeResumeUrl !== false;
|
|
3396
|
+
const expiresMs = durationMs(props.expiresAfter, props.expiresUnit ?? "days", block);
|
|
3397
|
+
const waitpoint = await ctx.run.createWaitpoint({
|
|
3398
|
+
type: "WEBHOOK",
|
|
3399
|
+
responseToSend: (url) => withResumeUrl(response, url, inBody),
|
|
3400
|
+
...expiresMs ? { expiresAt: new Date(Date.now() + expiresMs).toISOString() } : {}
|
|
3401
|
+
});
|
|
3402
|
+
ctx.run.waitForWaitpoint(waitpoint.id);
|
|
3403
|
+
return { resumeUrl: waitpoint.resumeUrl };
|
|
3404
|
+
}
|
|
3405
|
+
}), {
|
|
3406
|
+
ports: PIECE_ACTION_PORTS,
|
|
3407
|
+
portOf: () => NEXT_PORT
|
|
3408
|
+
});
|
|
3409
|
+
//#endregion
|
|
2987
3410
|
//#region src/pieces/core/version.ts
|
|
2988
|
-
const CORE_PIECE_VERSION = "6.2.3-dev.
|
|
3411
|
+
const CORE_PIECE_VERSION = "6.2.3-dev.86";
|
|
2989
3412
|
//#endregion
|
|
2990
3413
|
//#region src/pieces/core/index.ts
|
|
2991
3414
|
const corePiece = createPiece({
|
|
2992
3415
|
displayName: "Core",
|
|
2993
|
-
description: "The engine's own blocks: branching, assertions, and the triggers that belong to no service.",
|
|
3416
|
+
description: "The engine's own blocks: branching, assertions, delays, approvals, stopping and webhook replies, and the triggers that belong to no service.",
|
|
2994
3417
|
logoUrl: "",
|
|
2995
3418
|
authors: ["powerhouse"],
|
|
2996
3419
|
auth: void 0,
|
|
2997
3420
|
categories: [PieceCategory.CORE],
|
|
2998
|
-
actions: [
|
|
3421
|
+
actions: [
|
|
3422
|
+
branchAction,
|
|
3423
|
+
assertAction,
|
|
3424
|
+
delayAction,
|
|
3425
|
+
approvalAction,
|
|
3426
|
+
stopAction,
|
|
3427
|
+
waitForWebhookAction
|
|
3428
|
+
],
|
|
2999
3429
|
triggers: [
|
|
3000
3430
|
scheduleTrigger,
|
|
3001
3431
|
webhookTrigger,
|
|
@@ -3050,10 +3480,56 @@ var UnknownBuiltinActionError = class extends Error {
|
|
|
3050
3480
|
this.name = "UnknownBuiltinActionError";
|
|
3051
3481
|
}
|
|
3052
3482
|
};
|
|
3053
|
-
|
|
3483
|
+
function resolvedCall(call, resumeBaseUrl) {
|
|
3484
|
+
const { responseToSend, ...rest } = call;
|
|
3485
|
+
if (typeof responseToSend !== "function") return responseToSend ? {
|
|
3486
|
+
...rest,
|
|
3487
|
+
responseToSend
|
|
3488
|
+
} : rest;
|
|
3489
|
+
if (!resumeBaseUrl) return rest;
|
|
3490
|
+
const token = randomBytes(32).toString("base64url");
|
|
3491
|
+
const url = `${resumeBaseUrl.replace(/\/+$/, "")}/${token}`;
|
|
3492
|
+
return {
|
|
3493
|
+
...rest,
|
|
3494
|
+
responseToSend: responseToSend(url),
|
|
3495
|
+
token
|
|
3496
|
+
};
|
|
3497
|
+
}
|
|
3498
|
+
async function runBuiltinAction(builtin, actionName, propsValue, options = {}) {
|
|
3054
3499
|
const action = getActions(builtin.piece)[actionName];
|
|
3055
3500
|
if (!action || typeof action.run !== "function") throw new UnknownBuiltinActionError(builtin.name, actionName);
|
|
3056
|
-
|
|
3501
|
+
let paused;
|
|
3502
|
+
let stopped;
|
|
3503
|
+
const { waitpoints, resume } = options;
|
|
3504
|
+
const context = {
|
|
3505
|
+
propsValue,
|
|
3506
|
+
executionType: resume ? "RESUME" : "BEGIN",
|
|
3507
|
+
...resume ? { resumePayload: resume.payload } : {},
|
|
3508
|
+
run: {
|
|
3509
|
+
canPause: waitpoints !== void 0,
|
|
3510
|
+
createWaitpoint: (call) => {
|
|
3511
|
+
if (!waitpoints) throw new CoreCannotPauseError(actionName);
|
|
3512
|
+
return waitpoints.create(resolvedCall(call, waitpoints.resumeBaseUrl));
|
|
3513
|
+
},
|
|
3514
|
+
waitForWaitpoint: (waitpointId) => {
|
|
3515
|
+
if (!waitpoints) throw new CoreCannotPauseError(actionName);
|
|
3516
|
+
paused = { waitpointId };
|
|
3517
|
+
},
|
|
3518
|
+
stop: (params) => {
|
|
3519
|
+
stopped = jsonSafe(params?.response ?? {}) ?? {};
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
};
|
|
3523
|
+
const output = await action.run(context);
|
|
3524
|
+
if (paused) return {
|
|
3525
|
+
output,
|
|
3526
|
+
paused
|
|
3527
|
+
};
|
|
3528
|
+
if (stopped) return {
|
|
3529
|
+
output,
|
|
3530
|
+
response: stopped,
|
|
3531
|
+
stopped: true
|
|
3532
|
+
};
|
|
3057
3533
|
return {
|
|
3058
3534
|
output,
|
|
3059
3535
|
...isPorted(action) ? { port: action.portOf(output) } : {}
|
|
@@ -3137,6 +3613,27 @@ function storeHandlers(port) {
|
|
|
3137
3613
|
};
|
|
3138
3614
|
}
|
|
3139
3615
|
const logger$1 = childLogger(["workflow", "piece-staging"]);
|
|
3616
|
+
function waitpointHandlers(port, execution, parsed, created) {
|
|
3617
|
+
return { [WAITPOINT_CREATE]: async (payload) => {
|
|
3618
|
+
const call = payload;
|
|
3619
|
+
const waitpoint = await port.create({
|
|
3620
|
+
...waitpointRequest(execution, parsed),
|
|
3621
|
+
type: call.type,
|
|
3622
|
+
...call.resumeDateTime !== void 0 ? { resumeDateTime: call.resumeDateTime } : {},
|
|
3623
|
+
...call.responseToSend !== void 0 ? { responseToSend: call.responseToSend } : {}
|
|
3624
|
+
});
|
|
3625
|
+
created.add(waitpoint.id);
|
|
3626
|
+
return waitpoint;
|
|
3627
|
+
} };
|
|
3628
|
+
}
|
|
3629
|
+
function waitpointRequest(execution, parsed) {
|
|
3630
|
+
return {
|
|
3631
|
+
stepId: execution.step.id,
|
|
3632
|
+
stepKey: execution.step.key,
|
|
3633
|
+
pieceName: parsed.packageName,
|
|
3634
|
+
blockName: parsed.name
|
|
3635
|
+
};
|
|
3636
|
+
}
|
|
3140
3637
|
function stepTaps(options, execution, values) {
|
|
3141
3638
|
const { onPieceLog, onPartialOutput } = options;
|
|
3142
3639
|
if (!onPieceLog && !onPartialOutput) return void 0;
|
|
@@ -3210,13 +3707,26 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3210
3707
|
try {
|
|
3211
3708
|
const builtin = builtinPiece(parsed.packageName);
|
|
3212
3709
|
return {
|
|
3213
|
-
...builtin ? await runBuiltinAction(builtin, parsed.name, execution.config) : await this.run(execution, parsed),
|
|
3710
|
+
...builtin ? await runBuiltinAction(builtin, parsed.name, execution.config, this.builtinOptions(execution, parsed)) : await this.run(execution, parsed),
|
|
3214
3711
|
resolution
|
|
3215
3712
|
};
|
|
3216
3713
|
} catch (error) {
|
|
3217
3714
|
throw withResolution(error, resolution);
|
|
3218
3715
|
}
|
|
3219
3716
|
}
|
|
3717
|
+
builtinOptions(execution, parsed) {
|
|
3718
|
+
const port = this.options.stepTest?.() ?? false ? void 0 : this.options.waitpoints?.();
|
|
3719
|
+
return {
|
|
3720
|
+
...port ? { waitpoints: {
|
|
3721
|
+
create: (call) => port.create({
|
|
3722
|
+
...waitpointRequest(execution, parsed),
|
|
3723
|
+
...call
|
|
3724
|
+
}),
|
|
3725
|
+
...port.resumeBaseUrl ? { resumeBaseUrl: port.resumeBaseUrl } : {}
|
|
3726
|
+
} } : {},
|
|
3727
|
+
...execution.resume ? { resume: execution.resume } : {}
|
|
3728
|
+
};
|
|
3729
|
+
}
|
|
3220
3730
|
async run(execution, parsed) {
|
|
3221
3731
|
const stagingDir = this.options.stagingRoot ? path.join(this.options.stagingRoot, randomUUID()) : void 0;
|
|
3222
3732
|
const runSecrets = execution.redactValues ?? [];
|
|
@@ -3245,6 +3755,15 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3245
3755
|
const pieceStore = this.options.pieceStore;
|
|
3246
3756
|
const notifications = stepTaps(this.options, execution, redactValues);
|
|
3247
3757
|
const egress = this.options.egress === void 0 ? DEFAULT_EGRESS_POLICY : this.options.egress;
|
|
3758
|
+
const uploads = this.uploadHandlers(stagingDir, signal);
|
|
3759
|
+
const stepTest = this.options.stepTest?.() ?? false;
|
|
3760
|
+
const waitpoints = stepTest ? void 0 : this.options.waitpoints?.();
|
|
3761
|
+
const created = /* @__PURE__ */ new Set();
|
|
3762
|
+
const hostCalls = pieceStore || uploads || waitpoints ? {
|
|
3763
|
+
...pieceStore ? storeHandlers(pieceStore) : {},
|
|
3764
|
+
...uploads,
|
|
3765
|
+
...waitpoints ? waitpointHandlers(waitpoints, execution, parsed, created) : {}
|
|
3766
|
+
} : void 0;
|
|
3248
3767
|
const reactorTap = await this.options.reactorAccess?.({
|
|
3249
3768
|
block: parsed,
|
|
3250
3769
|
reactorConnectionId: execution.reactorConnectionId
|
|
@@ -3259,8 +3778,15 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3259
3778
|
stepName: execution.step.key
|
|
3260
3779
|
},
|
|
3261
3780
|
...redactValues.length > 0 ? { redactValues } : {},
|
|
3262
|
-
...
|
|
3781
|
+
...stepTest ? { stepTest: true } : {},
|
|
3782
|
+
...waitpoints ? { canPause: true } : {},
|
|
3783
|
+
...waitpoints?.resumeBaseUrl ? { resumeBaseUrl: waitpoints.resumeBaseUrl } : {},
|
|
3784
|
+
...execution.resume ? {
|
|
3785
|
+
executionType: "RESUME",
|
|
3786
|
+
resumePayload: execution.resume.payload
|
|
3787
|
+
} : {},
|
|
3263
3788
|
...stagingDir ? { stagingDir } : {},
|
|
3789
|
+
...uploads ? { uploadFiles: true } : {},
|
|
3264
3790
|
...stagedInputs ? { stagedInputs } : {},
|
|
3265
3791
|
...pieceStore ? { durableStore: true } : {},
|
|
3266
3792
|
...this.options.onPieceLog ? { captureLogs: true } : {},
|
|
@@ -3269,13 +3795,31 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3269
3795
|
}, {
|
|
3270
3796
|
...remainingMs ? { timeoutMs: remainingMs } : {},
|
|
3271
3797
|
hostCallTimeoutMs: hostCallTimeoutForStep(timeoutMs),
|
|
3272
|
-
...
|
|
3798
|
+
...hostCalls ? { hostCalls } : {},
|
|
3273
3799
|
...notifications ? { notifications } : {},
|
|
3274
3800
|
...reactorTap ? { reactor: reactorTap } : {}
|
|
3275
3801
|
});
|
|
3802
|
+
const output = await this.ingestFiles(result.output, result.files, stagingDir, signal);
|
|
3803
|
+
const answer = {
|
|
3804
|
+
...result.response ? { response: result.response } : {},
|
|
3805
|
+
...result.stopped ? { stopped: true } : {}
|
|
3806
|
+
};
|
|
3807
|
+
if (!result.paused) return {
|
|
3808
|
+
output,
|
|
3809
|
+
redactValues,
|
|
3810
|
+
...answer
|
|
3811
|
+
};
|
|
3812
|
+
if (!waitpoints) throw new Error("The step paused a run that cannot pause");
|
|
3813
|
+
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`);
|
|
3814
|
+
const waitpointId = "waitpointId" in result.paused ? result.paused.waitpointId : (await waitpoints.create({
|
|
3815
|
+
...waitpointRequest(execution, parsed),
|
|
3816
|
+
...result.paused.pause,
|
|
3817
|
+
...result.paused.token ? { token: result.paused.token } : {}
|
|
3818
|
+
})).id;
|
|
3276
3819
|
return {
|
|
3277
|
-
output
|
|
3278
|
-
redactValues
|
|
3820
|
+
output,
|
|
3821
|
+
redactValues,
|
|
3822
|
+
paused: { waitpointId }
|
|
3279
3823
|
};
|
|
3280
3824
|
} catch (error) {
|
|
3281
3825
|
throw redactThrown(error, redactValues);
|
|
@@ -3341,6 +3885,20 @@ var ActivepiecesBlockExecutor = class {
|
|
|
3341
3885
|
});
|
|
3342
3886
|
return meta;
|
|
3343
3887
|
}
|
|
3888
|
+
uploadHandlers(stagingDir, signal) {
|
|
3889
|
+
const port = this.options.attachments;
|
|
3890
|
+
if (!stagingDir || !port) return void 0;
|
|
3891
|
+
return { [FILES_UPLOAD]: async (payload) => {
|
|
3892
|
+
const file = payload;
|
|
3893
|
+
const size = await this.checkStagedFile(file, stagingDir);
|
|
3894
|
+
return port.write({
|
|
3895
|
+
path: path.resolve(file.path),
|
|
3896
|
+
fileName: file.fileName,
|
|
3897
|
+
size,
|
|
3898
|
+
contentType: file.contentType
|
|
3899
|
+
}, signal);
|
|
3900
|
+
} };
|
|
3901
|
+
}
|
|
3344
3902
|
async checkStagedFile(file, stagingDir) {
|
|
3345
3903
|
if (!stagingDir) throw new Error(`Refusing to ingest "${file.fileName}": no staging directory`);
|
|
3346
3904
|
const root = await realpath(stagingDir);
|
|
@@ -3531,6 +4089,20 @@ function actionRetryPolicy(retry) {
|
|
|
3531
4089
|
...declared
|
|
3532
4090
|
});
|
|
3533
4091
|
}
|
|
4092
|
+
function lazyEntry(read) {
|
|
4093
|
+
let value;
|
|
4094
|
+
let done = false;
|
|
4095
|
+
return Object.defineProperty({}, "output", {
|
|
4096
|
+
enumerable: true,
|
|
4097
|
+
get: () => {
|
|
4098
|
+
if (!done) {
|
|
4099
|
+
value = read();
|
|
4100
|
+
done = true;
|
|
4101
|
+
}
|
|
4102
|
+
return value;
|
|
4103
|
+
}
|
|
4104
|
+
});
|
|
4105
|
+
}
|
|
3534
4106
|
function deadPortWarnings(definition, declaredPorts) {
|
|
3535
4107
|
const blocks = new Map(definition.steps.map((step) => [step.id, {
|
|
3536
4108
|
key: step.key,
|
|
@@ -3581,7 +4153,9 @@ async function runWorkflow(options) {
|
|
|
3581
4153
|
let runFailed;
|
|
3582
4154
|
let runCancelled;
|
|
3583
4155
|
let runFailedName;
|
|
3584
|
-
let
|
|
4156
|
+
let runWaiting;
|
|
4157
|
+
let runStopped = false;
|
|
4158
|
+
let executedCount = options.firstOrdinal ?? 0;
|
|
3585
4159
|
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => {
|
|
3586
4160
|
setTimeout(resolve, ms).unref();
|
|
3587
4161
|
}));
|
|
@@ -3658,7 +4232,27 @@ async function runWorkflow(options) {
|
|
|
3658
4232
|
scope.steps[step.key] = { output: null };
|
|
3659
4233
|
decideOutgoing(step.id, "next");
|
|
3660
4234
|
};
|
|
4235
|
+
const carryStep = (step, carried) => {
|
|
4236
|
+
const failed = carried.status === "FAILED";
|
|
4237
|
+
const port = carried.port ?? (failed ? "error" : "next");
|
|
4238
|
+
records.set(step.id, {
|
|
4239
|
+
stepId: step.id,
|
|
4240
|
+
key: step.key,
|
|
4241
|
+
pieceName: step.pieceName,
|
|
4242
|
+
blockName: step.actionName,
|
|
4243
|
+
status: carried.status,
|
|
4244
|
+
port,
|
|
4245
|
+
carried: true
|
|
4246
|
+
});
|
|
4247
|
+
scope.steps[step.key] = failed ? { error: carried.error ?? "" } : lazyEntry(carried.output);
|
|
4248
|
+
decideOutgoing(step.id, port);
|
|
4249
|
+
};
|
|
3661
4250
|
const executeStep = async (step) => {
|
|
4251
|
+
const carried = options.carriedSteps?.get(step.id);
|
|
4252
|
+
if (carried) {
|
|
4253
|
+
carryStep(step, carried);
|
|
4254
|
+
return;
|
|
4255
|
+
}
|
|
3662
4256
|
if (step.skip === true) {
|
|
3663
4257
|
await passStep(step);
|
|
3664
4258
|
return;
|
|
@@ -3696,8 +4290,9 @@ async function runWorkflow(options) {
|
|
|
3696
4290
|
const maxAttempts = retry?.maxAttempts ?? 1;
|
|
3697
4291
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3698
4292
|
let input;
|
|
4293
|
+
const resumedCore = options.resume?.stepId === step.id && step.pieceName === CORE_PIECE_NAME;
|
|
3699
4294
|
try {
|
|
3700
|
-
input = resolveStepInput(step, scope);
|
|
4295
|
+
input = resumedCore ? resolveResumedCoreInput(step, scope) : resolveStepInput(step, scope);
|
|
3701
4296
|
checkDynamicProperties(input, step.propertySettings);
|
|
3702
4297
|
} catch (error) {
|
|
3703
4298
|
await endStep(step, {
|
|
@@ -3718,10 +4313,34 @@ async function runWorkflow(options) {
|
|
|
3718
4313
|
reactorConnectionId: step.reactorConnectionId,
|
|
3719
4314
|
step,
|
|
3720
4315
|
...runSecrets.length > 0 ? { redactValues: runSecrets } : {},
|
|
3721
|
-
...defaultTimeout
|
|
4316
|
+
...defaultTimeout,
|
|
4317
|
+
...options.resume?.stepId === step.id ? { resume: { payload: options.resume.payload } } : {}
|
|
3722
4318
|
});
|
|
3723
4319
|
const port = result.port ?? "next";
|
|
3724
4320
|
const values = [...runSecrets, ...result.redactValues ?? []];
|
|
4321
|
+
if (result.response) options.onRespond?.(result.response);
|
|
4322
|
+
if (result.paused) {
|
|
4323
|
+
const record = {
|
|
4324
|
+
stepId: step.id,
|
|
4325
|
+
key: step.key,
|
|
4326
|
+
pieceName: step.pieceName,
|
|
4327
|
+
blockName: step.actionName,
|
|
4328
|
+
status: "WAITING",
|
|
4329
|
+
input: journaled(input, values),
|
|
4330
|
+
output: journaled(referenceDocuments(result.output), values),
|
|
4331
|
+
startedAt,
|
|
4332
|
+
...withPiece(pieceRecord(result.resolution)),
|
|
4333
|
+
configHash: stepConfigHash(step),
|
|
4334
|
+
...attempts
|
|
4335
|
+
};
|
|
4336
|
+
records.set(step.id, record);
|
|
4337
|
+
await journal(record);
|
|
4338
|
+
runWaiting = {
|
|
4339
|
+
stepId: step.id,
|
|
4340
|
+
waitpointId: result.paused.waitpointId
|
|
4341
|
+
};
|
|
4342
|
+
return;
|
|
4343
|
+
}
|
|
3725
4344
|
const record = {
|
|
3726
4345
|
stepId: step.id,
|
|
3727
4346
|
key: step.key,
|
|
@@ -3740,6 +4359,10 @@ async function runWorkflow(options) {
|
|
|
3740
4359
|
records.set(step.id, record);
|
|
3741
4360
|
await journal(record);
|
|
3742
4361
|
scope.steps[step.key] = { output: result.output };
|
|
4362
|
+
if (result.stopped) {
|
|
4363
|
+
runStopped = true;
|
|
4364
|
+
return;
|
|
4365
|
+
}
|
|
3743
4366
|
decideOutgoing(step.id, port);
|
|
3744
4367
|
return;
|
|
3745
4368
|
} catch (error) {
|
|
@@ -3845,8 +4468,9 @@ async function runWorkflow(options) {
|
|
|
3845
4468
|
runCancelled ??= outOfTime();
|
|
3846
4469
|
return runCancelled !== void 0;
|
|
3847
4470
|
};
|
|
4471
|
+
const stopped = () => Boolean(runFailed || runCancelled || runWaiting || runStopped);
|
|
3848
4472
|
let progressed = true;
|
|
3849
|
-
while (progressed && !
|
|
4473
|
+
while (progressed && !stopped()) {
|
|
3850
4474
|
progressed = false;
|
|
3851
4475
|
for (const step of definition.steps) {
|
|
3852
4476
|
if (records.has(step.id)) continue;
|
|
@@ -3855,7 +4479,7 @@ async function runWorkflow(options) {
|
|
|
3855
4479
|
if (expiredBeforeStep()) break;
|
|
3856
4480
|
await executeStep(step);
|
|
3857
4481
|
progressed = true;
|
|
3858
|
-
if (
|
|
4482
|
+
if (stopped()) break;
|
|
3859
4483
|
continue;
|
|
3860
4484
|
}
|
|
3861
4485
|
if (inbound.length === 0) continue;
|
|
@@ -3865,9 +4489,18 @@ async function runWorkflow(options) {
|
|
|
3865
4489
|
await executeStep(step);
|
|
3866
4490
|
} else skipStep(step);
|
|
3867
4491
|
progressed = true;
|
|
3868
|
-
if (
|
|
4492
|
+
if (stopped()) break;
|
|
3869
4493
|
}
|
|
3870
4494
|
}
|
|
4495
|
+
if (runWaiting && !runFailed && !runCancelled) {
|
|
4496
|
+
const warnings = options.declaredPorts ? deadPortWarnings(definition, options.declaredPorts) : [];
|
|
4497
|
+
return {
|
|
4498
|
+
status: "WAITING",
|
|
4499
|
+
steps: definition.steps.filter((step) => records.has(step.id)).map((step) => records.get(step.id)),
|
|
4500
|
+
waiting: runWaiting,
|
|
4501
|
+
...warnings.length > 0 ? { warnings } : {}
|
|
4502
|
+
};
|
|
4503
|
+
}
|
|
3871
4504
|
for (const step of definition.steps) if (!records.has(step.id)) skipStep(step);
|
|
3872
4505
|
const steps = definition.steps.map((step) => records.get(step.id));
|
|
3873
4506
|
const warnings = options.declaredPorts ? deadPortWarnings(definition, options.declaredPorts) : [];
|
|
@@ -3949,6 +4582,7 @@ var WorkflowTelemetry = class {
|
|
|
3949
4582
|
stepDuration;
|
|
3950
4583
|
phaseDuration;
|
|
3951
4584
|
dispatcherGauges;
|
|
4585
|
+
suspendedGauge;
|
|
3952
4586
|
poolGauges;
|
|
3953
4587
|
constructor(options = {}) {
|
|
3954
4588
|
this.tracer = options.tracer ?? trace.getTracer("@powerhousedao/reactor-workflow");
|
|
@@ -4078,6 +4712,18 @@ var WorkflowTelemetry = class {
|
|
|
4078
4712
|
this.meter.addBatchObservableCallback(callback, observables);
|
|
4079
4713
|
return () => this.meter.removeBatchObservableCallback(callback, observables);
|
|
4080
4714
|
}
|
|
4715
|
+
observeSuspended(count) {
|
|
4716
|
+
this.suspendedGauge ??= this.meter.createObservableGauge("workflow.runs.suspended", {
|
|
4717
|
+
description: "Runs suspended on a waitpoint",
|
|
4718
|
+
unit: "{run}"
|
|
4719
|
+
});
|
|
4720
|
+
const gauge = this.suspendedGauge;
|
|
4721
|
+
const callback = (result) => {
|
|
4722
|
+
result.observe(count());
|
|
4723
|
+
};
|
|
4724
|
+
gauge.addCallback(callback);
|
|
4725
|
+
return () => gauge.removeCallback(callback);
|
|
4726
|
+
}
|
|
4081
4727
|
createPoolGauges() {
|
|
4082
4728
|
const gauge = (name, description) => this.meter.createObservableGauge(name, {
|
|
4083
4729
|
description,
|
|
@@ -4219,6 +4865,6 @@ function tracedMethods(target, telemetry, prefix, parent, nested = []) {
|
|
|
4219
4865
|
} });
|
|
4220
4866
|
}
|
|
4221
4867
|
//#endregion
|
|
4222
|
-
export {
|
|
4868
|
+
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 };
|
|
4223
4869
|
|
|
4224
|
-
//# sourceMappingURL=telemetry-
|
|
4870
|
+
//# sourceMappingURL=telemetry-GZA1FLlY.js.map
|