@powerhousedao/reactor-workflow 6.2.3-dev.89 → 6.2.3-dev.91
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 +6 -3
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -15
- package/dist/index.js.map +1 -1
- package/dist/{telemetry-Dg51lywn.js → telemetry-BXcQDBa5.js} +2 -2
- package/dist/{telemetry-Dg51lywn.js.map → telemetry-BXcQDBa5.js.map} +1 -1
- package/dist/testing.js +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as PieceWorkerPool, A as builtinPiece, At as isIndeterminateError, B as shapeConnection, C as flowsHandlers, Ct as unsupportedAuth, D as blockLabel, Dt as npmRegistryBaseUrl, E as storeHandlers, F as AttachmentCache, G as SecretCreatorMismatchError, H as expressionsIn, I as BoundConnectionResolver, J as SecretOwnerMismatchError, K as SecretDeletedError, M as CORE_PIECE_NAME, N as CORE_PIECE_VERSION, O as unpinnedNote, Ot as pieceRegistrySource, P as loopItems, Q as triggerBlock, R as declaredConnectionIds, S as CompositeBlockExecutor, St as authMethodFor, T as resolvedBlock, U as unavailableValue, V as resolveStepInput, X as secretRefFromId, Y as parseSecretRef, Z as stepBlock, _ as stepConfigHash, _t as bundleResolver, a as PieceRegistry, at as redact, b as effectiveRetryPolicy, c as packagePieces, ct as secretsFor, d as runWorkflow, dt as parseAddress, et as PieceWorker, f as isLoopStep, ft as extractDedupeKey, g as hashOf, gt as HOST_ORIGIN, h as canonicalJson, ht as FLOWS_LIST, i as tracedSteps, it as containsRedactedMarker, j as describeBuiltinPiece, k as blockPorts, kt as setPieceRegistryUrl, lt as DEFAULT_EGRESS_POLICY, m as loopStructure, mt as maxFileBytes, n as WorkflowTelemetry, nt as PieceWorkerError, o as installedPiece, ot as redactMessage, p as loopConfigHash, pt as FileTooLargeError, q as SecretNotFoundError, r as tracedMethods, rt as PieceWorkerTimeoutError, s as installedPieces, st as rememberSecrets, t as TELEMETRY_SCOPE, tt as PieceWorkerDisposedError, u as errorNameOf, ut as isPrivateAddress, v as DynamicPropertiesError, vt as pieceModuleRef, w as isHostBound, wt as unsupportedTrigger, x as ActivepiecesBlockExecutor, xt as UnsupportedPieceFeatureError, y as checkDynamicProperties, yt as sourcedResolver, z as declaredReactorConnectionIds } from "./telemetry-
|
|
1
|
+
import { $ as PieceWorkerPool, A as builtinPiece, At as isIndeterminateError, B as shapeConnection, C as flowsHandlers, Ct as unsupportedAuth, D as blockLabel, Dt as npmRegistryBaseUrl, E as storeHandlers, F as AttachmentCache, G as SecretCreatorMismatchError, H as expressionsIn, I as BoundConnectionResolver, J as SecretOwnerMismatchError, K as SecretDeletedError, M as CORE_PIECE_NAME, N as CORE_PIECE_VERSION, O as unpinnedNote, Ot as pieceRegistrySource, P as loopItems, Q as triggerBlock, R as declaredConnectionIds, S as CompositeBlockExecutor, St as authMethodFor, T as resolvedBlock, U as unavailableValue, V as resolveStepInput, X as secretRefFromId, Y as parseSecretRef, Z as stepBlock, _ as stepConfigHash, _t as bundleResolver, a as PieceRegistry, at as redact, b as effectiveRetryPolicy, c as packagePieces, ct as secretsFor, d as runWorkflow, dt as parseAddress, et as PieceWorker, f as isLoopStep, ft as extractDedupeKey, g as hashOf, gt as HOST_ORIGIN, h as canonicalJson, ht as FLOWS_LIST, i as tracedSteps, it as containsRedactedMarker, j as describeBuiltinPiece, k as blockPorts, kt as setPieceRegistryUrl, lt as DEFAULT_EGRESS_POLICY, m as loopStructure, mt as maxFileBytes, n as WorkflowTelemetry, nt as PieceWorkerError, o as installedPiece, ot as redactMessage, p as loopConfigHash, pt as FileTooLargeError, q as SecretNotFoundError, r as tracedMethods, rt as PieceWorkerTimeoutError, s as installedPieces, st as rememberSecrets, t as TELEMETRY_SCOPE, tt as PieceWorkerDisposedError, u as errorNameOf, ut as isPrivateAddress, v as DynamicPropertiesError, vt as pieceModuleRef, w as isHostBound, wt as unsupportedTrigger, x as ActivepiecesBlockExecutor, xt as UnsupportedPieceFeatureError, y as checkDynamicProperties, yt as sourcedResolver, z as declaredReactorConnectionIds } from "./telemetry-BXcQDBa5.js";
|
|
2
2
|
import { DENIED_ACTION_INDEXES, ReactorAccessDeniedError, ReactorAccessDeniedError as ReactorAccessDeniedError$1, ReactorJobFailedError, ReactorJobPendingError as ReactorJobPendingError$1, WebhookHandshakeStrategy, assertActionsApplied } from "@powerhousedao/pieces-framework";
|
|
3
3
|
import { mkdirSync, openAsBlob, readFileSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { open, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
@@ -18,6 +18,7 @@ import http, { validateHeaderName, validateHeaderValue } from "node:http";
|
|
|
18
18
|
import https from "node:https";
|
|
19
19
|
import { actions as actions$1, reducer, utils } from "@powerhousedao/workflow/document-models/workflow";
|
|
20
20
|
import { Kind, parse } from "graphql";
|
|
21
|
+
import { resolvePhDir } from "@powerhousedao/shared/clis/ph-dir";
|
|
21
22
|
import { ReactorHostServer } from "@powerhousedao/reactor/rpc";
|
|
22
23
|
import { SpanStatusCode, context } from "@opentelemetry/api";
|
|
23
24
|
import { isFolderNode } from "@powerhousedao/shared/document-drive";
|
|
@@ -1533,9 +1534,23 @@ var BlockResolver = class {
|
|
|
1533
1534
|
//#endregion
|
|
1534
1535
|
//#region src/reactor/run-scope.ts
|
|
1535
1536
|
const storage = new AsyncLocalStorage();
|
|
1537
|
+
let scopesOpened = 0;
|
|
1538
|
+
let scopesCollected = 0;
|
|
1539
|
+
const collectedScopes = new FinalizationRegistry(() => {
|
|
1540
|
+
scopesCollected += 1;
|
|
1541
|
+
});
|
|
1536
1542
|
function withRunScope(scope, fn) {
|
|
1543
|
+
scopesOpened += 1;
|
|
1544
|
+
collectedScopes.register(scope, void 0);
|
|
1537
1545
|
return storage.run(scope, fn);
|
|
1538
1546
|
}
|
|
1547
|
+
function runScopeStats() {
|
|
1548
|
+
return {
|
|
1549
|
+
opened: scopesOpened,
|
|
1550
|
+
collected: scopesCollected,
|
|
1551
|
+
held: scopesOpened - scopesCollected
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1539
1554
|
function currentWorkflowId() {
|
|
1540
1555
|
return storage.getStore()?.workflowId;
|
|
1541
1556
|
}
|
|
@@ -1708,12 +1723,12 @@ function configuredEgress() {
|
|
|
1708
1723
|
pieceLogger.info(`Egress policy widened by ${EGRESS_ALLOW_ENV}: ${allowAddresses.join(", ")}`);
|
|
1709
1724
|
return { allowAddresses };
|
|
1710
1725
|
}
|
|
1711
|
-
let bundleCache = join(
|
|
1726
|
+
let bundleCache = join(resolvePhDir(), "ap-bundles");
|
|
1712
1727
|
function bundleCacheDir() {
|
|
1713
1728
|
return bundleCache;
|
|
1714
1729
|
}
|
|
1715
|
-
const ATTACHMENT_STAGING_DIR = join(
|
|
1716
|
-
const ATTACHMENT_CACHE_DIR = join(
|
|
1730
|
+
const ATTACHMENT_STAGING_DIR = join(resolvePhDir(), "ap-attachment-staging");
|
|
1731
|
+
const ATTACHMENT_CACHE_DIR = join(resolvePhDir(), "ap-attachment-cache");
|
|
1717
1732
|
const DEFAULT_ATTACHMENT_CACHE_BYTES = 1073741824;
|
|
1718
1733
|
function attachmentCacheBytes() {
|
|
1719
1734
|
const raw = process.env.PH_WORKFLOWS_ATTACHMENT_CACHE_BYTES;
|
|
@@ -2751,22 +2766,27 @@ var MasterKeyMismatchError = class extends Error {
|
|
|
2751
2766
|
this.name = "MasterKeyMismatchError";
|
|
2752
2767
|
}
|
|
2753
2768
|
};
|
|
2754
|
-
function
|
|
2755
|
-
const hex = options.masterKeyHex ?? process.env[MASTER_KEY_ENV];
|
|
2756
|
-
if (hex !== void 0) {
|
|
2757
|
-
if (!/^[0-9a-f]{64}$/i.test(hex)) throw new Error("Secrets master key must be 64 hex chars (32 bytes)");
|
|
2758
|
-
return Buffer.from(hex, "hex");
|
|
2759
|
-
}
|
|
2760
|
-
if (options.keyFile === false) throw new MasterKeyRequiredError();
|
|
2761
|
-
const file = options.keyFile ?? join(process.cwd(), ".ph", "secrets.key");
|
|
2769
|
+
function readKeyFile(file) {
|
|
2762
2770
|
try {
|
|
2763
2771
|
const key = Buffer.from(readFileSync(file, "utf8").trim(), "hex");
|
|
2764
2772
|
if (key.length !== KEY_BYTES) throw new Error(`Key file "${file}" is not 32 bytes of hex`);
|
|
2765
2773
|
return key;
|
|
2766
2774
|
} catch (error) {
|
|
2767
2775
|
if (error.code !== "ENOENT") throw error;
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
function loadKey(options) {
|
|
2780
|
+
const hex = options.masterKeyHex ?? process.env[MASTER_KEY_ENV];
|
|
2781
|
+
if (hex !== void 0) {
|
|
2782
|
+
if (!/^[0-9a-f]{64}$/i.test(hex)) throw new Error("Secrets master key must be 64 hex chars (32 bytes)");
|
|
2783
|
+
return Buffer.from(hex, "hex");
|
|
2768
2784
|
}
|
|
2769
|
-
|
|
2785
|
+
if (options.keyFile === false) throw new MasterKeyRequiredError();
|
|
2786
|
+
const file = options.keyFile ?? join(resolvePhDir(), "secrets.key");
|
|
2787
|
+
const kept = readKeyFile(file);
|
|
2788
|
+
if (kept) return kept;
|
|
2789
|
+
const key = (options.keyFile === void 0 ? readKeyFile(join(resolvePhDir(process.cwd(), {}), "secrets.key")) : void 0) ?? randomBytes(KEY_BYTES);
|
|
2770
2790
|
mkdirSync(dirname(file), { recursive: true });
|
|
2771
2791
|
writeFileSync(file, key.toString("hex") + "\n", { mode: 384 });
|
|
2772
2792
|
return key;
|
|
@@ -13710,9 +13730,11 @@ var WorkflowRuntimeService = class {
|
|
|
13710
13730
|
}
|
|
13711
13731
|
const unobservePool = this.telemetry.observeWorkerPool(() => pool.stats());
|
|
13712
13732
|
const unregisterGauge = registerTelemetryGauge("workflow.pool", () => pool.memoryStats());
|
|
13733
|
+
const unregisterRuns = registerTelemetryGauge("workflow.runs", runScopeStats);
|
|
13713
13734
|
this.unobservePool = () => {
|
|
13714
13735
|
unobservePool();
|
|
13715
13736
|
unregisterGauge();
|
|
13737
|
+
unregisterRuns();
|
|
13716
13738
|
};
|
|
13717
13739
|
return this.pieceWorkers = pool;
|
|
13718
13740
|
}
|
|
@@ -14073,7 +14095,7 @@ var WorkflowRuntimeService = class {
|
|
|
14073
14095
|
if (store && runId) {
|
|
14074
14096
|
let waiting = result.status === WAITING_RUN_STATUS;
|
|
14075
14097
|
try {
|
|
14076
|
-
const { held, closed } = await this.
|
|
14098
|
+
const { held, closed } = await this.journalFinish(store, runId, result, executionOrder, waiting ? leg.pin?.() : void 0);
|
|
14077
14099
|
this.answerClosed(closed, runId, {
|
|
14078
14100
|
status: waiting ? CANCELLED_RUN_STATUS : result.status,
|
|
14079
14101
|
error: waiting ? "The step that created this waitpoint no longer waits on it" : result.error ?? "The run ended without resuming on it"
|
|
@@ -14096,6 +14118,9 @@ var WorkflowRuntimeService = class {
|
|
|
14096
14118
|
handed
|
|
14097
14119
|
};
|
|
14098
14120
|
}
|
|
14121
|
+
journalFinish(store, runId, result, executionOrder, pin) {
|
|
14122
|
+
return this.telemetry.phase("journal.finish", {}, () => store.finishRun(runId, result, executionOrder, pin));
|
|
14123
|
+
}
|
|
14099
14124
|
async endUnheldWait(store, runId, result) {
|
|
14100
14125
|
const on = result.waiting;
|
|
14101
14126
|
const step = result.steps.find((record) => record.stepId === on?.stepId);
|
|
@@ -15777,7 +15802,7 @@ async function acquireWorkflowSingletonLease(options) {
|
|
|
15777
15802
|
instance,
|
|
15778
15803
|
acquired_at: dbNow(),
|
|
15779
15804
|
...stamps()
|
|
15780
|
-
}).where("id", "=", LEASE_ID).where((eb) => eb.or([eb("expires_at", "<=", dbNow()), eb.and([eb("owner", "=", owner), eb("heartbeat_at", "<=", dbNowPlus(-staleMs))])])).returning("owner").executeTakeFirst() !== void 0;
|
|
15805
|
+
}).where("id", "=", LEASE_ID).where((eb) => eb.or([eb("expires_at", "<=", dbNow()), eb.and([eb("owner", "=", owner), eb("heartbeat_at", "<=", dbNowPlus(options.exclusive ? 0 : -staleMs))])])).returning("owner").executeTakeFirst() !== void 0;
|
|
15781
15806
|
};
|
|
15782
15807
|
const claimSentAt = performance.now();
|
|
15783
15808
|
if (!await claim()) {
|