@powerhousedao/reactor-workflow 6.2.3-dev.18 → 6.2.3-dev.19

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { _ as FileTooLargeError, a as redactMessage, c as DEFAULT_EGRESS_POLICY, f as extractDedupeKey, n as containsRedactedMarker, o as rememberSecrets, r as redact, s as secretsFor, y as maxFileBytes } from "./redact-C7LWgAyD.js";
2
- import { C as pieceModuleRef, D as setPieceRegistryUrl, E as pieceRegistrySource, S as localFirstResolver, _ as secretRefFromId, a as CompositeBlockExecutor, b as PieceWorkerError, c as storeHandlers, d as declaredConnectionIds, f as shapeConnection, g as parseSecretRef, h as SecretNotFoundError, i as ActivepiecesBlockExecutor, l as BoundConnectionResolver, m as SecretDeletedError, n as packagePieces, o as parseBlockType, r as runWorkflow, s as reactorHandlers, t as PieceRegistry, v as PieceWorkerPool, w as ensurePieceBundle, x as PieceWorkerTimeoutError, y as PieceWorker } from "./piece-registry-CzYq4sK-.js";
2
+ import { C as pieceModuleRef, D as setPieceRegistryUrl, E as pieceRegistrySource, S as localFirstResolver, _ as secretRefFromId, a as CompositeBlockExecutor, b as PieceWorkerError, c as storeHandlers, d as declaredConnectionIds, f as shapeConnection, g as parseSecretRef, h as SecretNotFoundError, i as ActivepiecesBlockExecutor, l as BoundConnectionResolver, m as SecretDeletedError, n as packagePieces, o as parseBlockType, r as runWorkflow, s as reactorHandlers, t as PieceRegistry, v as PieceWorkerPool, w as ensurePieceBundle, x as PieceWorkerTimeoutError, y as PieceWorker } from "./piece-registry-WukyH-O-.js";
3
3
  import { WebhookHandshakeStrategy } from "@powerhousedao/pieces-framework";
4
4
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { open, readFile, rm } from "node:fs/promises";
@@ -1 +1 @@
1
- {"version":3,"file":"piece-registry-DWTQoft_.d.ts","names":[],"sources":["../src/pieces/activepieces/types.ts","../src/pieces/activepieces/fetch.ts","../src/pieces/activepieces/loader.ts","../src/pieces/activepieces/descriptor.ts","../src/pieces/activepieces/context/store-scope.ts","../src/pieces/activepieces/context/files.ts","../src/pieces/activepieces/context/action.ts","../src/pieces/activepieces/context/trigger.ts","../src/pieces/activepieces/worker/protocol.ts","../src/pieces/activepieces/resolver.ts","../src/pieces/activepieces/worker/transport.ts","../src/pieces/activepieces/worker/host.ts","../src/pieces/activepieces/worker/pool.ts","../src/pieces/engine/types.ts","../src/pieces/engine/secrets.ts","../src/pieces/engine/connections.ts","../src/pieces/engine/blocks.ts","../src/pieces/engine/coordinator.ts","../src/reactor/piece-registry.ts"],"mappings":";;;KAiBY,cAAA;AAAA,KAEA,gBAAA,GAAmB,IAAA,CAAK,cAAA;AAAA,KAGxB,qBAAA,GAAwB,IAAA,CAClC,aAAA;EAEI,OAAA,EAAS,gBAAA;AAAA;AAAA,KAIH,UAAA,GAAa,OAAA,CACvB,IAAA,CAAK,kBAAA,oDAEL,OAAA,CAAQ,IAAA,CAAK,gBAAA;EACX,IAAA,GAAO,cAAA;EACP,QAAA;EACA,YAAA;EACA,OAAA,GAAU,qBAAA,QAA6B,IAAA;EAEvC,KAAA,OAAY,IAAA;EAEZ,UAAA,GAAa,MAAA,SAAe,UAAA;AAAA;AAAA,KAIpB,QAAA,GAAW,OAAA,CACrB,IAAA,CAAK,UAAA;EAEL,KAAA,GAAQ,MAAA,SAAe,UAAA;EACvB,GAAA,GAAM,GAAA,cAAiB,OAAA;AAAA;AAAA,KAKb,iBAAA;AAAA,KAIA,wBAAA,GAA2B,OAAA,CACrC,IAAA,CAAK,6BAAA;EACD,QAAA;AAAA;AAAA,KAEM,SAAA,GAAY,OAAA,CACtB,IAAA,CACE,WAAA;EAIF,IAAA,GAAO,iBAAA;EAEP,YAAA;EACA,KAAA,GAAQ,MAAA,SAAe,UAAA;EACvB,sBAAA,GAAyB,wBAAA;EACzB,QAAA,IAAY,GAAA,cAAiB,OAAA;EAC7B,SA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BAgBQ,WAAA,CACpB,OAAA,EAAS,kBAAA,GACR,OAAA,CAAQ,iBAAA;;;cC1CE,aAAA;EAAA,QACH,MAAA;EAIR,SAAA,CAAU,MAAA,WAAiB,UAAA;EAkB3B,MAAA,GAAU,IAAA,aAAe,UAAA;EAEzB,OAAA,CAAA,GAAW,UAAA;EAMX,QAAA,CAAA,GAAY,MAAA;ElBvBY;EkB8BxB,KAAA,CAAA;AAAA;AAAA,cAMW,aAAA,EAAa,aAAA"}
1
+ {"version":3,"file":"piece-registry-DWTQoft_.d.ts","names":[],"sources":["../src/pieces/activepieces/types.ts","../src/pieces/activepieces/fetch.ts","../src/pieces/activepieces/loader.ts","../src/pieces/activepieces/descriptor.ts","../src/pieces/activepieces/context/store-scope.ts","../src/pieces/activepieces/context/files.ts","../src/pieces/activepieces/context/action.ts","../src/pieces/activepieces/context/trigger.ts","../src/pieces/activepieces/worker/protocol.ts","../src/pieces/activepieces/resolver.ts","../src/pieces/activepieces/worker/transport.ts","../src/pieces/activepieces/worker/host.ts","../src/pieces/activepieces/worker/pool.ts","../src/pieces/engine/types.ts","../src/pieces/engine/secrets.ts","../src/pieces/engine/connections.ts","../src/pieces/engine/blocks.ts","../src/pieces/engine/coordinator.ts","../src/reactor/piece-registry.ts"],"mappings":";;;KAiBY,cAAA;AAAA,KAEA,gBAAA,GAAmB,IAAA,CAAK,cAAA;AAAA,KAGxB,qBAAA,GAAwB,IAAA,CAClC,aAAA;EAEI,OAAA,EAAS,gBAAA;AAAA;AAAA,KAIH,UAAA,GAAa,OAAA,CACvB,IAAA,CAAK,kBAAA,oDAEL,OAAA,CAAQ,IAAA,CAAK,gBAAA;EACX,IAAA,GAAO,cAAA;EACP,QAAA;EACA,YAAA;EACA,OAAA,GAAU,qBAAA,QAA6B,IAAA;EAEvC,KAAA,OAAY,IAAA;EAEZ,UAAA,GAAa,MAAA,SAAe,UAAA;AAAA;AAAA,KAIpB,QAAA,GAAW,OAAA,CACrB,IAAA,CAAK,UAAA;EA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iBACA,QAAA;EAAA,iBAJF,IAAA;cAGE,MAAA,EAAQ,aAAA,EACR,QAAA,GAAU,MAAA,SAAe,aAAA;EAG5C,OAAA,CAAQ,SAAA,EAAW,cAAA,GAAiB,OAAA,CAAQ,WAAA;AAAA;;;UC3rB7B,kBAAA;EACf,UAAA,EAAY,kBAAA;EACZ,QAAA,EAAU,aAAA;EAEV,cAAA;EAGA,cAAA,GAAiB,GAAA;IAAc,MAAA;IAAkB,IAAA;EAAA;EAIjD,MAAA,IACE,MAAA,EAAQ,mBAAA,EACR,OAAA,oBACU,OAAA;AAAA;AAAA,iBAgBQ,WAAA,CACpB,OAAA,EAAS,kBAAA,GACR,OAAA,CAAQ,iBAAA;;;cC1CE,aAAA;EAAA,QACH,MAAA;EAIR,SAAA,CAAU,MAAA,WAAiB,UAAA;EAkB3B,MAAA,GAAU,IAAA,aAAe,UAAA;EAEzB,OAAA,CAAA,GAAW,UAAA;EAMX,QAAA,CAAA,GAAY,MAAA;ElBvBY;EkB8BxB,KAAA,CAAA;AAAA;AAAA,cAMW,aAAA,EAAa,aAAA"}
@@ -10,7 +10,7 @@ import { fileURLToPath } from "node:url";
10
10
  import { randomUUID } from "node:crypto";
11
11
  import { fork } from "node:child_process";
12
12
  //#region src/pieces/activepieces/registry-source.ts
13
- const logger$1 = childLogger(["workflow", "piece-registry"]);
13
+ const logger$2 = childLogger(["workflow", "piece-registry"]);
14
14
  function source(baseUrl) {
15
15
  return {
16
16
  baseUrl,
@@ -28,7 +28,7 @@ function setPieceRegistryUrl(url) {
28
28
  }
29
29
  if (configured?.baseUrl === trimmed) return;
30
30
  configured = source(trimmed);
31
- logger$1.info(`Pieces may be fetched from ${configured.baseUrl}`);
31
+ logger$2.info(`Pieces may be fetched from ${configured.baseUrl}`);
32
32
  }
33
33
  function pieceRegistrySource() {
34
34
  return configured;
@@ -953,6 +953,7 @@ function storeHandlers(port) {
953
953
  }
954
954
  };
955
955
  }
956
+ const logger$1 = childLogger(["workflow", "piece-staging"]);
956
957
  function stepTaps(options, execution, values) {
957
958
  const { onPieceLog, onPartialOutput } = options;
958
959
  if (!onPieceLog && !onPartialOutput) return void 0;
@@ -1097,12 +1098,16 @@ var ActivepiecesBlockExecutor = class {
1097
1098
  let index = 0;
1098
1099
  for (const ref of refs) {
1099
1100
  const destPath = path.join(stagingDir, `in-${index++}`);
1100
- const meta = await port.read(ref, destPath);
1101
- staged.push({
1102
- ref,
1103
- path: destPath,
1104
- ...meta
1105
- });
1101
+ try {
1102
+ const meta = await port.read(ref, destPath);
1103
+ staged.push({
1104
+ ref,
1105
+ path: destPath,
1106
+ ...meta
1107
+ });
1108
+ } catch (error) {
1109
+ logger$1.debug(`Left ${ref} unstaged: ${error instanceof Error ? error.message : String(error)}`);
1110
+ }
1106
1111
  }
1107
1112
  return staged;
1108
1113
  }
@@ -1315,4 +1320,4 @@ const packagePieces = new PieceRegistry();
1315
1320
  //#endregion
1316
1321
  export { pieceModuleRef as C, setPieceRegistryUrl as D, pieceRegistrySource as E, localFirstResolver as S, fetchPieceBundle as T, secretRefFromId as _, CompositeBlockExecutor as a, PieceWorkerError as b, storeHandlers as c, declaredConnectionIds as d, shapeConnection as f, parseSecretRef as g, SecretNotFoundError as h, ActivepiecesBlockExecutor as i, BoundConnectionResolver as l, SecretDeletedError as m, packagePieces as n, parseBlockType as o, InMemorySecretProvider as p, runWorkflow as r, reactorHandlers as s, PieceRegistry as t, StaticConnectionResolver as u, PieceWorkerPool as v, ensurePieceBundle as w, PieceWorkerTimeoutError as x, PieceWorker as y };
1317
1322
 
1318
- //# sourceMappingURL=piece-registry-CzYq4sK-.js.map
1323
+ //# sourceMappingURL=piece-registry-WukyH-O-.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"piece-registry-WukyH-O-.js","names":["logger","gunzip","gunzipCb","logger"],"sources":["../src/pieces/activepieces/registry-source.ts","../src/pieces/activepieces/fetch.ts","../src/pieces/activepieces/resolver.ts","../src/pieces/activepieces/worker/transport.ts","../src/pieces/activepieces/worker/host.ts","../src/pieces/activepieces/worker/pool.ts","../src/pieces/engine/secrets.ts","../src/pieces/engine/expressions.ts","../src/pieces/engine/connections.ts","../src/pieces/engine/blocks.ts","../src/pieces/engine/coordinator.ts","../src/reactor/piece-registry.ts"],"sourcesContent":["// A Powerhouse registry as a source of pieces: where this runtime reads piece\n// metadata and fetches piece code.\n\n// It serves the same three shapes cloud.activepieces.com and its CDN do — a\n// list, one piece's detail, a bundle tarball — so only the base URL differs.\n\n// The registry is the one the host already installs packages from. A package\n// installed from it ships pieces that run in the worker with the same reach, so\n// a bundle fetched from it is no more trusted than one that arrived inside a\n// package; the trust boundary is the registry, and it is already drawn.\nimport { childLogger } from \"document-model\";\n\nconst logger = childLogger([\"workflow\", \"piece-registry\"]);\n\nexport interface PieceRegistrySource {\n /** Origin the piece endpoints hang off, without a trailing slash. */\n baseUrl: string;\n /** The catalog, in cloud.activepieces.com's list shape. */\n catalogUrl(suggestions?: boolean): string;\n /** One piece's detail, in the shape their piece endpoint answers with. */\n pieceUrl(name: string): string;\n /** The bundle, under the filename their CDN would serve it as. */\n tarballUrl(name: string, version: string): string;\n}\n\nfunction source(baseUrl: string): PieceRegistrySource {\n return {\n baseUrl,\n catalogUrl: (suggestions) =>\n suggestions\n ? `${baseUrl}/pieces?suggestionType=ACTION_AND_TRIGGER`\n : `${baseUrl}/pieces`,\n // Encoded whole, slash included: a scoped name is one path segment to the\n // registry's route, not two.\n pieceUrl: (name) => `${baseUrl}/pieces/${encodeURIComponent(name)}`,\n tarballUrl: (name, version) =>\n `${baseUrl}/-/pieces/bundled/${name.replace(\"/\", \"-\")}-${version}.tgz`,\n };\n}\n\n// Set by the host at composition from the registry it resolved for package\n// installs; absent on a host that installs no packages from one, and nothing\n// changes.\nlet configured: PieceRegistrySource | undefined;\n\nexport function setPieceRegistryUrl(url: string | undefined): void {\n const trimmed = url?.trim().replace(/\\/+$/, \"\") ?? \"\";\n if (trimmed === \"\") {\n configured = undefined;\n return;\n }\n if (configured?.baseUrl === trimmed) return;\n configured = source(trimmed);\n logger.info(`Pieces may be fetched from ${configured.baseUrl}`);\n}\n\nexport function pieceRegistrySource(): PieceRegistrySource | undefined {\n return configured;\n}\n","import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { gunzip as gunzipCb } from \"node:zlib\";\nimport { pieceRegistrySource } from \"./registry-source.js\";\n\nconst gunzip = promisify(gunzipCb);\n\n// Mirrors their pieceBundle.resolve(): CDN bundle when served, else the npm\n// tarball. Tarballs are immutable per (name, version), so the cache never expires.\nconst CDN_PIECES_URL = \"https://cdn.activepieces.com/pieces/bundled/\";\nconst NPM_REGISTRY_URL = \"https://registry.npmjs.org\";\n\nexport function cdnTarballUrl(name: string, version: string): string {\n return `${CDN_PIECES_URL}${name.replace(\"/\", \"-\")}-${version}.tgz`;\n}\n\nexport function npmTarballUrl(name: string, version: string): string {\n const unscoped = name.startsWith(\"@\") ? name.split(\"/\")[1] : name;\n return `${NPM_REGISTRY_URL}/${name}/-/${unscoped}-${version}.tgz`;\n}\n\n// name/version come from a workflow step's blockType, an unconstrained string.\nconst NPM_NAME_RE = /^(@[a-z0-9][a-z0-9-_.]*\\/)?[a-z0-9][a-z0-9-_.]*$/;\nconst NPM_VERSION_RE = /^[A-Za-z0-9][A-Za-z0-9.+-]*$/;\n\nfunction assertValidPackageCoordinate(name: string, version: string): void {\n if (!NPM_NAME_RE.test(name)) {\n throw new Error(`Invalid piece package name: ${name}`);\n }\n if (!NPM_VERSION_RE.test(version)) {\n throw new Error(`Invalid piece package version: ${version}`);\n }\n}\n\n// Belt-and-suspenders: the path we're about to rm/rename must land under cacheDir.\nfunction assertWithinCacheDir(dir: string, cacheDir: string): void {\n const root = path.resolve(cacheDir);\n const resolved = path.resolve(dir);\n if (resolved !== root && !resolved.startsWith(root + path.sep)) {\n throw new Error(`Resolved piece cache path escapes cacheDir: ${dir}`);\n }\n}\n\nfunction readString(header: Buffer, offset: number, length: number): string {\n const slice = header.subarray(offset, offset + length);\n const nul = slice.indexOf(0);\n return slice.subarray(0, nul === -1 ? length : nul).toString(\"utf8\");\n}\n\n// Published piece bundles run a few hundred KB extracted; the cap is well clear\n// of that and bounds what a hostile or corrupt tarball can inflate to.\nconst MAX_EXTRACTED_BYTES = 64 * 1024 * 1024;\n\n// Caps the compressed transfer itself, before gunzip ever runs — the decompressed\n// cap above does nothing for a huge (not necessarily bomb-like) response body.\nconst MAX_COMPRESSED_BYTES = 64 * 1024 * 1024;\n\n// Minimal ustar extraction: regular files only, \"package/\" root stripped.\nasync function extractTarball(tgz: Buffer, dest: string): Promise<void> {\n // Async gunzip: the sync one blocks the reactor's event loop for every\n // request, not just this one, and inflation is unbounded without maxOutputLength.\n const tar = await gunzip(tgz, { maxOutputLength: MAX_EXTRACTED_BYTES }).catch(\n (error: unknown) => {\n throw new Error(`Failed to decompress piece bundle: ${String(error)}`);\n },\n );\n let offset = 0;\n while (offset + 512 <= tar.length) {\n const header = tar.subarray(offset, offset + 512);\n if (header.every((byte) => byte === 0)) break;\n const name = readString(header, 0, 100);\n const prefix = readString(header, 345, 155);\n const size = parseInt(readString(header, 124, 12).trim() || \"0\", 8);\n const type = String.fromCharCode(header[156]);\n offset += 512;\n const isFile = type === \"0\" || type === \"\\0\" || type === \"\";\n if (isFile && size >= 0) {\n const full = prefix ? `${prefix}/${name}` : name;\n const rel = full.replace(/^[^/]+\\//, \"\");\n const target = path.resolve(dest, rel);\n // Guard against path traversal from a hostile tarball.\n if (rel && target.startsWith(path.resolve(dest) + path.sep)) {\n await mkdir(path.dirname(target), { recursive: true });\n await writeFile(target, tar.subarray(offset, offset + size));\n }\n }\n offset += Math.ceil(size / 512) * 512;\n }\n}\n\nexport interface FetchPieceBundleOptions {\n name: string;\n version: string;\n cacheDir: string;\n timeoutMs?: number;\n}\n\n/** Where a bundle came from, \"cache\" being a copy one of the others left. */\nexport type BundleSource = \"registry\" | \"cdn\" | \"npm\";\n\nexport interface FetchedBundle {\n dir: string;\n source: BundleSource | \"cache\";\n}\n\n// Bounds the transfer before gunzip: rejects an over-limit Content-Length up\n// front, else tracks a running total as the body streams in.\nasync function readBoundedBody(\n response: Response,\n url: string,\n): Promise<Buffer> {\n const declared = response.headers.get(\"content-length\");\n if (declared && Number(declared) > MAX_COMPRESSED_BYTES) {\n throw new Error(\n `${url} exceeds the ${MAX_COMPRESSED_BYTES}-byte compressed size cap (Content-Length: ${declared})`,\n );\n }\n if (!response.body) return Buffer.from(await response.arrayBuffer());\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let total = 0;\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n total += value.byteLength;\n if (total > MAX_COMPRESSED_BYTES) {\n await reader.cancel();\n throw new Error(\n `${url} exceeds the ${MAX_COMPRESSED_BYTES}-byte compressed size cap`,\n );\n }\n chunks.push(value);\n }\n return Buffer.concat(chunks);\n}\n\n// A Powerhouse registry this deployment allowed comes first, so a piece it\n// serves is not shadowed by an Activepieces piece of the same name.\nfunction tarballSources(\n name: string,\n version: string,\n): { source: BundleSource; url: string }[] {\n const registry = pieceRegistrySource();\n return [\n ...(registry\n ? [\n {\n source: \"registry\" as const,\n url: registry.tarballUrl(name, version),\n },\n ]\n : []),\n { source: \"cdn\" as const, url: cdnTarballUrl(name, version) },\n { source: \"npm\" as const, url: npmTarballUrl(name, version) },\n ];\n}\n\nasync function downloadTarball(\n name: string,\n version: string,\n timeoutMs: number,\n): Promise<{ tgz: Buffer; source: BundleSource }> {\n const sources = tarballSources(name, version);\n let lastError: unknown;\n for (const { source, url } of sources) {\n try {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(timeoutMs),\n });\n if (!response.ok) {\n lastError = new Error(`${url} responded ${response.status}`);\n continue;\n }\n return { tgz: await readBoundedBody(response, url), source };\n } catch (error) {\n lastError = error;\n }\n }\n throw new Error(\n `Failed to fetch piece bundle ${name}@${version}: ${String(lastError)}`,\n );\n}\n\n// Downloads and extracts a published piece bundle, returning the directory to\n// hand to loadPieceFromDir(). A cached extraction is reused, and re-checked.\nexport async function fetchPieceBundle(\n options: FetchPieceBundleOptions,\n): Promise<FetchedBundle> {\n const { name, version, cacheDir, timeoutMs = 30_000 } = options;\n assertValidPackageCoordinate(name, version);\n const dir = path.join(cacheDir, `${name.replace(\"/\", \"-\")}-${version}`);\n assertWithinCacheDir(dir, cacheDir);\n if (existsSync(path.join(dir, \"package.json\"))) {\n await assertSelfContained(dir, name, version);\n return { dir, source: \"cache\" };\n }\n\n const { tgz, source } = await downloadTarball(name, version, timeoutMs);\n const staging = `${dir}.tmp-${process.pid}`;\n await rm(staging, { recursive: true, force: true });\n await extractTarball(tgz, staging);\n await rm(dir, { recursive: true, force: true });\n try {\n await rename(staging, dir);\n } catch (error) {\n // Concurrent fetcher won the rename; its extraction is identical.\n await rm(staging, { recursive: true, force: true });\n if (!existsSync(path.join(dir, \"package.json\"))) throw error;\n }\n // Checked here rather than before the rename so a bundle an older build\n // already extracted is refused on its cache hit too, not only a fresh one.\n await assertSelfContained(dir, name, version);\n return { dir, source };\n}\n\n// Concurrent callers for the same bundle share one download+extract rather\n// than racing each other through it.\nconst inFlight = new Map<string, Promise<FetchedBundle>>();\n\n// The way in: a bundle arrives extracted, cached and checked, and callers that\n// ask for the same one at the same time wait on a single fetch.\nexport async function ensurePieceBundle(\n options: FetchPieceBundleOptions,\n): Promise<FetchedBundle> {\n const key = `${options.cacheDir}\\u0000${options.name}@${options.version}`;\n const pending = inFlight.get(key);\n if (pending) return pending;\n // Dropped once settled, refusals included, so a later caller re-checks the\n // bundle rather than inheriting this call's answer forever.\n const started = fetchPieceBundle(options).finally(() => inFlight.delete(key));\n inFlight.set(key, started);\n return started;\n}\n\n// The Activepieces release that began inlining a piece's dependencies into its\n// bundle. They still publish pieces to npm, which is why npm stays a source.\nconst AP_SELF_CONTAINED_SINCE = \"0.86.0\";\n\n// Enough to recognise what the bundle wants without turning the refusal into\n// a wall of text.\nconst MAX_LISTED_DEPENDENCIES = 5;\n\n// A bundle has to carry its own code: the worker imports it straight out of the\n// cache directory, where there is no node_modules and nothing to install one.\nasync function assertSelfContained(\n dir: string,\n name: string,\n version: string,\n): Promise<void> {\n const dependencies = await readDependencies(dir);\n const declared = Object.keys(dependencies);\n if (declared.length === 0) return;\n const listed = declared\n .slice(0, MAX_LISTED_DEPENDENCIES)\n .map((dep) => `${dep}@${dependencies[dep]}`);\n const rest = declared.length - listed.length;\n const count =\n declared.length === 1 ? \"a dependency\" : `${declared.length} dependencies`;\n // Only an Activepieces piece gets their release number: a bundle from\n // anywhere else would be sent chasing a version that means nothing to it.\n const since = name.startsWith(\"@activepieces/\")\n ? ` Activepieces bundles have been self-contained since ${AP_SELF_CONTAINED_SINCE}.`\n : \"\";\n throw new Error(\n `Piece bundle ${name}@${version} is not self-contained: it declares ${count} ` +\n `(${listed.join(\", \")}${rest > 0 ? `, and ${rest} more` : \"\"}). ` +\n `The reactor no longer installs a bundle's dependencies. Pin ${name} at or above ` +\n `its first self-contained release.${since}`,\n );\n}\n\nasync function readDependencies(dir: string): Promise<Record<string, string>> {\n const raw = await readFile(path.join(dir, \"package.json\"), \"utf8\");\n const pkg = JSON.parse(raw) as { dependencies?: Record<string, string> };\n return pkg.dependencies ?? {};\n}\n","// Where a piece's code comes from. Two sources, one seam.\n\n// A published piece is a bundle fetched from a registry and cached on disk; a\n// first-party piece ships inside an installed reactor package and is already\n// on disk, with no version to fetch and no cache to warm.\nimport { ensurePieceBundle } from \"./fetch.js\";\nimport type { PieceModuleRef } from \"./worker/protocol.js\";\n\nexport interface ResolvedPiece extends PieceModuleRef {\n name: string;\n version: string;\n // True when the piece is code the operator installed rather than a bundle\n // fetched from a registry. Only these are offered host capabilities.\n local: boolean;\n}\n\nexport interface PieceResolver {\n resolve(name: string, version: string): Promise<ResolvedPiece>;\n}\n\n// A piece found in an installed reactor package: a module file, or a directory\n// in npm-bundle shape when the package ships one already bundled.\nexport interface LocalPiece {\n name: string;\n version: string;\n entryPath?: string;\n bundleDir?: string;\n}\n\n// May answer asynchronously: a host whose registry loads on first use waits\n// here rather than racing every caller to have loaded it first.\nexport type LocalPieceLookup = (\n name: string,\n) => LocalPiece | undefined | Promise<LocalPiece | undefined>;\n\n// One entry of a reactor package's `pieces` export: which piece it ships and\n// where the built bundle sits, relative to the package root.\nexport type { PackagePiece } from \"@powerhousedao/pieces-framework\";\n\n// The published path: fetch (or reuse) the bundle for an exact version.\nexport function bundleResolver(options: {\n cacheDir: string;\n timeoutMs?: number;\n}): PieceResolver {\n return {\n async resolve(name: string, version: string): Promise<ResolvedPiece> {\n const bundle = await ensurePieceBundle({\n name,\n version,\n cacheDir: options.cacheDir,\n ...(options.timeoutMs ? { timeoutMs: options.timeoutMs } : {}),\n });\n return { name, version, bundleDir: bundle.dir, local: false };\n },\n };\n}\n\n// An installed package wins over the registry for its own name, whatever\n// version the block type asked for: the installed copy is the one this reactor\n// runs, and a fetched bundle of the same name would shadow it silently.\nexport function localFirstResolver(\n lookup: LocalPieceLookup,\n fallback: PieceResolver,\n): PieceResolver {\n return {\n async resolve(name: string, version: string): Promise<ResolvedPiece> {\n const local = await lookup(name);\n if (!local) return fallback.resolve(name, version);\n return {\n name,\n version: local.version,\n ...(local.entryPath ? { entryPath: local.entryPath } : {}),\n ...(local.bundleDir ? { bundleDir: local.bundleDir } : {}),\n local: true,\n };\n },\n };\n}\n\n// What a request hands the worker, from whichever source answered.\nexport function pieceModuleRef(piece: ResolvedPiece): PieceModuleRef {\n return piece.entryPath\n ? { entryPath: piece.entryPath }\n : { bundleDir: piece.bundleDir };\n}\n","// What PieceWorker needs from a connection to a worker, and nothing else.\n\n// Written against this rather than a ChildProcess so a later transport — a\n// pooled fork, a socket to another machine — slots in underneath unchanged.\nimport { fork, type ChildProcess } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport interface TransportExit {\n code: number | null;\n signal: NodeJS.Signals | null;\n}\n\nexport type TransportEventMap = {\n message: unknown;\n exit: TransportExit;\n};\n\nexport type TransportEvent = keyof TransportEventMap;\n\nexport type TransportListener<E extends TransportEvent> = (\n payload: TransportEventMap[E],\n) => void;\n\n// One worker's connection. An implementation must deliver `message` payloads\n// faithfully enough for the protocol above, and emit `exit` exactly once.\n\n// \"Faithfully enough\" means JSON-shaped, deliberately: the fork's structured\n// clone would carry a Date or a Map, but nothing may depend on that, because\n// no other carrier could honour it.\n\n// PieceWorker flattens what it sends and the child flattens what it answers,\n// so this is a contract a socket could meet too — a transport is not required\n// to preserve anything JSON would lose.\nexport interface IPieceWorkerTransport {\n send(message: unknown): void;\n on<E extends TransportEvent>(event: E, listener: TransportListener<E>): void;\n off<E extends TransportEvent>(event: E, listener: TransportListener<E>): void;\n // Ends the worker now; it takes any pending host calls with it.\n kill(): void;\n // False once the worker cannot receive: a send after this is dropped.\n readonly connected: boolean;\n}\n\n// Builds a fresh connection. Called on first use and again after a worker is\n// killed, so a factory must be able to produce more than one.\nexport type PieceWorkerTransportFactory = () => IPieceWorkerTransport;\n\nexport function defaultEntryPath(): string {\n let dir = path.dirname(fileURLToPath(import.meta.url));\n while (!existsSync(path.join(dir, \"package.json\"))) {\n const parent = path.dirname(dir);\n if (parent === dir) throw new Error(\"Could not locate package root\");\n dir = parent;\n }\n const entry = path.join(dir, \"dist\", \"worker-entry.js\");\n if (!existsSync(entry)) {\n throw new Error(`Worker entry not built at ${entry} — run pnpm build`);\n }\n return entry;\n}\n\n// A forked node child on this machine, over its IPC channel.\nexport function createForkTransport(entryPath: string): IPieceWorkerTransport {\n const child: ChildProcess = fork(entryPath, [], {\n // Empty env: the child gets no host secrets and no inherited TLS overrides.\n env: {},\n execArgv: [],\n // Structured clone rather than JSON, so a Buffer in a payload survives.\n serialization: \"advanced\",\n // Piece stdout/stderr are dropped for now; log capture arrives with journaling.\n stdio: [\"ignore\", \"ignore\", \"ignore\", \"ipc\"],\n });\n\n // Node reports exit as two positional arguments; the interface carries one\n // payload, so the adaptation lives here rather than in every listener.\n const exitListeners = new Map<\n TransportListener<\"exit\">,\n (code: number | null, signal: NodeJS.Signals | null) => void\n >();\n\n return {\n get connected() {\n return child.connected;\n },\n send(message) {\n child.send(message as never);\n },\n on(event, listener) {\n if (event === \"exit\") {\n const adapted = (code: number | null, signal: NodeJS.Signals | null) =>\n (listener as TransportListener<\"exit\">)({ code, signal });\n exitListeners.set(listener as TransportListener<\"exit\">, adapted);\n child.on(\"exit\", adapted);\n return;\n }\n child.on(\"message\", listener as (value: unknown) => void);\n },\n off(event, listener) {\n if (event === \"exit\") {\n const adapted = exitListeners.get(\n listener as TransportListener<\"exit\">,\n );\n if (adapted) {\n child.off(\"exit\", adapted);\n exitListeners.delete(listener as TransportListener<\"exit\">);\n }\n return;\n }\n child.off(\"message\", listener as (value: unknown) => void);\n },\n kill() {\n child.kill(\"SIGKILL\");\n },\n };\n}\n","import type { StagedFile } from \"../context/files.js\";\nimport type { RecordedListener, RecordedSchedule } from \"../context/trigger.js\";\nimport { jsonSafe } from \"./json-safe.js\";\nimport {\n createForkTransport,\n defaultEntryPath,\n type IPieceWorkerTransport,\n type PieceWorkerTransportFactory,\n type TransportExit,\n} from \"./transport.js\";\nimport type {\n CheckConnectionRequest,\n DescribePieceRequest,\n HostCallHandlers,\n HostCallMessage,\n HostCallResponse,\n HostNotifyHandlers,\n HostNotifyMessage,\n ResolveOptionsRequest,\n RunActionRequest,\n SerializedPieceError,\n TriggerHookRequest,\n WorkerResponse,\n} from \"./protocol.js\";\n\ntype WorkerRequestType =\n | \"run\"\n | \"resolve-options\"\n | \"trigger-hook\"\n | \"check-connection\"\n | \"describe\";\n\ntype WorkerRequest =\n | RunActionRequest\n | ResolveOptionsRequest\n | TriggerHookRequest\n | CheckConnectionRequest\n | DescribePieceRequest;\n\nexport class PieceWorkerError extends Error {\n readonly serialized: SerializedPieceError;\n\n constructor(serialized: SerializedPieceError) {\n super(`${serialized.name}: ${serialized.message}`);\n this.name = \"PieceWorkerError\";\n this.serialized = serialized;\n }\n}\n\nexport class PieceWorkerTimeoutError extends Error {\n constructor(timeoutMs: number) {\n super(`Piece action timed out after ${timeoutMs}ms; worker was replaced`);\n this.name = \"PieceWorkerTimeoutError\";\n }\n}\n\nexport class PieceWorkerExitError extends Error {\n constructor(code: number | null, signal: string | null) {\n super(`Piece worker exited unexpectedly (code=${code}, signal=${signal})`);\n this.name = \"PieceWorkerExitError\";\n }\n}\n\nexport interface PieceWorkerResult {\n output: unknown;\n touched: string[];\n tlsPoisoned: boolean;\n // run only: files the piece wrote through ctx.files, staged on disk for the\n // host to ingest before the output is journalled.\n files?: StagedFile[];\n // trigger-hook only: final store contents plus captured context calls.\n storeState?: Record<string, unknown>;\n schedules?: RecordedSchedule[];\n listeners?: RecordedListener[];\n}\n\n// Handlers the host offers for the duration of one request: calls it answers,\n// and one-way reports it receives.\nexport interface RequestTaps {\n hostCalls?: HostCallHandlers;\n notifications?: HostNotifyHandlers;\n}\n\n// Every request that can serve a piece takes the same shape: a deadline plus\n// the taps the host offers while it runs.\nexport interface RequestOptions extends RequestTaps {\n timeoutMs?: number;\n}\n\n/** @deprecated Named for the one request that had it; every request takes it\n * now. Kept because the old name is on main, in this package's public types. */\nexport type RunActionOptions = RequestOptions;\n\ntype ChildMessage = WorkerResponse | HostCallMessage | HostNotifyMessage;\n\n// A tap reports on the step; it never decides its outcome. Node delivers these\n// before the result, so no draining step is needed at teardown.\nfunction serveNotify(\n message: HostNotifyMessage,\n handlers: HostNotifyHandlers | undefined,\n): void {\n const handler = handlers?.[message.method];\n if (!handler) return;\n try {\n // Declared void, but TypeScript admits an async function here, and its\n // rejection would take the host down rather than the tap.\n void Promise.resolve(handler(message.payload)).catch(() => undefined);\n } catch {\n // A broken tap is not the step's problem.\n }\n}\n\nexport interface PieceWorkerOptions {\n // Absolute path to the compiled worker entry; defaults to dist/worker-entry.js.\n entryPath?: string;\n defaultTimeoutMs?: number;\n // How to reach a worker. Defaults to a forked child on this machine; a\n // remote transport replaces it without touching the protocol above.\n transport?: PieceWorkerTransportFactory;\n}\n\n// The five requests a worker serves, plus teardown. Callers hold this rather\n// than PieceWorker itself, so a child that outlives every request and a child\n// that lives for one run are interchangeable to them.\nexport interface IPieceWorker {\n runAction(\n request: RunActionRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult>;\n resolveOptions(\n request: ResolveOptionsRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult>;\n checkConnection(\n request: CheckConnectionRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult>;\n describePiece(\n request: DescribePieceRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult>;\n runTriggerHook(\n request: TriggerHookRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult>;\n // Ends the worker. A caller that was handed one it does not own must not\n // call this; PieceWorkerPool disposes the workers it hands out.\n dispose(): void;\n}\n\n// Executes piece actions in a child process. Side-effects (TLS env poisoning,\n// crashes) stay in the child; a timed-out or crashed worker is replaced.\nexport class PieceWorker implements IPieceWorker {\n private readonly connect: PieceWorkerTransportFactory;\n private readonly defaultTimeoutMs: number;\n private worker: IPieceWorkerTransport | undefined;\n private queue: Promise<unknown> = Promise.resolve();\n private nextId = 1;\n\n constructor(options: PieceWorkerOptions = {}) {\n const entryPath = options.entryPath;\n this.connect =\n options.transport ??\n (() => createForkTransport(entryPath ?? defaultEntryPath()));\n this.defaultTimeoutMs = options.defaultTimeoutMs ?? 30_000;\n }\n\n // Requests are serialized per worker; concurrency comes from holding more\n // than one, which is what PieceWorkerPool does.\n runAction(\n request: RunActionRequest,\n options: RequestOptions = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"run\", request, options.timeoutMs, options);\n }\n\n // Design-time DROPDOWN options() / DYNAMIC props() resolution. It takes the\n // same taps a run does: a package piece's resolver may read the reactor.\n resolveOptions(\n request: ResolveOptionsRequest,\n options: RequestOptions = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"resolve-options\", request, options.timeoutMs, options);\n }\n\n // A piece's app.checkConnection over resolved credentials; the output is a\n // CheckConnectionOutcome.\n checkConnection(\n request: CheckConnectionRequest,\n options: { timeoutMs?: number } = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"check-connection\", request, options.timeoutMs);\n }\n\n // The piece's design-time descriptor; the output is a PieceDescriptor.\n describePiece(\n request: DescribePieceRequest,\n options: { timeoutMs?: number } = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"describe\", request, options.timeoutMs);\n }\n\n // One trigger lifecycle hook. It takes the same taps a run does, so a\n // `durableStore` hook reaches the host's store while it is still running.\n runTriggerHook(\n request: TriggerHookRequest,\n options: RequestOptions = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"trigger-hook\", request, options.timeoutMs, options);\n }\n\n private enqueue(\n type: WorkerRequestType,\n request: WorkerRequest,\n timeoutMs?: number,\n taps: RequestTaps = {},\n ): Promise<PieceWorkerResult> {\n const run = this.queue.then(() =>\n this.execute(type, request, timeoutMs ?? this.defaultTimeoutMs, taps),\n );\n this.queue = run.catch(() => undefined);\n return run;\n }\n\n dispose(): void {\n this.worker?.kill();\n this.worker = undefined;\n }\n\n private spawn(): IPieceWorkerTransport {\n if (this.worker) return this.worker;\n const worker = this.connect();\n const forget = () => {\n if (this.worker === worker) this.worker = undefined;\n worker.off(\"exit\", forget);\n };\n worker.on(\"exit\", forget);\n this.worker = worker;\n return worker;\n }\n\n private execute(\n type: WorkerRequestType,\n request: WorkerRequest,\n timeoutMs: number,\n taps: RequestTaps,\n ): Promise<PieceWorkerResult> {\n const worker = this.spawn();\n const id = this.nextId++;\n\n return new Promise<PieceWorkerResult>((resolve, reject) => {\n const timer = setTimeout(() => {\n cleanup();\n worker.kill();\n this.worker = undefined;\n reject(new PieceWorkerTimeoutError(timeoutMs));\n }, timeoutMs);\n\n const onMessage = (value: unknown) => {\n const response = value as ChildMessage;\n // Ids come from two counters; dispatch on type before comparing them.\n if (response.type === \"host-call\" || response.type === \"host-notify\") {\n return;\n }\n if (response.id !== id) return;\n cleanup();\n if (response.type === \"result\") {\n resolve({\n output: response.output,\n touched: response.touched,\n tlsPoisoned: response.tlsPoisoned,\n files: response.files,\n storeState: response.storeState,\n schedules: response.schedules,\n listeners: response.listeners,\n });\n } else {\n reject(new PieceWorkerError(response.error));\n }\n };\n\n const onExit = ({ code, signal }: TransportExit) => {\n cleanup();\n reject(new PieceWorkerExitError(code, signal));\n };\n\n // Served outside the request queue: the queue is held by this very\n // request, so routing a call through it would deadlock the step.\n const onHostCall = (value: unknown) => {\n const message = value as ChildMessage;\n if (message.type === \"host-call\") {\n void this.serveHostCall(worker, message, taps.hostCalls);\n return;\n }\n if (message.type === \"host-notify\") {\n serveNotify(message, taps.notifications);\n }\n };\n\n const cleanup = () => {\n clearTimeout(timer);\n worker.off(\"message\", onMessage);\n worker.off(\"message\", onHostCall);\n worker.off(\"exit\", onExit);\n };\n\n worker.on(\"message\", onMessage);\n worker.on(\"message\", onHostCall);\n worker.on(\"exit\", onExit);\n // Flattened here rather than per caller: config, auth and connection\n // values are piece-authored, and the contract is JSON-shaped both ways.\n worker.send(jsonSafe({ id, type, request }));\n });\n }\n\n // Answers one call from the child. The handler set belongs to the request in\n // flight, so a call arriving after the step returned is refused, not served.\n private async serveHostCall(\n worker: IPieceWorkerTransport,\n message: HostCallMessage,\n handlers: HostCallHandlers | undefined,\n ): Promise<void> {\n let response: HostCallResponse;\n try {\n const handler = handlers?.[message.method];\n if (!handler) {\n throw new Error(`No host handler for \"${message.method}\"`);\n }\n response = {\n id: message.id,\n type: \"host-result\",\n value: await handler(message.payload),\n };\n } catch (error) {\n response = {\n id: message.id,\n type: \"host-result\",\n error: error instanceof Error ? error.message : String(error),\n };\n }\n // A worker killed on timeout takes its pending calls with it.\n if (worker.connected) worker.send(response);\n }\n}\n","// A bounded set of piece workers, handed out one per run (doc 08 §7, doc 03 §5).\n\n// PieceWorker serializes its requests, so one shared worker makes every\n// connector step on the server wait for every other.\n\n// The pool answers both halves of that: N sessions run at once, and each holds\n// a child of its own, killed when the session closes.\n\n// So a run starts on a clean heap, waits only on itself, and takes nothing\n// with it when it ends.\nimport {\n PieceWorker,\n type IPieceWorker,\n type PieceWorkerOptions,\n type PieceWorkerResult,\n type RequestOptions,\n} from \"./host.js\";\nimport type {\n CheckConnectionRequest,\n DescribePieceRequest,\n ResolveOptionsRequest,\n RunActionRequest,\n TriggerHookRequest,\n} from \"./protocol.js\";\n\n// Thrown when a session asks for a slot the pool will not queue.\n\n// The pool queues without limit unless an operator caps it, so this only\n// appears where someone chose failing fast over waiting.\nexport class PieceWorkerPoolBusyError extends Error {\n constructor(size: number, waiting: number) {\n super(\n `All ${size} piece workers are busy and ${waiting} runs are already waiting`,\n );\n this.name = \"PieceWorkerPoolBusyError\";\n }\n}\n\nexport class PieceWorkerSessionClosedError extends Error {\n constructor() {\n super(\"This piece worker session is closed\");\n this.name = \"PieceWorkerSessionClosedError\";\n }\n}\n\nexport interface PieceWorkerPoolOptions extends PieceWorkerOptions {\n // How many sessions may hold a worker at once. Each one is a child process,\n // so this is the server's real connector concurrency.\n size?: number;\n // How many sessions may wait for a slot. 0 is unbounded, which is what the\n // single shared worker effectively did: latency rather than failure.\n maxQueueDepth?: number;\n // Builds one worker. Defaults to a forked child; a test or a remote\n // deployment substitutes its own.\n createWorker?: (options: PieceWorkerOptions) => IPieceWorker;\n}\n\nconst DEFAULT_SIZE = 4;\n\ninterface Waiter {\n session: PieceWorkerSession;\n resolve: () => void;\n reject: (error: unknown) => void;\n}\n\n// One run's claim on a worker. Lazy on purpose: a run whose steps are all\n// document or core blocks never takes a slot and never forks a child.\nexport class PieceWorkerSession implements IPieceWorker {\n private worker: IPieceWorker | undefined;\n private taking: Promise<IPieceWorker> | undefined;\n private held = false;\n private closed = false;\n\n constructor(private readonly pool: PieceWorkerPool) {}\n\n runAction(\n request: RunActionRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.runAction(request, options));\n }\n\n resolveOptions(\n request: ResolveOptionsRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.resolveOptions(request, options));\n }\n\n checkConnection(\n request: CheckConnectionRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.checkConnection(request, options));\n }\n\n describePiece(\n request: DescribePieceRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.describePiece(request, options));\n }\n\n runTriggerHook(\n request: TriggerHookRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.runTriggerHook(request, options));\n }\n\n // Kills this session's child and frees its slot for whoever is waiting.\n\n // Idempotent: a caller closing in a `finally` must not have to care whether\n // the run failed before it ever reached a piece step.\n close(): void {\n if (this.closed) return;\n this.closed = true;\n // Still queueing: the request fails now rather than when a slot happens\n // to free, which for a saturated pool may be never.\n this.pool.cancel(this);\n this.worker?.dispose();\n this.worker = undefined;\n this.pool.forget(this);\n this.giveBack();\n }\n\n // IPieceWorker's teardown is this session's close: a caller holding one\n // through the interface ends the run's child, not the pool.\n dispose(): void {\n this.close();\n }\n\n private async request<T>(fn: (worker: IPieceWorker) => Promise<T>) {\n const worker = await this.take();\n // Closed while this was waiting — a shutdown landing mid-run.\n\n // Its worker is already killed, and PieceWorker forks a replacement on the\n // next request, so dispatching now would leak a child the pool never sees.\n if (this.closed) throw new PieceWorkerSessionClosedError();\n return fn(worker);\n }\n\n private take(): Promise<IPieceWorker> {\n if (this.closed) {\n return Promise.reject(new PieceWorkerSessionClosedError());\n }\n if (this.worker) return Promise.resolve(this.worker);\n // Memoized: two steps entering at once must not take two slots, even\n // though the coordinator runs a run's steps one after another.\n this.taking ??= this.acquire();\n return this.taking;\n }\n\n private async acquire(): Promise<IPieceWorker> {\n await this.pool.acquire(this);\n this.held = true;\n // Closed while queueing: hand the slot straight back rather than fork a\n // child for a run that is already over.\n if (this.closed) {\n this.giveBack();\n throw new PieceWorkerSessionClosedError();\n }\n this.worker = this.pool.build();\n return this.worker;\n }\n\n private giveBack(): void {\n if (!this.held) return;\n this.held = false;\n this.pool.release();\n }\n}\n\n// Sized once at construction. Sessions queue for a slot in the order they ask\n// for one, so a burst of runs is served first-come rather than at random.\nexport class PieceWorkerPool {\n readonly size: number;\n private readonly maxQueueDepth: number;\n private readonly createWorker: (options: PieceWorkerOptions) => IPieceWorker;\n private readonly workerOptions: PieceWorkerOptions;\n private readonly sessions = new Set<PieceWorkerSession>();\n private readonly waiters: Waiter[] = [];\n private inUse = 0;\n private disposed = false;\n\n constructor(options: PieceWorkerPoolOptions = {}) {\n const { size, maxQueueDepth, createWorker, ...workerOptions } = options;\n this.size = Math.max(1, Math.trunc(size ?? DEFAULT_SIZE));\n this.maxQueueDepth = Math.max(0, Math.trunc(maxQueueDepth ?? 0));\n this.createWorker = createWorker ?? ((o) => new PieceWorker(o));\n this.workerOptions = workerOptions;\n }\n\n // A run's claim on a worker, for the length of the run. Free until its\n // first piece step, so opening one per run costs nothing.\n session(): PieceWorkerSession {\n if (this.disposed) throw new Error(\"Piece worker pool is disposed\");\n const session = new PieceWorkerSession(this);\n this.sessions.add(session);\n return session;\n }\n\n // Sessions holding a worker, and sessions waiting for one. The wait is what\n // a queue-depth alarm watches: it is invisible in a run's own timings.\n stats(): { size: number; active: number; waiting: number } {\n return {\n size: this.size,\n active: this.inUse,\n waiting: this.waiters.length,\n };\n }\n\n // Closes every session — killing the children mid-run — and refuses the ones\n // still queueing. For shutdown; a live run does not survive it.\n dispose(): void {\n this.disposed = true;\n // Queued sessions hear why before the closing below turns their wait into\n // the more ordinary \"your session closed\".\n for (const waiter of this.waiters.splice(0)) {\n waiter.reject(new Error(\"Piece worker pool is disposed\"));\n }\n for (const session of [...this.sessions]) session.close();\n this.sessions.clear();\n }\n\n /** @internal — a session taking its slot. */\n acquire(session: PieceWorkerSession): Promise<void> {\n if (this.disposed) {\n return Promise.reject(new Error(\"Piece worker pool is disposed\"));\n }\n if (this.inUse < this.size) {\n this.inUse++;\n return Promise.resolve();\n }\n if (this.maxQueueDepth > 0 && this.waiters.length >= this.maxQueueDepth) {\n return Promise.reject(\n new PieceWorkerPoolBusyError(this.size, this.waiters.length),\n );\n }\n return new Promise<void>((resolve, reject) => {\n this.waiters.push({ session, resolve, reject });\n });\n }\n\n /** @internal — a session that closed while queueing. */\n cancel(session: PieceWorkerSession): void {\n const index = this.waiters.findIndex((w) => w.session === session);\n if (index < 0) return;\n const [waiter] = this.waiters.splice(index, 1);\n waiter.reject(new PieceWorkerSessionClosedError());\n }\n\n /** @internal — a session giving its slot back. */\n release(): void {\n const next = this.waiters.shift();\n // Handed straight on rather than counted down and up again, so a slot\n // freed with someone waiting cannot be taken by a later arrival.\n if (next) {\n next.resolve();\n return;\n }\n this.inUse = Math.max(0, this.inUse - 1);\n }\n\n /** @internal — one child for one session. */\n build(): IPieceWorker {\n return this.createWorker(this.workerOptions);\n }\n\n /** @internal — a session that closed itself. */\n forget(session: PieceWorkerSession): void {\n this.sessions.delete(session);\n }\n}\n","// Secret references and the provider/store seams. Refs are server-minted\n// random ids — stable handles over mutable values, never content hashes.\n\nexport const SECRET_REF_PREFIX = \"secret://v1:\";\n\nconst SECRET_ID_PATTERN = /^[0-9a-f]{32}$/;\n\n// Read seam consumed by the engine (connection resolution).\nexport interface SecretProvider {\n get(ref: string): Promise<string>;\n}\n\nexport interface SecretStat {\n ref: string;\n label: string | null;\n version: number;\n status: \"ACTIVE\" | \"DELETED\";\n createdAt: string;\n updatedAt: string;\n}\n\n// Full lifecycle, implemented by managed backends. `get` is execution-context\n// only and must never be exposed over a transport.\nexport interface SecretStore extends SecretProvider {\n create(input: { value: string; label?: string }): Promise<SecretStat>;\n rotate(ref: string, value: string): Promise<SecretStat>;\n stat(ref: string): Promise<SecretStat>;\n list(): Promise<SecretStat[]>;\n delete(ref: string): Promise<void>;\n}\n\nexport class SecretNotFoundError extends Error {\n constructor(ref: string) {\n super(`No secret found for ref \"${ref}\"`);\n this.name = \"SecretNotFoundError\";\n }\n}\n\nexport class SecretDeletedError extends Error {\n constructor(ref: string) {\n super(`Secret \"${ref}\" has been deleted`);\n this.name = \"SecretDeletedError\";\n }\n}\n\nexport class InvalidSecretRefError extends Error {\n constructor(ref: string) {\n super(\n `Invalid secret ref \"${ref}\"; expected ${SECRET_REF_PREFIX}<32 hex chars>`,\n );\n this.name = \"InvalidSecretRefError\";\n }\n}\n\nexport function isSecretRef(ref: string): boolean {\n return (\n ref.startsWith(SECRET_REF_PREFIX) &&\n SECRET_ID_PATTERN.test(ref.slice(SECRET_REF_PREFIX.length))\n );\n}\n\n// Returns the 32-hex id; throws on anything else.\nexport function parseSecretRef(ref: string): string {\n if (!isSecretRef(ref)) throw new InvalidSecretRefError(ref);\n return ref.slice(SECRET_REF_PREFIX.length);\n}\n\nexport function secretRefFromId(id: string): string {\n if (!SECRET_ID_PATTERN.test(id)) throw new InvalidSecretRefError(id);\n return `${SECRET_REF_PREFIX}${id}`;\n}\n\nexport class InMemorySecretProvider implements SecretProvider {\n private readonly secrets: Map<string, string>;\n\n constructor(secrets: Record<string, string>) {\n this.secrets = new Map(Object.entries(secrets));\n }\n\n get(ref: string): Promise<string> {\n const value = this.secrets.get(ref);\n if (value === undefined)\n return Promise.reject(new SecretNotFoundError(ref));\n return Promise.resolve(value);\n }\n}\n","// Minimal {{path}} expression resolution over the run scope (doc 08 §4.6).\n// A whole-string expression yields the raw value; embedded ones interpolate.\n\nexport interface ExpressionScope {\n trigger?: unknown;\n steps: Record<string, { output: unknown }>;\n variables: Record<string, unknown>;\n}\n\nconst WHOLE_EXPRESSION = /^\\{\\{\\s*([^{}]+?)\\s*\\}\\}$/;\nconst EMBEDDED_EXPRESSION = /\\{\\{\\s*([^{}]+?)\\s*\\}\\}/g;\n\nexport function lookupPath(scope: ExpressionScope, path: string): unknown {\n let current: unknown = scope;\n for (const segment of path.split(\".\")) {\n if (current === null || typeof current !== \"object\") return undefined;\n current = (current as Record<string, unknown>)[segment];\n }\n return current;\n}\n\nconst STRING_LITERAL = /^(['\"])(.*)\\1$/;\n\n// \"a.b || c.d || 'default'\": first term that isn't undefined/null/\"\" wins.\nexport function resolveExpression(\n scope: ExpressionScope,\n expression: string,\n): unknown {\n for (const term of expression.split(\"||\")) {\n const trimmed = term.trim();\n if (!trimmed) continue;\n const literal = STRING_LITERAL.exec(trimmed);\n const value = literal ? literal[2] : lookupPath(scope, trimmed);\n if (value !== undefined && value !== null && value !== \"\") return value;\n }\n return undefined;\n}\n\nfunction interpolate(value: unknown): string {\n if (value === undefined || value === null) return \"\";\n if (typeof value === \"object\") return JSON.stringify(value);\n return String(value as string | number | boolean);\n}\n\nexport function resolveExpressions(\n value: unknown,\n scope: ExpressionScope,\n): unknown {\n if (typeof value === \"string\") {\n const whole = WHOLE_EXPRESSION.exec(value);\n if (whole) return resolveExpression(scope, whole[1]);\n return value.replaceAll(EMBEDDED_EXPRESSION, (_, path: string) =>\n interpolate(resolveExpression(scope, path)),\n );\n }\n if (Array.isArray(value)) {\n return value.map((item) => resolveExpressions(item, scope));\n }\n if (value !== null && typeof value === \"object\") {\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).map(([key, entry]) => [\n key,\n resolveExpressions(entry, scope),\n ]),\n );\n }\n return value;\n}\n\n// Truthiness of a resolved condition; the strings \"false\" and \"0\" are falsy.\nexport function evaluateCondition(\n condition: string,\n scope: ExpressionScope,\n): boolean {\n const resolved = resolveExpressions(condition, scope);\n if (resolved === \"false\" || resolved === \"0\") return false;\n return Boolean(resolved);\n}\n","// Resolves connection references into the auth value a piece reads from\n// ctx.auth, shaped per Activepieces auth kind (powerhouse/connection state).\n\nimport type { SecretProvider } from \"./secrets.js\";\nimport type { WorkflowDefinition } from \"./types.js\";\nimport {\n AppConnectionType,\n type AppConnectionValue,\n type BasicAuthConnectionValue,\n} from \"@powerhousedao/pieces-framework\";\n\n// The powerhouse/connection document model's own enum: the framework's\n// AppConnectionType, minus its OAuth2 variants, with NO_AUTH persisted as NONE.\nexport type ConnectionAuthType =\n | `${AppConnectionType.SECRET_TEXT}`\n | `${AppConnectionType.BASIC_AUTH}`\n | `${AppConnectionType.CUSTOM_AUTH}`\n | `${AppConnectionType.OAUTH2}`\n | `${AppConnectionType.OIDC}`\n | \"NONE\";\n\n// Mirrors the powerhouse/connection document state the resolver consumes.\nexport interface ConnectionSource {\n authType: ConnectionAuthType;\n config?: Record<string, unknown>;\n secretRefs?: { name: string; ref: string }[];\n}\n\n// Which step is asking. A resolver needs it to check the request against the\n// run's binding rather than trust the id it was handed.\n\n// piecePackage is the package the caller already resolved the block type to,\n// so a resolver never re-parses a block type to learn which piece is asking.\nexport interface ConnectionRequest {\n blockType: string;\n piecePackage?: string;\n stepId?: string;\n stepKey?: string;\n}\n\n// The auth a piece reads, plus the concrete secret strings behind it. The\n// second half is what value-based journal redaction matches on.\nexport interface ResolvedConnection {\n auth: unknown;\n secretValues: string[];\n}\n\nexport interface EngineConnectionResolver {\n resolve(connectionId: string, request?: ConnectionRequest): Promise<unknown>;\n // Optional: hosts that predate redaction keep working without it. It takes\n // the same request, so authorization is not skipped to get the secrets.\n resolveWithSecrets?(\n connectionId: string,\n request?: ConnectionRequest,\n ): Promise<ResolvedConnection>;\n}\n\nexport class ConnectionNotFoundError extends Error {\n constructor(connectionId: string) {\n super(`No connection registered for id \"${connectionId}\"`);\n this.name = \"ConnectionNotFoundError\";\n }\n}\n\n// A step reached for a connection its workflow definition never declared.\n// Raised before any lookup, so it cannot say whether the id exists.\nexport class ConnectionNotBoundError extends Error {\n constructor(connectionId: string) {\n super(`Connection \"${connectionId}\" is not bound to this workflow`);\n this.name = \"ConnectionNotBoundError\";\n }\n}\n\nexport class UnsupportedAuthTypeError extends Error {\n constructor(authType: string) {\n super(`Auth type \"${authType}\" is not supported yet`);\n this.name = \"UnsupportedAuthTypeError\";\n }\n}\n\nasync function resolveSecrets(\n source: ConnectionSource,\n secrets: SecretProvider,\n): Promise<Record<string, string>> {\n const entries = await Promise.all(\n (source.secretRefs ?? []).map(\n async ({ name, ref }) => [name, await secrets.get(ref)] as const,\n ),\n );\n return Object.fromEntries(entries);\n}\n\n// Values are AppConnectionValue-shaped: pieces read auth.secret_text,\n// auth.username/password or auth.props.* depending on their auth kind.\nexport async function shapeAuthValue(\n source: ConnectionSource,\n secrets: SecretProvider,\n): Promise<unknown> {\n return (await shapeConnection(source, secrets)).auth;\n}\n\n// Only the values behind `secretRefs` are reported as secret: config fields\n// (a base URL, a username) are not, and redacting them would cost debuggability.\nexport async function shapeConnection(\n source: ConnectionSource,\n secrets: SecretProvider,\n): Promise<ResolvedConnection> {\n const resolved = await resolveSecrets(source, secrets);\n return {\n auth: shapeAuth(source, resolved),\n secretValues: Object.values(resolved),\n };\n}\n\n// NONE is the persisted value; the framework's NO_AUTH case carries no value a\n// piece reads, so ctx.auth stays undefined rather than becoming that shape.\nfunction shapeAuth(\n source: ConnectionSource,\n resolved: Record<string, string>,\n): AppConnectionValue | undefined {\n switch (source.authType) {\n case \"NONE\":\n return undefined;\n case \"SECRET_TEXT\": {\n const values = Object.values(resolved);\n if (values.length !== 1) {\n throw new Error(\n `SECRET_TEXT connection must have exactly one secret ref, got ${values.length}`,\n );\n }\n return { type: AppConnectionType.SECRET_TEXT, secret_text: values[0] };\n }\n case \"BASIC_AUTH\": {\n const props = { ...source.config, ...resolved };\n return {\n type: AppConnectionType.BASIC_AUTH,\n username: props.username,\n password: props.password,\n } as BasicAuthConnectionValue;\n }\n case \"CUSTOM_AUTH\": {\n return {\n type: AppConnectionType.CUSTOM_AUTH,\n props: { ...source.config, ...resolved },\n };\n }\n default:\n throw new UnsupportedAuthTypeError(source.authType);\n }\n}\n\nexport class StaticConnectionResolver implements EngineConnectionResolver {\n private readonly connections: Map<string, ConnectionSource>;\n\n constructor(\n connections: Record<string, ConnectionSource>,\n private readonly secrets: SecretProvider,\n ) {\n this.connections = new Map(Object.entries(connections));\n }\n\n resolve(connectionId: string): Promise<unknown> {\n return this.resolveWithSecrets(connectionId).then(\n (resolved) => resolved.auth,\n );\n }\n\n resolveWithSecrets(connectionId: string): Promise<ResolvedConnection> {\n const source = this.connections.get(connectionId);\n if (!source) {\n return Promise.reject(new ConnectionNotFoundError(connectionId));\n }\n return shapeConnection(source, this.secrets);\n }\n}\n\n// Every connection a definition declares: the trigger's and each step's.\n\n// A templated id is left out — connectionId is never expression-resolved, so\n// it names no connection and a step cannot pick credentials at run time.\nexport function declaredConnectionIds(\n definition: WorkflowDefinition,\n): ReadonlySet<string> {\n const declared = new Set<string>();\n const declare = (connectionId: string | null | undefined) => {\n if (connectionId && !connectionId.includes(\"{{\"))\n declared.add(connectionId);\n };\n declare(definition.trigger?.connectionId);\n for (const step of definition.steps) declare(step.connectionId);\n return declared;\n}\n\n// The binding in force for the caller, or undefined when there is none. Read\n// per call because one executor serves every concurrent run.\nexport type ConnectionBindingLookup = () => ReadonlySet<string> | undefined;\n\n// Server-side connection binding (doc 08 §10): a step resolves only what the\n// definition its run pinned declared.\n\n// Without a binding nothing resolves, so a path that fails to establish one\n// fails closed.\nexport class BoundConnectionResolver implements EngineConnectionResolver {\n // Present only when the inner resolver has it, because its absence is what\n // tells a caller to fall back to guessing the secrets from the auth value.\n readonly resolveWithSecrets?: (\n connectionId: string,\n request?: ConnectionRequest,\n ) => Promise<ResolvedConnection>;\n\n constructor(\n private readonly inner: EngineConnectionResolver,\n private readonly binding: ConnectionBindingLookup,\n private readonly onRefused?: (\n connectionId: string,\n request?: ConnectionRequest,\n ) => void,\n ) {\n const withSecrets = inner.resolveWithSecrets?.bind(inner);\n if (!withSecrets) return;\n this.resolveWithSecrets = (connectionId, request) =>\n this.bound(connectionId, request)\n ? withSecrets(connectionId, request)\n : Promise.reject(new ConnectionNotBoundError(connectionId));\n }\n\n resolve(connectionId: string, request?: ConnectionRequest): Promise<unknown> {\n if (!this.bound(connectionId, request)) {\n return Promise.reject(new ConnectionNotBoundError(connectionId));\n }\n return this.inner.resolve(connectionId, request);\n }\n\n // Both paths ask the same question, so neither is a way around it.\n private bound(connectionId: string, request?: ConnectionRequest): boolean {\n if (this.binding()?.has(connectionId)) return true;\n this.onRefused?.(connectionId, request);\n return false;\n }\n}\n","import { childLogger } from \"document-model\";\nimport { randomUUID } from \"node:crypto\";\nimport { mkdir, rm } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport {\n bundleResolver,\n pieceModuleRef,\n type PieceResolver,\n} from \"../activepieces/resolver.js\";\nimport type { ReactorService } from \"../activepieces/context/reactor.js\";\nimport {\n rewriteFileRefs,\n type StagedFile,\n} from \"../activepieces/context/files.js\";\nimport { PieceWorker, type IPieceWorker } from \"../activepieces/worker/host.js\";\nimport { DEFAULT_EGRESS_POLICY } from \"../activepieces/worker/egress.js\";\nimport {\n LOG_WRITE,\n OUTPUT_UPDATE,\n REACTOR_CREATE,\n REACTOR_EXECUTE,\n REACTOR_FIND,\n REACTOR_GET,\n REACTOR_MODEL,\n REACTOR_MODELS,\n STORE_DELETE,\n STORE_GET,\n STORE_PUT,\n type EgressPolicy,\n type HostCallHandlers,\n type HostNotifyHandlers,\n type PieceLogEntry,\n type StagedInput,\n} from \"../activepieces/worker/protocol.js\";\nimport type { StoreScopeName } from \"../activepieces/context/store-scope.js\";\nimport {\n collectSecretValues,\n redactError,\n redactMessage,\n rememberSecrets,\n} from \"../activepieces/worker/redact.js\";\nimport type {\n ConnectionRequest,\n EngineConnectionResolver,\n ResolvedConnection,\n} from \"./connections.js\";\nimport type { BlockExecution, BlockExecutor, BlockResult } from \"./types.js\";\n\nexport class UnknownBlockTypeError extends Error {\n constructor(blockType: string) {\n super(`No executor registered for block type \"${blockType}\"`);\n this.name = \"UnknownBlockTypeError\";\n }\n}\n\nexport class TriggerBlockAsStepError extends Error {\n constructor(blockType: string) {\n super(`Trigger block type \"${blockType}\" cannot run as a workflow step`);\n this.name = \"TriggerBlockAsStepError\";\n }\n}\n\n// Core blocks. core#branch routes on its (already resolved) condition: equal\n// to `equals` when that is set, otherwise truthiness. core#assert fails the\n// run on blank or rejected values.\nexport class CoreBlockExecutor implements BlockExecutor {\n static handles(blockType: string): boolean {\n return blockType.startsWith(\"core#\");\n }\n\n execute(execution: BlockExecution): Promise<BlockResult> {\n if (execution.blockType === \"core#branch\") {\n const { condition, equals } = execution.config as {\n condition?: unknown;\n equals?: unknown;\n };\n // Trimmed and case-insensitive: the condition is often model output.\n const normalize = (value: unknown) =>\n (typeof value === \"string\"\n ? value\n : value === undefined || value === null\n ? \"\"\n : JSON.stringify(value)\n )\n .trim()\n .toLowerCase();\n const taken =\n typeof equals === \"string\"\n ? normalize(condition) === normalize(equals)\n : Boolean(condition) && condition !== \"false\" && condition !== \"0\";\n return Promise.resolve({\n output: { condition: condition ?? null },\n port: taken ? \"true\" : \"false\",\n });\n }\n if (execution.blockType === \"core#assert\") {\n return this.assert(execution);\n }\n return Promise.reject(new UnknownBlockTypeError(execution.blockType));\n }\n\n // core#assert fails the step when its value is blank or is one of the\n // rejected values. Model output is the motivating case: an empty\n // completion, or a classifier answering the wrong question, must not flow\n // on to a step with a side effect.\n private assert(execution: BlockExecution): Promise<BlockResult> {\n const { value, rejectValues, allowValues, allowEmpty, message } =\n execution.config as {\n value?: unknown;\n rejectValues?: unknown;\n allowValues?: unknown;\n allowEmpty?: unknown;\n message?: unknown;\n };\n const text =\n typeof value === \"string\"\n ? value\n : value === undefined || value === null\n ? \"\"\n : JSON.stringify(value);\n const trimmed = text.trim();\n const fail = (reason: string) =>\n Promise.reject(\n new Error(\n typeof message === \"string\" && message\n ? message\n : `core#assert: ${reason}`,\n ),\n );\n\n if (!trimmed && allowEmpty !== true) {\n return fail(\"value is empty\");\n }\n const normalizeList = (entries: unknown) =>\n (typeof entries === \"string\"\n ? [entries]\n : Array.isArray(entries)\n ? entries\n : []\n )\n .map((entry) => String(entry).trim().toLowerCase())\n .filter(Boolean);\n\n if (normalizeList(rejectValues).includes(trimmed.toLowerCase())) {\n return fail(`value is a rejected value (\"${trimmed}\")`);\n }\n // An allow-list is the safer gate for model output: anything unforeseen\n // fails here rather than reaching a step that writes.\n const allowed = normalizeList(allowValues);\n if (allowed.length > 0 && !allowed.includes(trimmed.toLowerCase())) {\n return fail(\n `value \"${trimmed}\" is not one of the allowed values (${allowed.join(\", \")})`,\n );\n }\n return Promise.resolve({ output: { value }, port: \"next\" });\n }\n}\n\n// The host's attachment store, as the engine needs it: materialize a\n// reference to a path the worker can read, and ingest a path the worker wrote.\n// Both directions go through the filesystem, so bytes never enter IPC.\nexport interface AttachmentPort {\n read(\n ref: string,\n destPath: string,\n ): Promise<{ fileName?: string; contentType?: string }>;\n write(file: {\n path: string;\n fileName: string;\n size: number;\n contentType?: string;\n }): Promise<string>;\n}\n\nconst ATTACHMENT_REF = /^attachment:\\/\\//i;\n\n// Collects every attachment reference appearing as a string in a step config.\n// Deliberately type-agnostic: the worker decides which of them to hydrate\n// (only FILE props go through toApFile), so staging a reference no one reads\n// costs one file, while missing one would fail the step.\nfunction collectRefs(value: unknown, found: Set<string>): void {\n if (typeof value === \"string\") {\n if (ATTACHMENT_REF.test(value)) found.add(value);\n return;\n }\n if (Array.isArray(value)) {\n for (const entry of value) collectRefs(entry, found);\n return;\n }\n if (typeof value === \"object\" && value !== null) {\n for (const entry of Object.values(value)) collectRefs(entry, found);\n }\n}\n\n// The durable `ctx.store`, as the engine needs it: one call per operation, so\n// a piece that checkpoints mid-loop keeps what it wrote if the step then dies.\n\n// Which scope a step's keys belong to is the host's business; the executor is\n// shared across runs and must not decide it.\nexport interface PieceStorePort {\n get(key: string, scope: StoreScopeName): Promise<unknown>;\n put(key: string, value: unknown, scope: StoreScopeName): Promise<void>;\n delete(key: string, scope: StoreScopeName): Promise<void>;\n}\n\n// One key operation as it arrives from the worker.\ninterface StoreCallPayload {\n key?: unknown;\n value?: unknown;\n scope?: unknown;\n}\n\n// An unrecognised scope is treated as FLOW, the narrower partition: a bad\n// name must never widen what a step can reach.\nfunction storeScopeOf(payload: unknown): StoreScopeName {\n const scope = (payload as StoreCallPayload | undefined)?.scope;\n return scope === \"PROJECT\" ? \"PROJECT\" : \"FLOW\";\n}\n\nfunction storeKeyOf(payload: unknown): string {\n const key = (payload as StoreCallPayload | undefined)?.key;\n if (typeof key !== \"string\" || key === \"\") {\n throw new Error(\"Store call carried no key\");\n }\n return key;\n}\n\n// The host's half of `ctx.reactor`: the same operations the piece calls, run\n// against the reactor this host serves. See activepieces/context/reactor.ts.\n\n// Registered per step and only for a piece the host resolved locally, so a\n// fetched bundle forging these calls finds no handler and is refused.\nexport type ReactorPort = ReactorService;\n\n// Payloads arrive from the child, which runs piece code: a call is checked\n// here rather than trusted to have come from our own proxy.\nfunction reactorInput(payload: unknown): Record<string, unknown> {\n if (\n typeof payload !== \"object\" ||\n payload === null ||\n Array.isArray(payload)\n ) {\n throw new Error(\"Reactor call carried no input object\");\n }\n return payload as Record<string, unknown>;\n}\n\nfunction requiredString(\n payload: Record<string, unknown>,\n field: string,\n): string {\n const value = payload[field];\n if (typeof value !== \"string\" || value === \"\") {\n throw new Error(`Reactor call carried no \"${field}\"`);\n }\n return value;\n}\n\nfunction optionalString(\n payload: Record<string, unknown>,\n field: string,\n): string | undefined {\n const value = payload[field];\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\nfunction reactorActions(payload: Record<string, unknown>) {\n const actions = payload.actions;\n if (!Array.isArray(actions) || actions.length === 0) {\n throw new Error(\"Reactor call carried no actions\");\n }\n return actions.map((entry, index) => {\n const action = entry as Record<string, unknown> | null;\n if (!action || typeof action.type !== \"string\") {\n throw new Error(`Reactor call: actions[${index}] needs a string \"type\"`);\n }\n return {\n type: action.type,\n input: action.input,\n ...(typeof action.scope === \"string\" ? { scope: action.scope } : {}),\n };\n });\n}\n\n// A page size the host will serve. The value arrives from piece code, so it\n// is clamped here rather than trusted; a host may cap it further.\nconst MAX_FIND_LIMIT = 100;\n\nfunction findLimit(value: unknown): number | undefined {\n if (typeof value !== \"number\" || !Number.isFinite(value)) return undefined;\n return Math.min(Math.max(Math.floor(value), 1), MAX_FIND_LIMIT);\n}\n\n// The state match, as the host will accept it. Both halves must be strings and\n// the path must name something: a match with an empty path would silently pass\n// every document, which is the opposite of what a step asking to match wants.\nfunction findMatch(\n value: unknown,\n): { path: string; value: string } | undefined {\n if (typeof value !== \"object\" || value === null) return undefined;\n const record = value as Record<string, unknown>;\n const path = record.path;\n const wanted = record.value;\n if (typeof path !== \"string\" || path.trim() === \"\") return undefined;\n if (typeof wanted !== \"string\") return undefined;\n return { path: path.trim(), value: wanted };\n}\n\nexport function reactorHandlers(port: ReactorPort): HostCallHandlers {\n return {\n [REACTOR_MODELS]: () => port.models(),\n [REACTOR_MODEL]: (payload) =>\n port.model(requiredString(reactorInput(payload), \"documentType\")),\n [REACTOR_GET]: (payload) => {\n const input = reactorInput(payload);\n return port.get({\n documentId: requiredString(input, \"documentId\"),\n ...(optionalString(input, \"branch\")\n ? { branch: optionalString(input, \"branch\") }\n : {}),\n });\n },\n [REACTOR_FIND]: (payload) => {\n const input = reactorInput(payload);\n return port.find({\n ...(optionalString(input, \"documentType\")\n ? { documentType: optionalString(input, \"documentType\") }\n : {}),\n ...(optionalString(input, \"parentId\")\n ? { parentId: optionalString(input, \"parentId\") }\n : {}),\n ...(findLimit(input.limit) !== undefined\n ? { limit: findLimit(input.limit) }\n : {}),\n ...(findMatch(input.match) ? { match: findMatch(input.match) } : {}),\n ...(input.withState === true ? { withState: true } : {}),\n });\n },\n [REACTOR_CREATE]: (payload) => {\n const input = reactorInput(payload);\n return port.create({\n documentType: requiredString(input, \"documentType\"),\n ...(optionalString(input, \"name\")\n ? { name: optionalString(input, \"name\") }\n : {}),\n ...(optionalString(input, \"parentId\")\n ? { parentId: optionalString(input, \"parentId\") }\n : {}),\n });\n },\n [REACTOR_EXECUTE]: (payload) => {\n const input = reactorInput(payload);\n return port.execute({\n documentId: requiredString(input, \"documentId\"),\n ...(optionalString(input, \"branch\")\n ? { branch: optionalString(input, \"branch\") }\n : {}),\n actions: reactorActions(input),\n });\n },\n };\n}\n\n// The handlers served to a running step or trigger hook. A rejection becomes\n// the error the piece sees, which is what an over-limit write should do.\nexport function storeHandlers(port: PieceStorePort): HostCallHandlers {\n return {\n [STORE_GET]: (payload) =>\n port.get(storeKeyOf(payload), storeScopeOf(payload)),\n [STORE_PUT]: async (payload) => {\n await port.put(\n storeKeyOf(payload),\n (payload as StoreCallPayload).value,\n storeScopeOf(payload),\n );\n return null;\n },\n [STORE_DELETE]: async (payload) => {\n await port.delete(storeKeyOf(payload), storeScopeOf(payload));\n return null;\n },\n };\n}\n\nconst logger = childLogger([\"workflow\", \"piece-staging\"]);\n\nexport interface ActivepiecesBlockExecutorOptions {\n cacheDir: string;\n // Piece package name -> pinned version; the connector registry for this run.\n // A blockType may instead pin inline: \"@scope/pkg@1.2.3#action\".\n\n // A function is awaited per step, so a host whose registry loads lazily —\n // package pieces are pinned by what is installed, not by the block type —\n // answers with what it has by the time a step actually runs.\n packages?:\n | Record<string, string>\n | (() => Record<string, string> | Promise<Record<string, string>>);\n connections?: EngineConnectionResolver;\n // The worker piece steps go to. A function is asked once per step, so a\n // host handing each run its own child answers with that run's.\n worker?: IPieceWorker | (() => IPieceWorker | undefined);\n defaultTimeoutMs?: number;\n // Both are needed for ctx.files to work: a directory the host and the forked\n // worker share, and somewhere to put what the piece wrote. Without them a\n // piece calling ctx.files falls back to inline data URIs.\n stagingRoot?: string;\n attachments?: AttachmentPort;\n // Without it `ctx.store` falls back to the worker's heap, which a step\n // timeout discards.\n pieceStore?: PieceStorePort;\n // Where a block type's piece comes from. Defaults to fetching the pinned\n // version into `cacheDir`, which is what a published piece needs.\n resolver?: PieceResolver;\n // Serves `ctx.reactor`, and only to a piece the resolver answered locally.\n // Without it even a package piece finds the member throwing.\n reactor?: ReactorPort;\n // Where a step's piece may connect to. Left unset it is the default policy,\n // which refuses private address space; `null` runs the piece unrestricted.\n egress?: EgressPolicy | null;\n // Taps on a running step. Each is opt-in because it costs the worker an IPC\n // message per event, and neither is asked for unless someone reads it.\n onPieceLog?: (entry: PieceLogEntry, execution: BlockExecution) => void;\n onPartialOutput?: (output: unknown, execution: BlockExecution) => void;\n}\n\n// The notify handlers served to one step. Unlike a store call, nothing here\n// answers the piece: these are reports, and the step never waits on them.\nfunction stepTaps(\n options: ActivepiecesBlockExecutorOptions,\n execution: BlockExecution,\n values: string[],\n): HostNotifyHandlers | undefined {\n const { onPieceLog, onPartialOutput } = options;\n if (!onPieceLog && !onPartialOutput) return undefined;\n const handlers: HostNotifyHandlers = {};\n if (onPieceLog) {\n // A piece logging its own outgoing request is a common idiom, so this is\n // one of the likeliest places for a credential to reach the host log.\n handlers[LOG_WRITE] = (payload) => {\n const entry = payload as PieceLogEntry;\n // Returned, not discarded: a sink that rejects is the host's to catch.\n return onPieceLog(\n { ...entry, message: redactMessage(entry.message, { values }) },\n execution,\n );\n };\n }\n if (onPartialOutput) {\n handlers[OUTPUT_UPDATE] = (payload) => onPartialOutput(payload, execution);\n }\n return handlers;\n}\n\n// Mutated in place rather than rewrapped: callers classify on the error's\n// class, and a new one would lose that.\n\n// `stack` embeds the message as it was at construction, so a caller logging\n// the error object rather than `.message` would otherwise still print it.\nfunction redactThrown(error: unknown, values: string[]): unknown {\n if (error instanceof Error) {\n error.message = redactMessage(error.message, { values });\n if (error.stack) error.stack = redactMessage(error.stack, { values });\n return rememberSecrets(error, values);\n }\n return rememberSecrets(redactError(error, { values }), values);\n}\n\nexport type BlockKind = \"action\" | \"trigger\";\n\nexport interface ParsedBlockType {\n packageName: string;\n version: string;\n kind: BlockKind;\n // Action or trigger name within the piece.\n name: string;\n}\n\nconst TRIGGER_FRAGMENT = \"trigger:\";\n\n// \"<pkg>[@<version>]#<action>\" or \"<pkg>[@<version>]#trigger:<trigger>\" —\n// the version after the scope-less \"@\" wins over the registry.\nexport function parseBlockType(\n blockType: string,\n packages: Record<string, string> = {},\n): ParsedBlockType | undefined {\n const separator = blockType.lastIndexOf(\"#\");\n if (separator <= 0) return undefined;\n const packageSpec = blockType.slice(0, separator);\n const fragment = blockType.slice(separator + 1);\n const isTrigger = fragment.startsWith(TRIGGER_FRAGMENT);\n const name = isTrigger ? fragment.slice(TRIGGER_FRAGMENT.length) : fragment;\n if (!name) return undefined;\n const kind: BlockKind = isTrigger ? \"trigger\" : \"action\";\n const versionAt = packageSpec.indexOf(\"@\", 1);\n if (versionAt > 0) {\n return {\n packageName: packageSpec.slice(0, versionAt),\n version: packageSpec.slice(versionAt + 1),\n kind,\n name,\n };\n }\n const version = packages[packageSpec] as string | undefined;\n if (!version) return undefined;\n return { packageName: packageSpec, version, kind, name };\n}\n\n// Executes \"<packageName>#<actionName>\" block types through the piece worker.\nexport class ActivepiecesBlockExecutor implements BlockExecutor {\n // Only set when nothing was supplied: the fallback this executor owns and\n // must dispose. A supplied worker belongs to whoever supplied it.\n private own: PieceWorker | undefined;\n\n private readonly resolver: PieceResolver;\n\n constructor(private readonly options: ActivepiecesBlockExecutorOptions) {\n this.resolver =\n options.resolver ?? bundleResolver({ cacheDir: options.cacheDir });\n }\n\n private worker(): IPieceWorker {\n const supplied = this.options.worker;\n if (typeof supplied === \"function\") {\n const worker = supplied();\n if (worker) return worker;\n } else if (supplied) {\n return supplied;\n }\n return (this.own ??= new PieceWorker());\n }\n\n private packages(): Promise<Record<string, string>> {\n const supplied = this.options.packages;\n return Promise.resolve(\n typeof supplied === \"function\" ? supplied() : (supplied ?? {}),\n );\n }\n\n async execute(execution: BlockExecution): Promise<BlockResult> {\n const parsed = parseBlockType(execution.blockType, await this.packages());\n if (!parsed) {\n throw new UnknownBlockTypeError(execution.blockType);\n }\n if (parsed.kind !== \"action\") {\n throw new TriggerBlockAsStepError(execution.blockType);\n }\n\n // One staging directory per execution, removed in the finally below. A\n // host crash can still leave one behind, which is why it lives under a\n // root the host can sweep at startup.\n const stagingDir = this.options.stagingRoot\n ? path.join(this.options.stagingRoot, randomUUID())\n : undefined;\n\n // Bundle fetch and connection resolution belong inside the catch: a secret\n // provider or a resolver can fail with the credential in its own message.\n let redactValues: string[] = [];\n try {\n const piece = await this.resolver.resolve(\n parsed.packageName,\n parsed.version,\n );\n const connection = await this.resolveConnection(execution.connectionId, {\n blockType: execution.blockType,\n piecePackage: parsed.packageName,\n stepId: execution.step.id,\n stepKey: execution.step.key,\n });\n const auth = connection?.auth;\n redactValues = connection?.secretValues ?? [];\n\n const timeoutMs = execution.step.timeoutSeconds\n ? execution.step.timeoutSeconds * 1000\n : this.options.defaultTimeoutMs;\n const stagedInputs = await this.stageInputs(execution.config, stagingDir);\n const pieceStore = this.options.pieceStore;\n const notifications = stepTaps(this.options, execution, redactValues);\n const egress =\n this.options.egress === undefined\n ? DEFAULT_EGRESS_POLICY\n : this.options.egress;\n // A fetched bundle never reaches the reactor: the handlers below are the\n // only way in, and they are registered for a local piece alone.\n const reactor = piece.local ? this.options.reactor : undefined;\n const result = await this.worker().runAction(\n {\n ...pieceModuleRef(piece),\n actionName: parsed.name,\n propsValue: execution.config as Record<string, unknown>,\n auth,\n ...(redactValues.length > 0 ? { redactValues } : {}),\n ...(stagingDir ? { stagingDir } : {}),\n ...(stagedInputs ? { stagedInputs } : {}),\n ...(pieceStore ? { durableStore: true } : {}),\n ...(reactor ? { reactorAccess: true } : {}),\n ...(this.options.onPieceLog ? { captureLogs: true } : {}),\n ...(this.options.onPartialOutput ? { liveOutput: true } : {}),\n ...(egress ? { egress } : {}),\n },\n {\n ...(timeoutMs ? { timeoutMs } : {}),\n ...(pieceStore || reactor\n ? {\n hostCalls: {\n ...(pieceStore ? storeHandlers(pieceStore) : {}),\n ...(reactor ? reactorHandlers(reactor) : {}),\n },\n }\n : {}),\n ...(notifications ? { notifications } : {}),\n },\n );\n return {\n output: await this.ingestFiles(result.output, result.files),\n redactValues,\n };\n } catch (error) {\n // The child already stripped what it threw; this covers what the host\n // itself raises (bundle fetch, connection resolution, file ingest).\n throw redactThrown(error, redactValues);\n } finally {\n if (stagingDir) await rm(stagingDir, { recursive: true, force: true });\n }\n }\n\n private async resolveConnection(\n connectionId: string | null | undefined,\n request: ConnectionRequest,\n ): Promise<ResolvedConnection | undefined> {\n const connections = this.options.connections;\n if (!connectionId || !connections) return undefined;\n // The request travels with both, so taking the secret-bearing path never\n // means skipping the check on who is asking.\n if (connections.resolveWithSecrets) {\n return connections.resolveWithSecrets(connectionId, request);\n }\n const auth = await connections.resolve(connectionId, request);\n return { auth, secretValues: [...collectSecretValues(auth)] };\n }\n\n private async stageInputs(\n config: unknown,\n stagingDir: string | undefined,\n ): Promise<StagedInput[] | undefined> {\n const port = this.options.attachments;\n if (!stagingDir || !port) return undefined;\n const refs = new Set<string>();\n collectRefs(config, refs);\n if (refs.size === 0) return undefined;\n await mkdir(stagingDir, { recursive: true });\n const staged: StagedInput[] = [];\n let index = 0;\n for (const ref of refs) {\n const destPath = path.join(stagingDir, `in-${index++}`);\n try {\n const meta = await port.read(ref, destPath);\n staged.push({ ref, path: destPath, ...meta });\n } catch (error) {\n // Staging is opportunistic: refs are collected from the whole config\n // without knowing which props are FILE, because the prop schema lives\n // in the worker. So a ref this step was never going to open must not\n // fail it -- a dispatch carrying one as data is the ordinary case. A\n // FILE prop that did need it still fails, in the worker, naming the\n // reference it could not resolve.\n logger.debug(\n `Left ${ref} unstaged: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n return staged;\n }\n\n // A provisional apfile:// token only becomes a real reference once the step\n // has returned, so a piece that writes a file and then reads it back by URL\n // within the same run would not work. No action needs that today; the fix is\n // a bidirectional worker channel, which is its own design.\n private async ingestFiles(\n output: unknown,\n files: StagedFile[] | undefined,\n ): Promise<unknown> {\n if (!files || files.length === 0) return output;\n const port = this.options.attachments;\n if (!port) {\n throw new Error(\n `The action wrote ${files.length} file(s) through ctx.files, but no attachment store is configured for this reactor`,\n );\n }\n const refs = new Map<string, string>();\n for (const file of files) {\n refs.set(\n file.token,\n await port.write({\n path: file.path,\n fileName: file.fileName,\n size: file.size,\n contentType: file.contentType,\n }),\n );\n }\n return rewriteFileRefs(output, refs);\n }\n\n dispose(): void {\n this.own?.dispose();\n this.own = undefined;\n }\n}\n\n// Routes explicit handlers first, then core#*, then the piece executor.\n// Handlers let a host add block types of its own, served in its process.\nexport class CompositeBlockExecutor implements BlockExecutor {\n private readonly core = new CoreBlockExecutor();\n\n constructor(\n private readonly pieces: BlockExecutor,\n private readonly handlers: Record<string, BlockExecutor> = {},\n ) {}\n\n execute(execution: BlockExecution): Promise<BlockResult> {\n const handler = this.handlers[execution.blockType] as\n | BlockExecutor\n | undefined;\n if (handler) return handler.execute(execution);\n if (CoreBlockExecutor.handles(execution.blockType)) {\n return this.core.execute(execution);\n }\n return this.pieces.execute(execution);\n }\n}\n","import {\n containsRedactedMarker,\n redact,\n redactMessage,\n secretsFor,\n} from \"../activepieces/worker/redact.js\";\nimport {\n evaluateCondition,\n resolveExpressions,\n type ExpressionScope,\n} from \"./expressions.js\";\nimport type {\n BlockExecutor,\n StepExecutionRecord,\n WorkflowDefinition,\n WorkflowRunResult,\n WorkflowStepDef,\n} from \"./types.js\";\n\nexport interface RunWorkflowOptions {\n definition: WorkflowDefinition;\n executor: BlockExecutor;\n // Exposed to expressions as {{trigger.payload...}}.\n triggerPayload?: unknown;\n // Journaled outputs from a prior run, keyed by step id; matching steps\n // replay (output injected, port re-taken) instead of executing.\n completedSteps?: Map<string, { output?: unknown; port?: string | null }>;\n // Called as each step reaches a terminal state, so a run that dies\n // mid-flight leaves the steps it finished behind. Ordinal is execution\n // order; skips are excluded, being knowable only once the run completes.\n onStep?: (\n record: StepExecutionRecord,\n ordinal: number,\n ) => void | Promise<void>;\n}\n\nfunction errorMessage(error: unknown): string {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\n// A record is journal material, read back by the editor and kept in the\n// database, so it never carries the live value a downstream step reads.\nfunction journaled(value: unknown, values: string[] | undefined): unknown {\n return value === undefined ? undefined : redact(value, { values });\n}\n\n// Sequential v1 of the RunCoordinator (doc 08 §7.3): walks the steps+edges\n// graph, resolving each step's config against prior outputs before executing.\nexport async function runWorkflow(\n options: RunWorkflowOptions,\n): Promise<WorkflowRunResult> {\n const { definition, executor } = options;\n const scope: ExpressionScope = {\n trigger: { payload: options.triggerPayload },\n steps: {},\n variables: Object.fromEntries(\n (definition.variables ?? []).map((v) => [v.key, v.value ?? null]),\n ),\n };\n\n const records = new Map<string, StepExecutionRecord>();\n // edgeId -> taken; an edge is decided once its source ran or was skipped.\n const edgeDecisions = new Map<string, boolean>();\n let runFailed: string | undefined;\n let executedCount = 0;\n\n // A failing journal write must not cost us the step's completed work: the\n // run carries on, and finishRun's final sweep repairs the missing row.\n const journal = async (record: StepExecutionRecord) => {\n if (!options.onStep) return;\n const ordinal = executedCount++;\n try {\n await options.onStep(record, ordinal);\n } catch {\n // Durability is the bonus here; run correctness is not at stake.\n }\n };\n\n const decideOutgoing = (sourceId: string, port: string | undefined) => {\n for (const edge of definition.edges) {\n if (edge.from !== sourceId) continue;\n const portMatches = port !== undefined && edge.port === port;\n const taken =\n portMatches &&\n (!edge.condition || evaluateCondition(edge.condition, scope));\n edgeDecisions.set(edge.id, taken);\n }\n };\n\n // Trigger edges fire on the trigger's implicit \"next\" port.\n if (definition.trigger) {\n decideOutgoing(definition.trigger.id, \"next\");\n }\n\n const inboundEdges = (step: WorkflowStepDef) =>\n definition.edges.filter((edge) => edge.to === step.id);\n\n const isEntryStep = (step: WorkflowStepDef) =>\n !definition.trigger && inboundEdges(step).length === 0;\n\n const skipStep = (step: WorkflowStepDef) => {\n records.set(step.id, {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"SKIPPED\",\n });\n decideOutgoing(step.id, undefined);\n };\n\n // The journal keeps a redacted copy, so a replay would hand the marker to\n // the next step. Refusing is loud; replaying it would be silently wrong.\n const refuseReplay = (step: WorkflowStepDef) => {\n const error =\n `Journaled output of step \"${step.key}\" was redacted and cannot be ` +\n \"replayed; fire the workflow again instead of rerunning it\";\n records.set(step.id, {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"FAILED\",\n error,\n });\n runFailed = error;\n };\n\n const executeStep = async (step: WorkflowStepDef) => {\n const replay = options.completedSteps?.get(step.id);\n if (replay) {\n if (containsRedactedMarker(replay.output)) {\n refuseReplay(step);\n return;\n }\n const port = replay.port ?? \"next\";\n const record: StepExecutionRecord = {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"REPLAYED\",\n output: replay.output,\n port,\n };\n records.set(step.id, record);\n await journal(record);\n scope.steps[step.key] = { output: replay.output };\n decideOutgoing(step.id, port);\n return;\n }\n const input = resolveExpressions(step.config, scope);\n try {\n const result = await executor.execute({\n blockType: step.blockType,\n config: input,\n connectionId: step.connectionId,\n step,\n });\n const port = result.port ?? \"next\";\n const record: StepExecutionRecord = {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"SUCCEEDED\",\n input: journaled(input, result.redactValues),\n output: journaled(result.output, result.redactValues),\n port,\n };\n records.set(step.id, record);\n await journal(record);\n scope.steps[step.key] = { output: result.output };\n decideOutgoing(step.id, port);\n } catch (error) {\n // A failed step is exactly where an input gets inspected, so it is\n // redacted with the same secrets the successful path uses.\n const values = secretsFor(error);\n const detail = redactMessage(errorMessage(error), { values });\n const record: StepExecutionRecord = {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"FAILED\",\n input: journaled(input, values),\n error: detail,\n };\n records.set(step.id, record);\n await journal(record);\n decideOutgoing(step.id, \"error\");\n const errorHandled = definition.edges.some(\n (edge) => edge.from === step.id && edgeDecisions.get(edge.id),\n );\n if (!errorHandled) {\n runFailed = `Step \"${step.key}\" failed: ${detail}`;\n }\n }\n };\n\n let progressed = true;\n while (progressed && !runFailed) {\n progressed = false;\n for (const step of definition.steps) {\n if (records.has(step.id)) continue;\n const inbound = inboundEdges(step);\n if (isEntryStep(step)) {\n await executeStep(step);\n progressed = true;\n // Independent roots are otherwise free to run their side effects\n // before the outer loop notices the run is already over.\n if (runFailed) break;\n continue;\n }\n if (inbound.length === 0) continue;\n const decided = inbound.every((edge) => edgeDecisions.has(edge.id));\n if (!decided) continue;\n const reachable = inbound.some((edge) => edgeDecisions.get(edge.id));\n if (reachable) {\n await executeStep(step);\n } else {\n skipStep(step);\n }\n progressed = true;\n if (runFailed) break;\n }\n }\n\n // Steps never reached (dangling, cyclic, or after a terminal failure).\n for (const step of definition.steps) {\n if (!records.has(step.id)) skipStep(step);\n }\n\n // A FAILED record with a taken error edge is a handled failure; only\n // unhandled ones set runFailed above.\n const steps = definition.steps.map((step) => records.get(step.id)!);\n return runFailed\n ? { status: \"FAILED\", steps, error: runFailed }\n : { status: \"SUCCEEDED\", steps };\n}\n","// The pieces this reactor holds locally, by piece name.\n\n// A holder, not a finder: resolving a package is the host's package manager's\n// job, and this runtime must not depend on reactor-api to have it done.\nimport { childLogger } from \"document-model\";\nimport type { LocalPiece } from \"../pieces/index.js\";\n\nconst logger = childLogger([\"workflow\", \"piece-registry\"]);\n\nexport class PieceRegistry {\n private byName = new Map<string, LocalPiece>();\n\n // Replaces the whole set: what the host reports is everything it holds, so\n // a piece missing from it is a piece the reactor no longer has.\n setPieces(pieces: readonly LocalPiece[]): void {\n const found = new Map<string, LocalPiece>();\n for (const piece of pieces) {\n // The first to claim a name keeps it, so a project can override a piece\n // one of its dependencies ships.\n if (!found.has(piece.name)) found.set(piece.name, piece);\n }\n this.byName = found;\n const names = [...found.keys()].join(\", \");\n // Names go through the logger's values: it substitutes `@`-prefixed\n // tokens, and a scoped package name printed inline comes out as null/pack.\n if (found.size > 0) {\n logger.info(`Holding ${found.size} package piece(s): @names`, names);\n } else {\n logger.debug(\"Holding no package pieces\");\n }\n }\n\n lookup = (name: string): LocalPiece | undefined => this.byName.get(name);\n\n entries(): LocalPiece[] {\n return [...this.byName.values()];\n }\n\n // Name -> installed version, the registry parseBlockType resolves an\n // unversioned block type against.\n versions(): Record<string, string> {\n return Object.fromEntries(\n [...this.byName.values()].map((piece) => [piece.name, piece.version]),\n );\n }\n\n /** Test seam: a suite that filled the registry starts the next from nothing. */\n reset(): void {\n this.byName = new Map();\n }\n}\n\n// One registry for the runtime, the way the bundle cache is one directory.\nexport const packagePieces = new PieceRegistry();\n"],"mappings":";;;;;;;;;;;;AAYA,MAAMA,WAAS,YAAY,CAAC,YAAY,iBAAiB,CAAC;AAa1D,SAAS,OAAO,SAAsC;AACpD,QAAO;EACL;EACA,aAAa,gBACX,cACI,GAAG,QAAQ,6CACX,GAAG,QAAQ;EAGjB,WAAW,SAAS,GAAG,QAAQ,UAAU,mBAAmB,KAAK;EACjE,aAAa,MAAM,YACjB,GAAG,QAAQ,oBAAoB,KAAK,QAAQ,KAAK,IAAI,CAAC,GAAG,QAAQ;EACpE;;AAMH,IAAI;AAEJ,SAAgB,oBAAoB,KAA+B;CACjE,MAAM,UAAU,KAAK,MAAM,CAAC,QAAQ,QAAQ,GAAG,IAAI;AACnD,KAAI,YAAY,IAAI;AAClB,eAAa,KAAA;AACb;;AAEF,KAAI,YAAY,YAAY,QAAS;AACrC,cAAa,OAAO,QAAQ;AAC5B,UAAO,KAAK,8BAA8B,WAAW,UAAU;;AAGjE,SAAgB,sBAAuD;AACrE,QAAO;;;;AClDT,MAAMC,WAAS,UAAUC,OAAS;AAIlC,MAAM,iBAAiB;AACvB,MAAM,mBAAmB;AAEzB,SAAgB,cAAc,MAAc,SAAyB;AACnE,QAAO,GAAG,iBAAiB,KAAK,QAAQ,KAAK,IAAI,CAAC,GAAG,QAAQ;;AAG/D,SAAgB,cAAc,MAAc,SAAyB;AAEnE,QAAO,GAAG,iBAAiB,GAAG,KAAK,KADlB,KAAK,WAAW,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,KAAK,KACZ,GAAG,QAAQ;;AAI9D,MAAM,cAAc;AACpB,MAAM,iBAAiB;AAEvB,SAAS,6BAA6B,MAAc,SAAuB;AACzE,KAAI,CAAC,YAAY,KAAK,KAAK,CACzB,OAAM,IAAI,MAAM,+BAA+B,OAAO;AAExD,KAAI,CAAC,eAAe,KAAK,QA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ACtB,SAAO,CAAC,GAAG,KAAK,OAAO,QAAQ,CAAC;;CAKlC,WAAmC;AACjC,SAAO,OAAO,YACZ,CAAC,GAAG,KAAK,OAAO,QAAQ,CAAC,CAAC,KAAK,UAAU,CAAC,MAAM,MAAM,MAAM,QAAQ,CAAC,CACtE;;;CAIH,QAAc;AACZ,OAAK,yBAAS,IAAI,KAAK;;;AAK3B,MAAa,gBAAgB,IAAI,eAAe"}
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { f as extractDedupeKey } from "./redact-C7LWgAyD.js";
2
- import { S as localFirstResolver, T as fetchPieceBundle, a as CompositeBlockExecutor, i as ActivepiecesBlockExecutor, p as InMemorySecretProvider, r as runWorkflow, t as PieceRegistry, u as StaticConnectionResolver, v as PieceWorkerPool, w as ensurePieceBundle, y as PieceWorker } from "./piece-registry-CzYq4sK-.js";
2
+ import { S as localFirstResolver, T as fetchPieceBundle, a as CompositeBlockExecutor, i as ActivepiecesBlockExecutor, p as InMemorySecretProvider, r as runWorkflow, t as PieceRegistry, u as StaticConnectionResolver, v as PieceWorkerPool, w as ensurePieceBundle, y as PieceWorker } from "./piece-registry-WukyH-O-.js";
3
3
  import { i as loadPieceFromDir, t as buildDescriptor } from "./descriptor-CRkDqx3C.js";
4
4
  export { ActivepiecesBlockExecutor, CompositeBlockExecutor, InMemorySecretProvider, PieceRegistry, PieceWorker, PieceWorkerPool, StaticConnectionResolver, buildDescriptor, ensurePieceBundle, extractDedupeKey, fetchPieceBundle, loadPieceFromDir, localFirstResolver, runWorkflow };
@@ -460,7 +460,7 @@ async function handleResolveOptions(message) {
460
460
  };
461
461
  }
462
462
  function stagedInputResolver(inputs) {
463
- if (!inputs || inputs.length === 0) return void 0;
463
+ if (!inputs) return void 0;
464
464
  const byRef = new Map(inputs.map((input) => [input.ref, input]));
465
465
  return async (ref) => {
466
466
  const staged = byRef.get(ref);
@@ -1 +1 @@
1
- {"version":3,"file":"worker-entry.js","names":[],"sources":["../src/pieces/activepieces/worker/host-call.ts","../src/pieces/activepieces/context/reactor.ts","../src/pieces/activepieces/context/check.ts","../src/pieces/activepieces/context/normalize.ts","../src/pieces/activepieces/context/props.ts","../src/pieces/activepieces/context/remote-store.ts","../src/pieces/activepieces/context/remote-output.ts","../src/pieces/activepieces/worker/logs.ts","../src/pieces/activepieces/worker/entry.ts"],"sourcesContent":["// The child's half of the call channel: how piece code reaches durable host\n// state mid-step, instead of handing everything back when the step returns.\n\n// Modelled on their engine RPC (createRpcClient): a method name, a payload, an\n// id, and failures returned as data rather than thrown across the boundary.\nimport type { HostCallResponse } from \"./protocol.js\";\n\n// A host call is a local IPC round trip. Ten seconds is already pathological;\n// the step's own timeout is the outer bound and kills the worker outright.\nconst DEFAULT_HOST_CALL_TIMEOUT_MS = 10_000;\n\ninterface Pending {\n method: string;\n resolve: (value: unknown) => void;\n reject: (error: Error) => void;\n timer: NodeJS.Timeout;\n}\n\nconst pending = new Map<number, Pending>();\nlet nextId = 1;\nlet listening = false;\n\nexport class HostCallError extends Error {\n constructor(method: string, detail: string) {\n super(`Host call \"${method}\" failed: ${detail}`);\n this.name = \"HostCallError\";\n }\n}\n\nexport class HostCallTimeoutError extends Error {\n constructor(method: string, timeoutMs: number) {\n super(`Host call \"${method}\" got no answer within ${timeoutMs}ms`);\n this.name = \"HostCallTimeoutError\";\n }\n}\n\nfunction isHostCallResponse(value: unknown): value is HostCallResponse {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { type?: unknown }).type === \"host-result\"\n );\n}\n\n// Registered once, on the same channel the job messages arrive on. The job\n// dispatcher ignores `host-result` because it only knows its own request types.\nfunction ensureListening(): void {\n if (listening) return;\n listening = true;\n process.on(\"message\", (message: unknown) => {\n if (!isHostCallResponse(message)) return;\n const entry = pending.get(message.id);\n if (!entry) return;\n pending.delete(message.id);\n clearTimeout(entry.timer);\n if (message.error !== undefined) {\n entry.reject(new HostCallError(entry.method, message.error));\n return;\n }\n entry.resolve(message.value);\n });\n}\n\nexport function callHost<T = unknown>(\n method: string,\n payload: unknown,\n timeoutMs: number = DEFAULT_HOST_CALL_TIMEOUT_MS,\n): Promise<T> {\n if (!process.send) {\n return Promise.reject(\n new HostCallError(method, \"the worker has no channel to its host\"),\n );\n }\n ensureListening();\n const id = nextId++;\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => {\n pending.delete(id);\n reject(new HostCallTimeoutError(method, timeoutMs));\n }, timeoutMs);\n pending.set(id, {\n method,\n resolve: resolve as (value: unknown) => void,\n reject,\n timer,\n });\n process.send?.({ id, type: \"host-call\", method, payload });\n });\n}\n\n// Test seam: a worker replaced between suites must not inherit pending calls.\nexport function resetHostCalls(): void {\n for (const entry of pending.values()) clearTimeout(entry.timer);\n pending.clear();\n}\n\n// The one-way half: a report with no answer to wait for. It cannot fail from\n// the piece's side, so a missing channel is dropped rather than raised.\nexport function notifyHost(method: string, payload: unknown): void {\n try {\n process.send?.({ type: \"host-notify\", method, payload });\n } catch {\n // `process.send` stays defined after the channel closes and throws. A tap\n // that threw here would be a tap that changed the step.\n }\n}\n","// `ctx.reactor` — the one way piece code reaches the reactor it runs inside.\n\n// Pieces are isolated from the host on purpose, so this is not a client: it is\n// the same call channel `ctx.store` uses (doc 08 §10), and every method is a\n// round trip the host answers. The host installs it only for a piece that came\n// from an installed reactor package; a bundle fetched from a registry gets the\n// throwing stub instead, and finds out by name that it has no reactor.\nimport { callHost } from \"../worker/host-call.js\";\nimport type {\n ReactorCreateInput,\n ReactorDocumentSummary,\n ReactorExecuteInput,\n ReactorFindInput,\n ReactorModelDetail,\n ReactorModelSummary,\n ReactorService,\n} from \"@powerhousedao/pieces-framework\";\nimport {\n REACTOR_CREATE,\n REACTOR_EXECUTE,\n REACTOR_FIND,\n REACTOR_GET,\n REACTOR_MODEL,\n REACTOR_MODELS,\n} from \"../worker/protocol.js\";\n\n// The service contract and its input/output shapes live in the framework, so a\n// piece and the host it calls are typed against one declaration.\nexport type {\n ReactorActionInput,\n ReactorCreateInput,\n ReactorDocumentSummary,\n ReactorExecuteInput,\n ReactorFindInput,\n ReactorModelActionSchema,\n ReactorModelDetail,\n ReactorModelSummary,\n ReactorService,\n} from \"@powerhousedao/pieces-framework\";\n\n// The worker's half: every method is one host call, named so a failure reads\n// as the operation the piece asked for.\nexport class RemoteReactorService implements ReactorService {\n models(): Promise<ReactorModelSummary[]> {\n return callHost<ReactorModelSummary[]>(REACTOR_MODELS, {});\n }\n\n model(documentType: string): Promise<ReactorModelDetail> {\n return callHost<ReactorModelDetail>(REACTOR_MODEL, { documentType });\n }\n\n get(input: {\n documentId: string;\n branch?: string;\n }): Promise<ReactorDocumentSummary> {\n return callHost<ReactorDocumentSummary>(REACTOR_GET, input);\n }\n\n find(input: ReactorFindInput): Promise<ReactorDocumentSummary[]> {\n return callHost<ReactorDocumentSummary[]>(REACTOR_FIND, input);\n }\n\n create(input: ReactorCreateInput): Promise<ReactorDocumentSummary> {\n return callHost<ReactorDocumentSummary>(REACTOR_CREATE, input);\n }\n\n execute(input: ReactorExecuteInput): Promise<ReactorDocumentSummary> {\n return callHost<ReactorDocumentSummary>(REACTOR_EXECUTE, input);\n }\n}\n","// Context handed to a piece's connection check. The framework has no\n// checkConnection hook: auth.validate({auth, server}) is the whole contract.\nimport { throwingStub, withTouchTracking } from \"./stubs.js\";\nimport type { AuthValidationServerContext } from \"@powerhousedao/pieces-framework\";\n\nexport interface CheckConnectionContextOptions {\n auth?: unknown;\n // apiUrl / publicUrl when the host serves them; mintOidcToken always throws,\n // since no reactor mints tokens for a piece's validate().\n server?: Omit<AuthValidationServerContext, \"mintOidcToken\">;\n onTouch?: (member: string) => void;\n}\n\nexport interface BuiltApCheckConnectionContext {\n auth: unknown;\n server: AuthValidationServerContext;\n}\n\nexport interface CheckConnectionContextHandle {\n context: BuiltApCheckConnectionContext;\n // Top-level members the check read; `UNDOCUMENTED:<name>` marks unknown reads.\n touched: ReadonlySet<string>;\n}\n\nexport function buildCheckConnectionContext(\n options: CheckConnectionContextOptions = {},\n): CheckConnectionContextHandle {\n const touched = new Set<string>();\n const base: Record<string, unknown> = {\n auth: options.auth,\n server: options.server\n ? {\n ...options.server,\n mintOidcToken: throwingStub(\"server.mintOidcToken\"),\n }\n : throwingStub(\"server\"),\n };\n const context = withTouchTracking(base, touched, options.onTouch);\n return {\n context: context as unknown as BuiltApCheckConnectionContext,\n touched,\n };\n}\n","// Run-time coercion of stored config values into the shapes pieces expect: the\n// engine's own property processors, with our file hydration in front of theirs.\nimport type { PieceProperty } from \"@powerhousedao/pieces-framework\";\nimport {\n arrayZipperProcessor,\n processors,\n type ProcessorFn,\n} from \"@powerhousedao/pieces-framework/host\";\nimport type { ApProperty } from \"../types.js\";\nimport {\n assertWithinLimit,\n DEFAULT_MAX_FILE_BYTES,\n maxFileBytes,\n} from \"./limits.js\";\n\n// Framework ApFile (filename, data, extension, base64) as a plain object so\n// it survives IPC and structured cloning.\nexport interface ApFileValue {\n filename: string;\n extension?: string;\n base64: string;\n data: Buffer;\n}\n\nexport interface FetchedFile {\n data: Buffer;\n filename?: string;\n contentType?: string;\n}\n\nexport interface NormalizeOptions {\n // Resolves a URL-valued FILE prop; defaults to fetch() with a size cap.\n fetchFile?: (url: string) => Promise<FetchedFile>;\n // Resolves a reference-valued FILE prop (attachment:// or apfile://). The\n // worker resolves these from files the host staged on disk, so the bytes\n // never cross IPC.\n resolveRef?: (ref: string) => Promise<FetchedFile>;\n}\n\n// Re-exported for compatibility; the ceiling itself lives in limits.ts so the\n// inbound and outbound paths cannot drift apart.\nexport const MAX_FILE_BYTES = DEFAULT_MAX_FILE_BYTES;\nconst FETCH_TIMEOUT_MS = 30_000;\n\n// A FILE prop whose value is a reference the host has to resolve.\nconst FILE_REF = /^(?:attachment|apfile):\\/\\//i;\n\nexport class FileFetchError extends Error {\n constructor(url: string, reason: string) {\n super(`Could not fetch FILE prop \"${url}\": ${reason}`);\n this.name = \"FileFetchError\";\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nconst DATA_URI = /^data:([^;,]*)((?:;[^;,]*)*),([\\s\\S]*)$/;\n\nfunction extensionOf(filename: string): string | undefined {\n const dot = filename.lastIndexOf(\".\");\n return dot > 0 && dot < filename.length - 1\n ? filename.slice(dot + 1)\n : undefined;\n}\n\nconst MIME_EXTENSIONS: Record<string, string> = {\n \"image/png\": \"png\",\n \"image/jpeg\": \"jpg\",\n \"image/gif\": \"gif\",\n \"image/webp\": \"webp\",\n \"image/svg+xml\": \"svg\",\n \"application/pdf\": \"pdf\",\n \"application/json\": \"json\",\n \"text/plain\": \"txt\",\n \"text/csv\": \"csv\",\n};\n\nfunction toFileValue(\n data: Buffer,\n filename: string | undefined,\n contentType: string | undefined,\n): ApFileValue {\n const mime = contentType?.split(\";\")[0].trim().toLowerCase();\n const mimeExtension = mime ? MIME_EXTENSIONS[mime] : undefined;\n const name =\n filename && filename !== \"\"\n ? filename\n : `file${mimeExtension ? `.${mimeExtension}` : \"\"}`;\n const extension = extensionOf(name) ?? mimeExtension;\n return {\n filename: name,\n ...(extension ? { extension } : {}),\n base64: data.toString(\"base64\"),\n data,\n };\n}\n\nfunction filenameFromDisposition(header: string | null): string | undefined {\n if (!header) return undefined;\n const utf8 = /filename\\*=(?:UTF-8'')?([^;]+)/i.exec(header);\n if (utf8) {\n try {\n return decodeURIComponent(utf8[1].trim().replace(/^\"|\"$/g, \"\"));\n } catch {\n // fall through to the plain form\n }\n }\n const plain = /filename=\"?([^\";]+)\"?/i.exec(header);\n return plain ? plain[1].trim() : undefined;\n}\n\nasync function defaultFetchFile(url: string): Promise<FetchedFile> {\n let response: Response;\n try {\n response = await fetch(url, {\n signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),\n });\n } catch (error) {\n throw new FileFetchError(\n url,\n error instanceof Error ? error.message : String(error),\n );\n }\n if (!response.ok) throw new FileFetchError(url, `HTTP ${response.status}`);\n const limit = maxFileBytes();\n const declared = Number(response.headers.get(\"content-length\"));\n if (Number.isFinite(declared) && declared > limit) {\n throw new FileFetchError(url, `${declared} bytes exceeds ${limit}`);\n }\n const data = Buffer.from(await response.arrayBuffer());\n if (data.byteLength > limit) {\n throw new FileFetchError(url, `${data.byteLength} bytes exceeds ${limit}`);\n }\n let filename = filenameFromDisposition(\n response.headers.get(\"content-disposition\"),\n );\n if (!filename) {\n const segment = new URL(url).pathname.split(\"/\").filter(Boolean).pop();\n if (segment) filename = decodeURIComponent(segment);\n }\n return {\n data,\n filename,\n contentType: response.headers.get(\"content-type\") ?? undefined,\n };\n}\n\nfunction isFileShaped(value: unknown): value is ApFileValue {\n return (\n isRecord(value) &&\n typeof value.filename === \"string\" &&\n (typeof value.base64 === \"string\" || Buffer.isBuffer(value.data))\n );\n}\n\n// URL or data URI → ApFile shape; already-shaped objects are completed\n// (data/base64 derived from each other); anything else passes through.\nexport async function toApFile(\n value: unknown,\n options: NormalizeOptions = {},\n): Promise<unknown> {\n if (isFileShaped(value)) {\n const data = Buffer.isBuffer(value.data)\n ? value.data\n : Buffer.from(value.base64, \"base64\");\n // The cap applies to every branch, not just the fetched one: an oversized\n // data URI or file-shaped object would otherwise slip past it.\n assertWithinLimit(data.byteLength);\n const extension = value.extension ?? extensionOf(value.filename);\n return {\n ...value,\n ...(extension ? { extension } : {}),\n base64:\n typeof value.base64 === \"string\"\n ? value.base64\n : data.toString(\"base64\"),\n data,\n };\n }\n if (typeof value !== \"string\") return value;\n const trimmed = value.trim();\n if (trimmed === \"\") return undefined;\n const dataUri = DATA_URI.exec(trimmed);\n if (dataUri) {\n const [, mime, params, payload] = dataUri;\n const isBase64 = /;base64/i.test(params);\n const data = isBase64\n ? Buffer.from(payload, \"base64\")\n : Buffer.from(decodeURIComponent(payload), \"utf8\");\n assertWithinLimit(data.byteLength);\n const nameParam = /;name=([^;]+)/i.exec(params)?.[1];\n return toFileValue(\n data,\n nameParam ? decodeURIComponent(nameParam) : undefined,\n mime || undefined,\n );\n }\n if (FILE_REF.test(trimmed)) {\n if (!options.resolveRef) {\n throw new FileFetchError(\n trimmed,\n \"no attachment resolver is available in this context\",\n );\n }\n const resolved = await options.resolveRef(trimmed);\n assertWithinLimit(resolved.data.byteLength);\n return toFileValue(resolved.data, resolved.filename, resolved.contentType);\n }\n if (/^https?:\\/\\//i.test(trimmed)) {\n const fetched = await (options.fetchFile ?? defaultFetchFile)(trimmed);\n return toFileValue(fetched.data, fetched.filename, fetched.contentType);\n }\n return value;\n}\n\n// ARRAY has no entry in the processor table: the engine zips an object of\n// parallel arrays into rows itself, then processes each row's own props.\nasync function normalizeArray(\n prop: ApProperty,\n value: unknown,\n options: NormalizeOptions,\n): Promise<unknown> {\n const fields = prop.properties;\n if (!fields) return value;\n const zipped: unknown = arrayZipperProcessor(prop as PieceProperty, value);\n if (!Array.isArray(zipped)) return value;\n return Promise.all(\n (zipped as unknown[]).map((item) =>\n isRecord(item) ? normalizePropsValue(fields, item, options) : item,\n ),\n );\n}\n\n// An ApFile is a class instance whose base64 is a prototype getter, and no\n// structured clone carries either; flatten it at the boundary (see ApFileValue).\nfunction plainFile(value: unknown): unknown {\n if (!isRecord(value) || typeof value.filename !== \"string\") return value;\n const { data } = value;\n if (!Buffer.isBuffer(data)) return value;\n const extension =\n typeof value.extension === \"string\"\n ? value.extension\n : extensionOf(value.filename);\n return {\n filename: value.filename,\n ...(extension ? { extension } : {}),\n base64:\n typeof value.base64 === \"string\" ? value.base64 : data.toString(\"base64\"),\n data,\n };\n}\n\nconst table = processors as Record<string, ProcessorFn | undefined>;\n\n// The types whose processor failing means \"not JSON\", not \"not usable\".\nconst JSON_LIKE = new Set([\"JSON\", \"OBJECT\"]);\n\nexport async function normalizeValue(\n prop: ApProperty,\n value: unknown,\n options: NormalizeOptions = {},\n): Promise<unknown> {\n if (value === undefined || value === null) return value;\n if (prop.type === \"ARRAY\") return normalizeArray(prop, value, options);\n if (prop.type === \"FILE\") {\n // Our hydration owns the forms the engine's own processor cannot resolve:\n // attachment and apfile refs, the size cap, and a host-injected fetcher.\n const hydrated = await toApFile(value, options);\n if (typeof hydrated !== \"string\") return hydrated;\n return plainFile(await table.FILE?.(prop as PieceProperty, hydrated));\n }\n const type = prop.type;\n const processor = type ? table[type] : undefined;\n if (!processor) return value;\n const processed = plainFile(await processor(prop as PieceProperty, value));\n // Every other type keeps its promise to the piece: a DATE_TIME prop is an\n // ISO string or nothing, a NUMBER is a number or NaN. JSON is the exception,\n // because the thing most often routed into one is a model's answer, and a\n // model wraps its object in prose. jsonProcessor answers undefined for that,\n // which would drop the value entirely — so hand back what the author wrote\n // and let the piece parse it. The pieces that take model output this way\n // carry their own tolerant parsing for exactly this case.\n if (processed === undefined && type && JSON_LIKE.has(type) && value !== \"\") {\n return value;\n }\n return processed;\n}\n\n// Normalises every configured value with a matching prop schema; keys\n// without a schema (or props without a value) pass through untouched.\nexport async function normalizePropsValue(\n props: Record<string, ApProperty> | undefined,\n values: Record<string, unknown>,\n options: NormalizeOptions = {},\n): Promise<Record<string, unknown>> {\n if (!props || !isRecord(values)) return values;\n const out: Record<string, unknown> = { ...values };\n for (const [name, prop] of Object.entries(props)) {\n if (!(name in out) || !isRecord(prop)) continue;\n const normalized = await normalizeValue(prop, out[name], options);\n if (normalized === undefined) delete out[name];\n else out[name] = normalized;\n }\n return out;\n}\n","// Design-time channel (doc 06 §2.5): builds the PropertyContext handed to\n// DROPDOWN options() / DYNAMIC props() resolvers, and invokes them out-of-band.\nimport {\n getActions,\n getTriggers,\n type ApPiece,\n type ApProperty,\n} from \"../types.js\";\nimport { throwingStub, withTouchTracking } from \"./stubs.js\";\nimport type {\n ConnectionsManager,\n FlowsContext,\n PropertyContext,\n ReactorService,\n ServerContext,\n} from \"@powerhousedao/pieces-framework\";\n\n// The framework's FlowsContext.list, minus the SeekPage cursors the host does\n// not serve: a resolver only ever reads `data`.\nexport interface FlowsProvider {\n list(\n ...params: Parameters<FlowsContext[\"list\"]>\n ): Promise<{ data: unknown[] }>;\n}\n\n// The framework's ConnectionsManager with its return widened: the host serves\n// whatever a connection resolved to, not only the shapes upstream enumerates.\nexport interface ConnectionsProvider {\n get(...params: Parameters<ConnectionsManager[\"get\"]>): Promise<unknown>;\n}\n\nexport type BuiltApPropertyContext = Omit<\n PropertyContext,\n \"flows\" | \"connections\"\n> & {\n flows: FlowsProvider;\n connections: ConnectionsProvider;\n // ctx.reactor: the Powerhouse capability the framework has no member for.\n reactor: ReactorService;\n};\n\nexport interface PropertyContextOptions {\n searchValue?: string;\n // Injected capabilities; anything omitted throws with its member path.\n flows?: FlowsProvider;\n connections?: ConnectionsProvider;\n server?: ServerContext;\n projectId?: string;\n // ctx.reactor for a design-time resolver, on the same terms as at run time:\n // offered to a package piece, a throwing stub to every other.\n reactor?: ReactorService;\n onTouch?: (member: string) => void;\n}\n\nexport interface PropertyContextHandle {\n context: BuiltApPropertyContext;\n // Top-level members the resolver read; `UNDOCUMENTED:<name>` marks unknown reads.\n touched: ReadonlySet<string>;\n}\n\nexport function buildPropertyContext(\n options: PropertyContextOptions = {},\n): PropertyContextHandle {\n const touched = new Set<string>();\n const base: Record<string, unknown> = {\n searchValue: options.searchValue,\n reactor: options.reactor ?? throwingStub(\"reactor\"),\n server: options.server ?? throwingStub(\"server\"),\n project: {\n id: options.projectId ?? \"project\",\n externalId: () => Promise.resolve(options.projectId ?? \"project\"),\n },\n flows: options.flows ?? { list: throwingStub(\"flows.list\") },\n connections: options.connections ?? {\n get: throwingStub(\"connections.get\"),\n },\n };\n const context = withTouchTracking(base, touched, options.onTouch);\n return { context: context as unknown as BuiltApPropertyContext, touched };\n}\n\nexport class NotDynamicPropertyError extends Error {\n constructor(actionName: string, propName: string) {\n super(`Property \"${actionName}.${propName}\" has no dynamic resolver`);\n this.name = \"NotDynamicPropertyError\";\n }\n}\n\nfunction pickResolver(\n prop: ApProperty,\n): ((...args: unknown[]) => unknown) | undefined {\n if (typeof prop.options === \"function\") return prop.options;\n if (typeof prop.props === \"function\") return prop.props;\n return undefined;\n}\n\nexport interface ResolveDynamicPropertyParams {\n piece: ApPiece;\n // Action or trigger name, per kind (default \"action\").\n actionName: string;\n kind?: \"action\" | \"trigger\";\n propName: string;\n // Resolved values of the prop's refresher inputs (auth and sibling props).\n refresherValues?: Record<string, unknown>;\n context: BuiltApPropertyContext;\n}\n\n// Props map of an action or trigger; throws when the owner is unknown.\nexport function ownerProps(\n piece: ApPiece,\n actionName: string,\n kind: \"action\" | \"trigger\" = \"action\",\n): Record<string, ApProperty> {\n const owner =\n kind === \"trigger\"\n ? (getTriggers(piece)[actionName] as\n | { props?: Record<string, ApProperty> }\n | undefined)\n : (getActions(piece)[actionName] as\n | { props?: Record<string, ApProperty> }\n | undefined);\n if (!owner) throw new Error(`No ${kind} \"${actionName}\" on piece`);\n return owner.props ?? {};\n}\n\nexport function findProperty(\n piece: ApPiece,\n actionName: string,\n propName: string,\n kind: \"action\" | \"trigger\" = \"action\",\n): ApProperty {\n const prop = ownerProps(piece, actionName, kind)[propName] as\n | ApProperty\n | undefined;\n if (!prop)\n throw new Error(`No prop \"${propName}\" on ${kind} \"${actionName}\"`);\n return prop;\n}\n\n// Invokes a DROPDOWN options() or DYNAMIC props() resolver. The result is\n// returned untouched: pieces may soft-fail with a disabled DropdownState.\nexport async function resolveDynamicProperty(\n params: ResolveDynamicPropertyParams,\n): Promise<unknown> {\n const { piece, actionName, propName, kind = \"action\" } = params;\n const prop = findProperty(piece, actionName, propName, kind);\n const resolver = pickResolver(prop);\n if (!resolver) throw new NotDynamicPropertyError(actionName, propName);\n return await resolver(params.refresherValues ?? {}, params.context);\n}\n\nexport interface ParsedResolverId {\n packageName: string;\n actionName: string;\n propName: string;\n}\n\n// Inverse of the descriptor's id scheme: activepieces:<pkg>#<action>.<prop>.\nexport function parseDynamicResolverId(id: string): ParsedResolverId {\n const match = /^activepieces:(.+)#(.+)\\.([^.]+)$/.exec(id);\n if (!match) throw new Error(`Invalid dynamic resolver id: ${id}`);\n return { packageName: match[1], actionName: match[2], propName: match[3] };\n}\n\nexport async function resolveByResolverId(\n piece: ApPiece,\n resolverId: string,\n refresherValues: Record<string, unknown>,\n context: BuiltApPropertyContext,\n): Promise<unknown> {\n const { actionName, propName } = parseDynamicResolverId(resolverId);\n return resolveDynamicProperty({\n piece,\n actionName,\n propName,\n refresherValues,\n context,\n });\n}\n","// `ctx.store` served by the host, one call per operation, so a value a piece\n// writes is durable the moment it writes it rather than when the step ends.\n\n// This is the semantic Activepieces pieces are written against — theirs is an\n// HTTP call per get/put/delete — so a loop that checkpoints its cursor resumes.\nimport type { KeyValueStore } from \"./action.js\";\nimport type { StoreScopeName } from \"./store-scope.js\";\nimport { STORE_DELETE, STORE_GET, STORE_PUT } from \"../worker/protocol.js\";\nimport { callHost } from \"../worker/host-call.js\";\nimport { jsonSafe } from \"../worker/json-safe.js\";\n\n// The host writes JSON, so a value is flattened here rather than at the point\n// it lands. A piece that stores a Date reads back a string either way, whether\n// or not a durable store is configured — and whatever carries the message.\nexport class RemoteKeyValueStore implements KeyValueStore {\n async put(\n key: string,\n value: unknown,\n scope?: StoreScopeName,\n ): Promise<unknown> {\n const stored = jsonSafe(value);\n await callHost(STORE_PUT, { key, value: stored, scope });\n return stored;\n }\n\n get(key: string, scope?: StoreScopeName): Promise<unknown> {\n return callHost(STORE_GET, { key, scope });\n }\n\n async delete(key: string, scope?: StoreScopeName): Promise<void> {\n await callHost(STORE_DELETE, { key, scope });\n }\n}\n","// ctx.output.update: the piece reporting progress before it returns. A long\n// step is otherwise opaque until the moment it finishes.\nimport { notifyHost } from \"../worker/host-call.js\";\nimport { jsonSafe } from \"../worker/json-safe.js\";\nimport { OUTPUT_UPDATE } from \"../worker/protocol.js\";\n\nexport interface PartialOutput {\n update(output: unknown): Promise<void>;\n}\n\n// Resolves immediately: a tap the step waits on is a tap that can stall it,\n// which is the one thing plan/08 §7.8 rules out.\n\n// A notification carries no request id, and the worker is reused. A piece that\n// keeps `ctx` and updates from a timer would otherwise report progress against\n// whichever step is running by then, so the tap is closed when its step ends.\nexport class RemoteOutput implements PartialOutput {\n private open = true;\n\n update(output: unknown): Promise<void> {\n if (this.open) notifyHost(OUTPUT_UPDATE, jsonSafe(output));\n return Promise.resolve();\n }\n\n close(): void {\n this.open = false;\n }\n}\n","// Piece console output, forwarded to the host while the step runs. The child\n// is forked with its stdio discarded, so without this a piece's logs vanish.\nimport { format } from \"node:util\";\nimport { notifyHost } from \"./host-call.js\";\nimport { LOG_WRITE, type PieceLogEntry } from \"./protocol.js\";\n\n// A runaway piece can log in a loop; the channel is shared with the step's own\n// result, so both the size of an entry and the number of them are capped.\n\n// Without the count, a loop enqueues IPC messages faster than the host drains\n// them and the result waits behind the backlog until the step times out.\nconst MAX_MESSAGE_LENGTH = 8_192;\nconst MAX_ENTRIES_PER_REQUEST = 1_000;\n\nconst LEVELS = [\"log\", \"info\", \"warn\", \"error\", \"debug\"] as const;\n\ntype Level = (typeof LEVELS)[number];\n\n// Installs the patch for one request and returns its undo. Logs written after\n// the step returned belong to no step, which is why the scope is this narrow.\nexport function captureConsole(): () => void {\n const original = new Map<Level, (...args: unknown[]) => void>();\n let sent = 0;\n\n for (const level of LEVELS) {\n const previous = console[level] as (...args: unknown[]) => void;\n original.set(level, previous);\n console[level] = (...args: unknown[]) => {\n if (sent > MAX_ENTRIES_PER_REQUEST) return;\n sent += 1;\n // The last one says why the rest are missing, so a truncated log does\n // not read as a step that fell silent.\n const message =\n sent > MAX_ENTRIES_PER_REQUEST\n ? `[log truncated after ${MAX_ENTRIES_PER_REQUEST} entries]`\n : format(...args).slice(0, MAX_MESSAGE_LENGTH);\n notifyHost(LOG_WRITE, {\n level,\n message,\n at: Date.now(),\n } satisfies PieceLogEntry);\n };\n }\n\n return () => {\n for (const [level, previous] of original) {\n console[level] = previous as typeof console.log;\n }\n };\n}\n","// Worker child: loads piece bundles and executes actions in an isolated\n// process, so piece side-effects (TLS env poisoning, crashes) never reach the host.\nimport {\n buildActionContext,\n InMemoryConnectionsProvider,\n InMemoryKeyValueStore,\n UnsupportedContextMemberError,\n} from \"../context/action.js\";\nimport { RemoteKeyValueStore } from \"../context/remote-store.js\";\nimport { RemoteReactorService } from \"../context/reactor.js\";\nimport { RemoteOutput } from \"../context/remote-output.js\";\nimport { captureConsole } from \"./logs.js\";\nimport { jsonSafe } from \"./json-safe.js\";\nimport { formatPieceError } from \"@powerhousedao/pieces-framework/host\";\nimport { redactError, redactMessage } from \"./redact.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { buildCheckConnectionContext } from \"../context/check.js\";\nimport { DataUriFilesService, StagedFilesService } from \"../context/files.js\";\nimport {\n normalizePropsValue,\n type NormalizeOptions,\n} from \"../context/normalize.js\";\nimport {\n buildPropertyContext,\n findProperty,\n resolveDynamicProperty,\n} from \"../context/props.js\";\nimport { buildTriggerContext, runTriggerHook } from \"../context/trigger.js\";\nimport { buildDescriptor, describeProperties } from \"../descriptor.js\";\nimport { loadPiece, loadPieceFromDir, type LoadedPiece } from \"../loader.js\";\nimport { getActions, getTriggers, type ApProperty } from \"../types.js\";\nimport { installEgressGuard, runWithEgressPolicy } from \"./egress.js\";\nimport type {\n StagedInput,\n PieceModuleRef,\n CheckConnectionMessage,\n CheckConnectionOutcome,\n DescribePieceMessage,\n ResolveOptionsMessage,\n RunMessage,\n SerializedPieceError,\n TriggerHookMessage,\n WorkerRequestMessage,\n WorkerResponse,\n} from \"./protocol.js\";\n\n// Before any piece module is loaded, so a piece cannot keep a pristine copy of\n// the socket layer from a request that carried no policy.\ninstallEgressGuard();\n\nconst loadedPieces = new Map<string, Promise<LoadedPiece>>();\n// One store per scope, alive for the worker's lifetime (in-memory phase:\n// state survives runs but not worker replacement).\nconst stores = new Map<string, InMemoryKeyValueStore>();\n\nfunction storeForScope(scope: string): InMemoryKeyValueStore {\n let store = stores.get(scope);\n if (!store) {\n store = new InMemoryKeyValueStore();\n stores.set(scope, store);\n }\n return store;\n}\n\n// The module this request names, and the cache key for it. A package piece\n// arrives as one file; a fetched bundle as the directory holding it.\nfunction pieceRefKey(ref: PieceModuleRef): string {\n const key = ref.entryPath ?? ref.bundleDir;\n if (!key) {\n throw new Error(\"Request names no piece module (entryPath or bundleDir)\");\n }\n return key;\n}\n\nfunction loadCached(ref: PieceModuleRef): Promise<LoadedPiece> {\n const key = pieceRefKey(ref);\n let loading = loadedPieces.get(key);\n if (!loading) {\n loading = ref.entryPath ? loadPiece(key) : loadPieceFromDir(key);\n loadedPieces.set(key, loading);\n }\n return loading;\n}\n\n// The secret values this request carried, if any. Redacting here rather than\n// on the host means the host process never holds them in an error object.\nfunction redactValuesOf(message: WorkerRequestMessage): string[] {\n const request = message.request as { redactValues?: string[] };\n return request.redactValues ?? [];\n}\n\nfunction serializeError(\n error: unknown,\n values: string[] = [],\n): SerializedPieceError {\n const properties: Record<string, unknown> = {};\n if (typeof error === \"object\" && error !== null) {\n for (const key of Object.keys(error)) {\n properties[key] = jsonSafe((error as Record<string, unknown>)[key]);\n }\n }\n // The framework's own formatter first: it lifts an HTTP status, the request\n // and response, and a message out of an HTML error page. Redaction stays last.\n const { __apErrorVersion, message, errorName, ...http } =\n formatPieceError(error);\n return {\n name:\n (typeof error === \"object\" && error !== null && error.constructor.name) ||\n errorName ||\n \"Error\",\n message: redactMessage(message, { values }),\n properties: redactError(\n { ...properties, ...(jsonSafe(http) as Record<string, unknown>) },\n { values },\n ) as Record<string, unknown>,\n unsupportedMember:\n error instanceof UnsupportedContextMemberError ? error.member : undefined,\n };\n}\n\n// Read-and-clear the piece-set TLS override so each run reports its own poisoning.\nfunction consumeTlsFlag(): boolean {\n const poisoned = process.env.NODE_TLS_REJECT_UNAUTHORIZED === \"0\";\n delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;\n return poisoned;\n}\n\nasync function handleResolveOptions(\n message: ResolveOptionsMessage,\n): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const { context, touched } = buildPropertyContext({\n searchValue: request.searchValue,\n // Design-time default: an empty flows listing instead of a throwing stub.\n flows: { list: () => Promise.resolve({ data: [] }) },\n ...(request.reactorAccess ? { reactor: new RemoteReactorService() } : {}),\n });\n const refresherValues = {\n ...(request.auth !== undefined ? { auth: request.auth } : {}),\n ...request.refresherValues,\n };\n const prop = findProperty(\n piece,\n request.actionName,\n request.propName,\n request.kind,\n );\n const output = await resolveDynamicProperty({\n piece,\n actionName: request.actionName,\n kind: request.kind,\n propName: request.propName,\n refresherValues,\n context,\n });\n // DYNAMIC props() yields raw piece properties (with resolver functions);\n // the editor only ever sees descriptors, so translate before crossing IPC.\n const isDynamic =\n typeof prop.props === \"function\" && typeof prop.options !== \"function\";\n return {\n id: message.id,\n type: \"result\",\n output: isDynamic\n ? describeProperties(output as Record<string, ApProperty> | undefined)\n : jsonSafe(output),\n touched: [...touched],\n tlsPoisoned: consumeTlsFlag(),\n };\n}\n\n// Reads a FILE prop's attachment ref from the copy the host staged on disk.\n// The fork shares the filesystem with its parent, so this is what keeps a\n// 50 MB scan out of the IPC channel in both directions.\nfunction stagedInputResolver(\n inputs: StagedInput[] | undefined,\n): NormalizeOptions[\"resolveRef\"] {\n if (!inputs || inputs.length === 0) return undefined;\n const byRef = new Map(inputs.map((input) => [input.ref, input]));\n return async (ref: string) => {\n const staged = byRef.get(ref);\n if (!staged) {\n throw new Error(`No staged file for reference \"${ref}\"`);\n }\n return {\n data: await readFile(staged.path),\n filename: staged.fileName,\n contentType: staged.contentType,\n };\n };\n}\n\nasync function handleRun(message: RunMessage): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const action = getActions(piece)[request.actionName] as\n | ReturnType<typeof getActions>[string]\n | undefined;\n if (!action) {\n throw new Error(\n `No action \"${request.actionName}\" in ${pieceRefKey(request)}`,\n );\n }\n const files = request.stagingDir\n ? new StagedFilesService(request.stagingDir)\n : new DataUriFilesService();\n // A durable store answers every get/put over the call channel, so a write\n // survives this worker; without one the value lives only in this heap.\n const durableStore = request.durableStore\n ? new RemoteKeyValueStore()\n : undefined;\n const liveOutput = request.liveOutput ? new RemoteOutput() : undefined;\n // Host-served reactor access, for a piece that ships inside a reactor package.\n const reactor = request.reactorAccess\n ? new RemoteReactorService()\n : undefined;\n // Before the props are normalised, not after: a processor that cannot coerce\n // says so on console.error, and the worker's stdio goes nowhere.\n const restoreConsole = request.captureLogs ? captureConsole() : undefined;\n const { context, touched } = buildActionContext({\n propsValue: await normalizePropsValue(action.props, request.propsValue, {\n resolveRef: stagedInputResolver(request.stagedInputs),\n }),\n auth: request.auth,\n store:\n durableStore ??\n (request.storeScope ? storeForScope(request.storeScope) : undefined),\n files,\n connections: request.connections\n ? new InMemoryConnectionsProvider(request.connections)\n : undefined,\n output: liveOutput,\n reactor,\n executionType: request.executionType,\n identity: request.identity,\n });\n let output: unknown;\n try {\n output = await action.run(context);\n } finally {\n restoreConsole?.();\n liveOutput?.close();\n }\n return {\n id: message.id,\n type: \"result\",\n output: jsonSafe(output),\n ...(files instanceof StagedFilesService && files.staged().length > 0\n ? { files: files.staged() }\n : {}),\n touched: [...touched],\n tlsPoisoned: consumeTlsFlag(),\n };\n}\n\nasync function handleTriggerHook(\n message: TriggerHookMessage,\n): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const trigger = getTriggers(piece)[request.triggerName] as\n | ReturnType<typeof getTriggers>[string]\n | undefined;\n if (!trigger) {\n throw new Error(\n `No trigger \"${request.triggerName}\" in bundle ${request.bundleDir}`,\n );\n }\n // The durable store answers every get/put over the call channel, so a long\n // onEnable checkpoints: registration ids survive a crash mid-hook.\n const snapshot = request.durableStore\n ? undefined\n : new InMemoryKeyValueStore(request.storeState);\n const runsPiece = request.hook === \"run\" || request.hook === \"test\";\n const handle = buildTriggerContext({\n propsValue: await normalizePropsValue(trigger.props, request.propsValue),\n auth: request.auth,\n store: snapshot ?? new RemoteKeyValueStore(),\n hostPartitionedStore: request.durableStore,\n // Test hooks write under a separate prefix, never the live cursor.\n storePrefix: request.hook === \"test\" ? \"test\" : \"\",\n identity: request.identity,\n isRepublish: request.isRepublish,\n payload: request.payload,\n webhookUrl: request.webhookUrl,\n server: request.server,\n files: runsPiece ? new DataUriFilesService() : undefined,\n });\n const output = await runTriggerHook(trigger, request.hook, handle);\n return {\n id: message.id,\n type: \"result\",\n output: jsonSafe(output),\n touched: [...handle.touched],\n tlsPoisoned: consumeTlsFlag(),\n // Only the snapshot path has state to hand back; a durable store already\n // committed everything the hook wrote.\n ...(snapshot\n ? { storeState: jsonSafe(snapshot.snapshot()) as Record<string, unknown> }\n : {}),\n schedules: handle.schedules,\n listeners: handle.listeners,\n };\n}\n\nasync function handleCheckConnection(\n message: CheckConnectionMessage,\n): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const app = piece as {\n checkConnection?: (context: unknown) => unknown;\n };\n if (typeof app.checkConnection !== \"function\") {\n const outcome: CheckConnectionOutcome = { declared: false };\n return {\n id: message.id,\n type: \"result\",\n output: outcome,\n touched: [],\n tlsPoisoned: consumeTlsFlag(),\n };\n }\n const { context, touched } = buildCheckConnectionContext({\n auth: request.auth,\n });\n const result = await app.checkConnection(context);\n const outcome: CheckConnectionOutcome = {\n declared: true,\n result: jsonSafe(result),\n };\n return {\n id: message.id,\n type: \"result\",\n output: outcome,\n touched: [...touched],\n tlsPoisoned: consumeTlsFlag(),\n };\n}\n\nasync function handleDescribe(\n message: DescribePieceMessage,\n): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const descriptor = buildDescriptor(piece, {\n packageName: request.packageName,\n version: request.version,\n });\n return {\n id: message.id,\n type: \"result\",\n // A prop's defaultValue is piece-authored; jsonSafe keeps a non-cloneable\n // one from failing the IPC send.\n output: jsonSafe(descriptor),\n touched: [],\n tlsPoisoned: consumeTlsFlag(),\n };\n}\n\nfunction isWorkerMessage(value: unknown): value is WorkerRequestMessage {\n if (typeof value !== \"object\" || value === null) return false;\n const type = (value as { type?: unknown }).type;\n return (\n type === \"run\" ||\n type === \"resolve-options\" ||\n type === \"trigger-hook\" ||\n type === \"check-connection\" ||\n type === \"describe\"\n );\n}\n\nfunction dispatch(message: WorkerRequestMessage): Promise<WorkerResponse> {\n switch (message.type) {\n case \"run\":\n return handleRun(message);\n case \"resolve-options\":\n return handleResolveOptions(message);\n case \"trigger-hook\":\n return handleTriggerHook(message);\n case \"check-connection\":\n return handleCheckConnection(message);\n case \"describe\":\n return handleDescribe(message);\n }\n}\n\nprocess.on(\"message\", (message: unknown) => {\n if (!isWorkerMessage(message)) return;\n // Deferred so a synchronous throw — a malformed egress policy — becomes a\n // rejection the handler below reports, instead of killing the child.\n const handler = Promise.resolve().then(() =>\n runWithEgressPolicy(message.request.egress, () => dispatch(message)),\n );\n handler\n .catch(\n (error: unknown): WorkerResponse => ({\n id: message.id,\n type: \"error\",\n error: serializeError(error, redactValuesOf(message)),\n tlsPoisoned: consumeTlsFlag(),\n }),\n )\n .then((response) => process.send?.(response))\n .catch(() => process.exit(1));\n});\n"],"mappings":";;;;;;AASA,MAAM,+BAA+B;AASrC,MAAM,0BAAU,IAAI,KAAsB;AAC1C,IAAI,SAAS;AACb,IAAI,YAAY;AAEhB,IAAa,gBAAb,cAAmC,MAAM;CACvC,YAAY,QAAgB,QAAgB;AAC1C,QAAM,cAAc,OAAO,YAAY,SAAS;AAChD,OAAK,OAAO;;;AAIhB,IAAa,uBAAb,cAA0C,MAAM;CAC9C,YAAY,QAAgB,WAAmB;AAC7C,QAAM,cAAc,OAAO,yBAAyB,UAAU,IAAI;AAClE,OAAK,OAAO;;;AAIhB,SAAS,mBAAmB,OAA2C;AACrE,QACE,OAAO,UAAU,YACjB,UAAU,QACT,MAA6B,SAAS;;AAM3C,SAAS,kBAAwB;AAC/B,KAAI,UAAW;AACf,aAAY;AACZ,SAAQ,GAAG,YAAY,YAAqB;AAC1C,MAAI,CAAC,mBAAmB,QAAQ,CAAE;EAClC,MAAM,QAAQ,QAAQ,IAAI,QAAQ,GAAG;AACrC,MAAI,CAAC,MAAO;AACZ,UAAQ,OAAO,QAAQ,GAAG;AAC1B,eAAa,MAAM,MAAM;AACzB,M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nC,KAAK,mBACH,QAAO,sBAAsB,QAAQ;EACvC,KAAK,WACH,QAAO,eAAe,QAAQ;;;AAIpC,QAAQ,GAAG,YAAY,YAAqB;AAC1C,KAAI,CAAC,gBAAgB,QAAQ,CAAE;AAGf,SAAQ,SAAS,CAAC,WAChC,oBAAoB,QAAQ,QAAQ,cAAc,SAAS,QAAQ,CAAC,CACrE,CAEE,OACE,WAAoC;EACnC,IAAI,QAAQ;EACZ,MAAM;EACN,OAAO,eAAe,OAAO,eAAe,QAAQ,CAAC;EACrD,aAAa,gBAAgB;EAC9B,EACF,CACA,MAAM,aAAa,QAAQ,OAAO,SAAS,CAAC,CAC5C,YAAY,QAAQ,KAAK,EAAE,CAAC;EAC/B"}
1
+ {"version":3,"file":"worker-entry.js","names":[],"sources":["../src/pieces/activepieces/worker/host-call.ts","../src/pieces/activepieces/context/reactor.ts","../src/pieces/activepieces/context/check.ts","../src/pieces/activepieces/context/normalize.ts","../src/pieces/activepieces/context/props.ts","../src/pieces/activepieces/context/remote-store.ts","../src/pieces/activepieces/context/remote-output.ts","../src/pieces/activepieces/worker/logs.ts","../src/pieces/activepieces/worker/entry.ts"],"sourcesContent":["// The child's half of the call channel: how piece code reaches durable host\n// state mid-step, instead of handing everything back when the step returns.\n\n// Modelled on their engine RPC (createRpcClient): a method name, a payload, an\n// id, and failures returned as data rather than thrown across the boundary.\nimport type { HostCallResponse } from \"./protocol.js\";\n\n// A host call is a local IPC round trip. Ten seconds is already pathological;\n// the step's own timeout is the outer bound and kills the worker outright.\nconst DEFAULT_HOST_CALL_TIMEOUT_MS = 10_000;\n\ninterface Pending {\n method: string;\n resolve: (value: unknown) => void;\n reject: (error: Error) => void;\n timer: NodeJS.Timeout;\n}\n\nconst pending = new Map<number, Pending>();\nlet nextId = 1;\nlet listening = false;\n\nexport class HostCallError extends Error {\n constructor(method: string, detail: string) {\n super(`Host call \"${method}\" failed: ${detail}`);\n this.name = \"HostCallError\";\n }\n}\n\nexport class HostCallTimeoutError extends Error {\n constructor(method: string, timeoutMs: number) {\n super(`Host call \"${method}\" got no answer within ${timeoutMs}ms`);\n this.name = \"HostCallTimeoutError\";\n }\n}\n\nfunction isHostCallResponse(value: unknown): value is HostCallResponse {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { type?: unknown }).type === \"host-result\"\n );\n}\n\n// Registered once, on the same channel the job messages arrive on. The job\n// dispatcher ignores `host-result` because it only knows its own request types.\nfunction ensureListening(): void {\n if (listening) return;\n listening = true;\n process.on(\"message\", (message: unknown) => {\n if (!isHostCallResponse(message)) return;\n const entry = pending.get(message.id);\n if (!entry) return;\n pending.delete(message.id);\n clearTimeout(entry.timer);\n if (message.error !== undefined) {\n entry.reject(new HostCallError(entry.method, message.error));\n return;\n }\n entry.resolve(message.value);\n });\n}\n\nexport function callHost<T = unknown>(\n method: string,\n payload: unknown,\n timeoutMs: number = DEFAULT_HOST_CALL_TIMEOUT_MS,\n): Promise<T> {\n if (!process.send) {\n return Promise.reject(\n new HostCallError(method, \"the worker has no channel to its host\"),\n );\n }\n ensureListening();\n const id = nextId++;\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => {\n pending.delete(id);\n reject(new HostCallTimeoutError(method, timeoutMs));\n }, timeoutMs);\n pending.set(id, {\n method,\n resolve: resolve as (value: unknown) => void,\n reject,\n timer,\n });\n process.send?.({ id, type: \"host-call\", method, payload });\n });\n}\n\n// Test seam: a worker replaced between suites must not inherit pending calls.\nexport function resetHostCalls(): void {\n for (const entry of pending.values()) clearTimeout(entry.timer);\n pending.clear();\n}\n\n// The one-way half: a report with no answer to wait for. It cannot fail from\n// the piece's side, so a missing channel is dropped rather than raised.\nexport function notifyHost(method: string, payload: unknown): void {\n try {\n process.send?.({ type: \"host-notify\", method, payload });\n } catch {\n // `process.send` stays defined after the channel closes and throws. A tap\n // that threw here would be a tap that changed the step.\n }\n}\n","// `ctx.reactor` — the one way piece code reaches the reactor it runs inside.\n\n// Pieces are isolated from the host on purpose, so this is not a client: it is\n// the same call channel `ctx.store` uses (doc 08 §10), and every method is a\n// round trip the host answers. The host installs it only for a piece that came\n// from an installed reactor package; a bundle fetched from a registry gets the\n// throwing stub instead, and finds out by name that it has no reactor.\nimport { callHost } from \"../worker/host-call.js\";\nimport type {\n ReactorCreateInput,\n ReactorDocumentSummary,\n ReactorExecuteInput,\n ReactorFindInput,\n ReactorModelDetail,\n ReactorModelSummary,\n ReactorService,\n} from \"@powerhousedao/pieces-framework\";\nimport {\n REACTOR_CREATE,\n REACTOR_EXECUTE,\n REACTOR_FIND,\n REACTOR_GET,\n REACTOR_MODEL,\n REACTOR_MODELS,\n} from \"../worker/protocol.js\";\n\n// The service contract and its input/output shapes live in the framework, so a\n// piece and the host it calls are typed against one declaration.\nexport type {\n ReactorActionInput,\n ReactorCreateInput,\n ReactorDocumentSummary,\n ReactorExecuteInput,\n ReactorFindInput,\n ReactorModelActionSchema,\n ReactorModelDetail,\n ReactorModelSummary,\n ReactorService,\n} from \"@powerhousedao/pieces-framework\";\n\n// The worker's half: every method is one host call, named so a failure reads\n// as the operation the piece asked for.\nexport class RemoteReactorService implements ReactorService {\n models(): Promise<ReactorModelSummary[]> {\n return callHost<ReactorModelSummary[]>(REACTOR_MODELS, {});\n }\n\n model(documentType: string): Promise<ReactorModelDetail> {\n return callHost<ReactorModelDetail>(REACTOR_MODEL, { documentType });\n }\n\n get(input: {\n documentId: string;\n branch?: string;\n }): Promise<ReactorDocumentSummary> {\n return callHost<ReactorDocumentSummary>(REACTOR_GET, input);\n }\n\n find(input: ReactorFindInput): Promise<ReactorDocumentSummary[]> {\n return callHost<ReactorDocumentSummary[]>(REACTOR_FIND, input);\n }\n\n create(input: ReactorCreateInput): Promise<ReactorDocumentSummary> {\n return callHost<ReactorDocumentSummary>(REACTOR_CREATE, input);\n }\n\n execute(input: ReactorExecuteInput): Promise<ReactorDocumentSummary> {\n return callHost<ReactorDocumentSummary>(REACTOR_EXECUTE, input);\n }\n}\n","// Context handed to a piece's connection check. The framework has no\n// checkConnection hook: auth.validate({auth, server}) is the whole contract.\nimport { throwingStub, withTouchTracking } from \"./stubs.js\";\nimport type { AuthValidationServerContext } from \"@powerhousedao/pieces-framework\";\n\nexport interface CheckConnectionContextOptions {\n auth?: unknown;\n // apiUrl / publicUrl when the host serves them; mintOidcToken always throws,\n // since no reactor mints tokens for a piece's validate().\n server?: Omit<AuthValidationServerContext, \"mintOidcToken\">;\n onTouch?: (member: string) => void;\n}\n\nexport interface BuiltApCheckConnectionContext {\n auth: unknown;\n server: AuthValidationServerContext;\n}\n\nexport interface CheckConnectionContextHandle {\n context: BuiltApCheckConnectionContext;\n // Top-level members the check read; `UNDOCUMENTED:<name>` marks unknown reads.\n touched: ReadonlySet<string>;\n}\n\nexport function buildCheckConnectionContext(\n options: CheckConnectionContextOptions = {},\n): CheckConnectionContextHandle {\n const touched = new Set<string>();\n const base: Record<string, unknown> = {\n auth: options.auth,\n server: options.server\n ? {\n ...options.server,\n mintOidcToken: throwingStub(\"server.mintOidcToken\"),\n }\n : throwingStub(\"server\"),\n };\n const context = withTouchTracking(base, touched, options.onTouch);\n return {\n context: context as unknown as BuiltApCheckConnectionContext,\n touched,\n };\n}\n","// Run-time coercion of stored config values into the shapes pieces expect: the\n// engine's own property processors, with our file hydration in front of theirs.\nimport type { PieceProperty } from \"@powerhousedao/pieces-framework\";\nimport {\n arrayZipperProcessor,\n processors,\n type ProcessorFn,\n} from \"@powerhousedao/pieces-framework/host\";\nimport type { ApProperty } from \"../types.js\";\nimport {\n assertWithinLimit,\n DEFAULT_MAX_FILE_BYTES,\n maxFileBytes,\n} from \"./limits.js\";\n\n// Framework ApFile (filename, data, extension, base64) as a plain object so\n// it survives IPC and structured cloning.\nexport interface ApFileValue {\n filename: string;\n extension?: string;\n base64: string;\n data: Buffer;\n}\n\nexport interface FetchedFile {\n data: Buffer;\n filename?: string;\n contentType?: string;\n}\n\nexport interface NormalizeOptions {\n // Resolves a URL-valued FILE prop; defaults to fetch() with a size cap.\n fetchFile?: (url: string) => Promise<FetchedFile>;\n // Resolves a reference-valued FILE prop (attachment:// or apfile://). The\n // worker resolves these from files the host staged on disk, so the bytes\n // never cross IPC.\n resolveRef?: (ref: string) => Promise<FetchedFile>;\n}\n\n// Re-exported for compatibility; the ceiling itself lives in limits.ts so the\n// inbound and outbound paths cannot drift apart.\nexport const MAX_FILE_BYTES = DEFAULT_MAX_FILE_BYTES;\nconst FETCH_TIMEOUT_MS = 30_000;\n\n// A FILE prop whose value is a reference the host has to resolve.\nconst FILE_REF = /^(?:attachment|apfile):\\/\\//i;\n\nexport class FileFetchError extends Error {\n constructor(url: string, reason: string) {\n super(`Could not fetch FILE prop \"${url}\": ${reason}`);\n this.name = \"FileFetchError\";\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\nconst DATA_URI = /^data:([^;,]*)((?:;[^;,]*)*),([\\s\\S]*)$/;\n\nfunction extensionOf(filename: string): string | undefined {\n const dot = filename.lastIndexOf(\".\");\n return dot > 0 && dot < filename.length - 1\n ? filename.slice(dot + 1)\n : undefined;\n}\n\nconst MIME_EXTENSIONS: Record<string, string> = {\n \"image/png\": \"png\",\n \"image/jpeg\": \"jpg\",\n \"image/gif\": \"gif\",\n \"image/webp\": \"webp\",\n \"image/svg+xml\": \"svg\",\n \"application/pdf\": \"pdf\",\n \"application/json\": \"json\",\n \"text/plain\": \"txt\",\n \"text/csv\": \"csv\",\n};\n\nfunction toFileValue(\n data: Buffer,\n filename: string | undefined,\n contentType: string | undefined,\n): ApFileValue {\n const mime = contentType?.split(\";\")[0].trim().toLowerCase();\n const mimeExtension = mime ? MIME_EXTENSIONS[mime] : undefined;\n const name =\n filename && filename !== \"\"\n ? filename\n : `file${mimeExtension ? `.${mimeExtension}` : \"\"}`;\n const extension = extensionOf(name) ?? mimeExtension;\n return {\n filename: name,\n ...(extension ? { extension } : {}),\n base64: data.toString(\"base64\"),\n data,\n };\n}\n\nfunction filenameFromDisposition(header: string | null): string | undefined {\n if (!header) return undefined;\n const utf8 = /filename\\*=(?:UTF-8'')?([^;]+)/i.exec(header);\n if (utf8) {\n try {\n return decodeURIComponent(utf8[1].trim().replace(/^\"|\"$/g, \"\"));\n } catch {\n // fall through to the plain form\n }\n }\n const plain = /filename=\"?([^\";]+)\"?/i.exec(header);\n return plain ? plain[1].trim() : undefined;\n}\n\nasync function defaultFetchFile(url: string): Promise<FetchedFile> {\n let response: Response;\n try {\n response = await fetch(url, {\n signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),\n });\n } catch (error) {\n throw new FileFetchError(\n url,\n error instanceof Error ? error.message : String(error),\n );\n }\n if (!response.ok) throw new FileFetchError(url, `HTTP ${response.status}`);\n const limit = maxFileBytes();\n const declared = Number(response.headers.get(\"content-length\"));\n if (Number.isFinite(declared) && declared > limit) {\n throw new FileFetchError(url, `${declared} bytes exceeds ${limit}`);\n }\n const data = Buffer.from(await response.arrayBuffer());\n if (data.byteLength > limit) {\n throw new FileFetchError(url, `${data.byteLength} bytes exceeds ${limit}`);\n }\n let filename = filenameFromDisposition(\n response.headers.get(\"content-disposition\"),\n );\n if (!filename) {\n const segment = new URL(url).pathname.split(\"/\").filter(Boolean).pop();\n if (segment) filename = decodeURIComponent(segment);\n }\n return {\n data,\n filename,\n contentType: response.headers.get(\"content-type\") ?? undefined,\n };\n}\n\nfunction isFileShaped(value: unknown): value is ApFileValue {\n return (\n isRecord(value) &&\n typeof value.filename === \"string\" &&\n (typeof value.base64 === \"string\" || Buffer.isBuffer(value.data))\n );\n}\n\n// URL or data URI → ApFile shape; already-shaped objects are completed\n// (data/base64 derived from each other); anything else passes through.\nexport async function toApFile(\n value: unknown,\n options: NormalizeOptions = {},\n): Promise<unknown> {\n if (isFileShaped(value)) {\n const data = Buffer.isBuffer(value.data)\n ? value.data\n : Buffer.from(value.base64, \"base64\");\n // The cap applies to every branch, not just the fetched one: an oversized\n // data URI or file-shaped object would otherwise slip past it.\n assertWithinLimit(data.byteLength);\n const extension = value.extension ?? extensionOf(value.filename);\n return {\n ...value,\n ...(extension ? { extension } : {}),\n base64:\n typeof value.base64 === \"string\"\n ? value.base64\n : data.toString(\"base64\"),\n data,\n };\n }\n if (typeof value !== \"string\") return value;\n const trimmed = value.trim();\n if (trimmed === \"\") return undefined;\n const dataUri = DATA_URI.exec(trimmed);\n if (dataUri) {\n const [, mime, params, payload] = dataUri;\n const isBase64 = /;base64/i.test(params);\n const data = isBase64\n ? Buffer.from(payload, \"base64\")\n : Buffer.from(decodeURIComponent(payload), \"utf8\");\n assertWithinLimit(data.byteLength);\n const nameParam = /;name=([^;]+)/i.exec(params)?.[1];\n return toFileValue(\n data,\n nameParam ? decodeURIComponent(nameParam) : undefined,\n mime || undefined,\n );\n }\n if (FILE_REF.test(trimmed)) {\n if (!options.resolveRef) {\n throw new FileFetchError(\n trimmed,\n \"no attachment resolver is available in this context\",\n );\n }\n const resolved = await options.resolveRef(trimmed);\n assertWithinLimit(resolved.data.byteLength);\n return toFileValue(resolved.data, resolved.filename, resolved.contentType);\n }\n if (/^https?:\\/\\//i.test(trimmed)) {\n const fetched = await (options.fetchFile ?? defaultFetchFile)(trimmed);\n return toFileValue(fetched.data, fetched.filename, fetched.contentType);\n }\n return value;\n}\n\n// ARRAY has no entry in the processor table: the engine zips an object of\n// parallel arrays into rows itself, then processes each row's own props.\nasync function normalizeArray(\n prop: ApProperty,\n value: unknown,\n options: NormalizeOptions,\n): Promise<unknown> {\n const fields = prop.properties;\n if (!fields) return value;\n const zipped: unknown = arrayZipperProcessor(prop as PieceProperty, value);\n if (!Array.isArray(zipped)) return value;\n return Promise.all(\n (zipped as unknown[]).map((item) =>\n isRecord(item) ? normalizePropsValue(fields, item, options) : item,\n ),\n );\n}\n\n// An ApFile is a class instance whose base64 is a prototype getter, and no\n// structured clone carries either; flatten it at the boundary (see ApFileValue).\nfunction plainFile(value: unknown): unknown {\n if (!isRecord(value) || typeof value.filename !== \"string\") return value;\n const { data } = value;\n if (!Buffer.isBuffer(data)) return value;\n const extension =\n typeof value.extension === \"string\"\n ? value.extension\n : extensionOf(value.filename);\n return {\n filename: value.filename,\n ...(extension ? { extension } : {}),\n base64:\n typeof value.base64 === \"string\" ? value.base64 : data.toString(\"base64\"),\n data,\n };\n}\n\nconst table = processors as Record<string, ProcessorFn | undefined>;\n\n// The types whose processor failing means \"not JSON\", not \"not usable\".\nconst JSON_LIKE = new Set([\"JSON\", \"OBJECT\"]);\n\nexport async function normalizeValue(\n prop: ApProperty,\n value: unknown,\n options: NormalizeOptions = {},\n): Promise<unknown> {\n if (value === undefined || value === null) return value;\n if (prop.type === \"ARRAY\") return normalizeArray(prop, value, options);\n if (prop.type === \"FILE\") {\n // Our hydration owns the forms the engine's own processor cannot resolve:\n // attachment and apfile refs, the size cap, and a host-injected fetcher.\n const hydrated = await toApFile(value, options);\n if (typeof hydrated !== \"string\") return hydrated;\n return plainFile(await table.FILE?.(prop as PieceProperty, hydrated));\n }\n const type = prop.type;\n const processor = type ? table[type] : undefined;\n if (!processor) return value;\n const processed = plainFile(await processor(prop as PieceProperty, value));\n // Every other type keeps its promise to the piece: a DATE_TIME prop is an\n // ISO string or nothing, a NUMBER is a number or NaN. JSON is the exception,\n // because the thing most often routed into one is a model's answer, and a\n // model wraps its object in prose. jsonProcessor answers undefined for that,\n // which would drop the value entirely — so hand back what the author wrote\n // and let the piece parse it. The pieces that take model output this way\n // carry their own tolerant parsing for exactly this case.\n if (processed === undefined && type && JSON_LIKE.has(type) && value !== \"\") {\n return value;\n }\n return processed;\n}\n\n// Normalises every configured value with a matching prop schema; keys\n// without a schema (or props without a value) pass through untouched.\nexport async function normalizePropsValue(\n props: Record<string, ApProperty> | undefined,\n values: Record<string, unknown>,\n options: NormalizeOptions = {},\n): Promise<Record<string, unknown>> {\n if (!props || !isRecord(values)) return values;\n const out: Record<string, unknown> = { ...values };\n for (const [name, prop] of Object.entries(props)) {\n if (!(name in out) || !isRecord(prop)) continue;\n const normalized = await normalizeValue(prop, out[name], options);\n if (normalized === undefined) delete out[name];\n else out[name] = normalized;\n }\n return out;\n}\n","// Design-time channel (doc 06 §2.5): builds the PropertyContext handed to\n// DROPDOWN options() / DYNAMIC props() resolvers, and invokes them out-of-band.\nimport {\n getActions,\n getTriggers,\n type ApPiece,\n type ApProperty,\n} from \"../types.js\";\nimport { throwingStub, withTouchTracking } from \"./stubs.js\";\nimport type {\n ConnectionsManager,\n FlowsContext,\n PropertyContext,\n ReactorService,\n ServerContext,\n} from \"@powerhousedao/pieces-framework\";\n\n// The framework's FlowsContext.list, minus the SeekPage cursors the host does\n// not serve: a resolver only ever reads `data`.\nexport interface FlowsProvider {\n list(\n ...params: Parameters<FlowsContext[\"list\"]>\n ): Promise<{ data: unknown[] }>;\n}\n\n// The framework's ConnectionsManager with its return widened: the host serves\n// whatever a connection resolved to, not only the shapes upstream enumerates.\nexport interface ConnectionsProvider {\n get(...params: Parameters<ConnectionsManager[\"get\"]>): Promise<unknown>;\n}\n\nexport type BuiltApPropertyContext = Omit<\n PropertyContext,\n \"flows\" | \"connections\"\n> & {\n flows: FlowsProvider;\n connections: ConnectionsProvider;\n // ctx.reactor: the Powerhouse capability the framework has no member for.\n reactor: ReactorService;\n};\n\nexport interface PropertyContextOptions {\n searchValue?: string;\n // Injected capabilities; anything omitted throws with its member path.\n flows?: FlowsProvider;\n connections?: ConnectionsProvider;\n server?: ServerContext;\n projectId?: string;\n // ctx.reactor for a design-time resolver, on the same terms as at run time:\n // offered to a package piece, a throwing stub to every other.\n reactor?: ReactorService;\n onTouch?: (member: string) => void;\n}\n\nexport interface PropertyContextHandle {\n context: BuiltApPropertyContext;\n // Top-level members the resolver read; `UNDOCUMENTED:<name>` marks unknown reads.\n touched: ReadonlySet<string>;\n}\n\nexport function buildPropertyContext(\n options: PropertyContextOptions = {},\n): PropertyContextHandle {\n const touched = new Set<string>();\n const base: Record<string, unknown> = {\n searchValue: options.searchValue,\n reactor: options.reactor ?? throwingStub(\"reactor\"),\n server: options.server ?? throwingStub(\"server\"),\n project: {\n id: options.projectId ?? \"project\",\n externalId: () => Promise.resolve(options.projectId ?? \"project\"),\n },\n flows: options.flows ?? { list: throwingStub(\"flows.list\") },\n connections: options.connections ?? {\n get: throwingStub(\"connections.get\"),\n },\n };\n const context = withTouchTracking(base, touched, options.onTouch);\n return { context: context as unknown as BuiltApPropertyContext, touched };\n}\n\nexport class NotDynamicPropertyError extends Error {\n constructor(actionName: string, propName: string) {\n super(`Property \"${actionName}.${propName}\" has no dynamic resolver`);\n this.name = \"NotDynamicPropertyError\";\n }\n}\n\nfunction pickResolver(\n prop: ApProperty,\n): ((...args: unknown[]) => unknown) | undefined {\n if (typeof prop.options === \"function\") return prop.options;\n if (typeof prop.props === \"function\") return prop.props;\n return undefined;\n}\n\nexport interface ResolveDynamicPropertyParams {\n piece: ApPiece;\n // Action or trigger name, per kind (default \"action\").\n actionName: string;\n kind?: \"action\" | \"trigger\";\n propName: string;\n // Resolved values of the prop's refresher inputs (auth and sibling props).\n refresherValues?: Record<string, unknown>;\n context: BuiltApPropertyContext;\n}\n\n// Props map of an action or trigger; throws when the owner is unknown.\nexport function ownerProps(\n piece: ApPiece,\n actionName: string,\n kind: \"action\" | \"trigger\" = \"action\",\n): Record<string, ApProperty> {\n const owner =\n kind === \"trigger\"\n ? (getTriggers(piece)[actionName] as\n | { props?: Record<string, ApProperty> }\n | undefined)\n : (getActions(piece)[actionName] as\n | { props?: Record<string, ApProperty> }\n | undefined);\n if (!owner) throw new Error(`No ${kind} \"${actionName}\" on piece`);\n return owner.props ?? {};\n}\n\nexport function findProperty(\n piece: ApPiece,\n actionName: string,\n propName: string,\n kind: \"action\" | \"trigger\" = \"action\",\n): ApProperty {\n const prop = ownerProps(piece, actionName, kind)[propName] as\n | ApProperty\n | undefined;\n if (!prop)\n throw new Error(`No prop \"${propName}\" on ${kind} \"${actionName}\"`);\n return prop;\n}\n\n// Invokes a DROPDOWN options() or DYNAMIC props() resolver. The result is\n// returned untouched: pieces may soft-fail with a disabled DropdownState.\nexport async function resolveDynamicProperty(\n params: ResolveDynamicPropertyParams,\n): Promise<unknown> {\n const { piece, actionName, propName, kind = \"action\" } = params;\n const prop = findProperty(piece, actionName, propName, kind);\n const resolver = pickResolver(prop);\n if (!resolver) throw new NotDynamicPropertyError(actionName, propName);\n return await resolver(params.refresherValues ?? {}, params.context);\n}\n\nexport interface ParsedResolverId {\n packageName: string;\n actionName: string;\n propName: string;\n}\n\n// Inverse of the descriptor's id scheme: activepieces:<pkg>#<action>.<prop>.\nexport function parseDynamicResolverId(id: string): ParsedResolverId {\n const match = /^activepieces:(.+)#(.+)\\.([^.]+)$/.exec(id);\n if (!match) throw new Error(`Invalid dynamic resolver id: ${id}`);\n return { packageName: match[1], actionName: match[2], propName: match[3] };\n}\n\nexport async function resolveByResolverId(\n piece: ApPiece,\n resolverId: string,\n refresherValues: Record<string, unknown>,\n context: BuiltApPropertyContext,\n): Promise<unknown> {\n const { actionName, propName } = parseDynamicResolverId(resolverId);\n return resolveDynamicProperty({\n piece,\n actionName,\n propName,\n refresherValues,\n context,\n });\n}\n","// `ctx.store` served by the host, one call per operation, so a value a piece\n// writes is durable the moment it writes it rather than when the step ends.\n\n// This is the semantic Activepieces pieces are written against — theirs is an\n// HTTP call per get/put/delete — so a loop that checkpoints its cursor resumes.\nimport type { KeyValueStore } from \"./action.js\";\nimport type { StoreScopeName } from \"./store-scope.js\";\nimport { STORE_DELETE, STORE_GET, STORE_PUT } from \"../worker/protocol.js\";\nimport { callHost } from \"../worker/host-call.js\";\nimport { jsonSafe } from \"../worker/json-safe.js\";\n\n// The host writes JSON, so a value is flattened here rather than at the point\n// it lands. A piece that stores a Date reads back a string either way, whether\n// or not a durable store is configured — and whatever carries the message.\nexport class RemoteKeyValueStore implements KeyValueStore {\n async put(\n key: string,\n value: unknown,\n scope?: StoreScopeName,\n ): Promise<unknown> {\n const stored = jsonSafe(value);\n await callHost(STORE_PUT, { key, value: stored, scope });\n return stored;\n }\n\n get(key: string, scope?: StoreScopeName): Promise<unknown> {\n return callHost(STORE_GET, { key, scope });\n }\n\n async delete(key: string, scope?: StoreScopeName): Promise<void> {\n await callHost(STORE_DELETE, { key, scope });\n }\n}\n","// ctx.output.update: the piece reporting progress before it returns. A long\n// step is otherwise opaque until the moment it finishes.\nimport { notifyHost } from \"../worker/host-call.js\";\nimport { jsonSafe } from \"../worker/json-safe.js\";\nimport { OUTPUT_UPDATE } from \"../worker/protocol.js\";\n\nexport interface PartialOutput {\n update(output: unknown): Promise<void>;\n}\n\n// Resolves immediately: a tap the step waits on is a tap that can stall it,\n// which is the one thing plan/08 §7.8 rules out.\n\n// A notification carries no request id, and the worker is reused. A piece that\n// keeps `ctx` and updates from a timer would otherwise report progress against\n// whichever step is running by then, so the tap is closed when its step ends.\nexport class RemoteOutput implements PartialOutput {\n private open = true;\n\n update(output: unknown): Promise<void> {\n if (this.open) notifyHost(OUTPUT_UPDATE, jsonSafe(output));\n return Promise.resolve();\n }\n\n close(): void {\n this.open = false;\n }\n}\n","// Piece console output, forwarded to the host while the step runs. The child\n// is forked with its stdio discarded, so without this a piece's logs vanish.\nimport { format } from \"node:util\";\nimport { notifyHost } from \"./host-call.js\";\nimport { LOG_WRITE, type PieceLogEntry } from \"./protocol.js\";\n\n// A runaway piece can log in a loop; the channel is shared with the step's own\n// result, so both the size of an entry and the number of them are capped.\n\n// Without the count, a loop enqueues IPC messages faster than the host drains\n// them and the result waits behind the backlog until the step times out.\nconst MAX_MESSAGE_LENGTH = 8_192;\nconst MAX_ENTRIES_PER_REQUEST = 1_000;\n\nconst LEVELS = [\"log\", \"info\", \"warn\", \"error\", \"debug\"] as const;\n\ntype Level = (typeof LEVELS)[number];\n\n// Installs the patch for one request and returns its undo. Logs written after\n// the step returned belong to no step, which is why the scope is this narrow.\nexport function captureConsole(): () => void {\n const original = new Map<Level, (...args: unknown[]) => void>();\n let sent = 0;\n\n for (const level of LEVELS) {\n const previous = console[level] as (...args: unknown[]) => void;\n original.set(level, previous);\n console[level] = (...args: unknown[]) => {\n if (sent > MAX_ENTRIES_PER_REQUEST) return;\n sent += 1;\n // The last one says why the rest are missing, so a truncated log does\n // not read as a step that fell silent.\n const message =\n sent > MAX_ENTRIES_PER_REQUEST\n ? `[log truncated after ${MAX_ENTRIES_PER_REQUEST} entries]`\n : format(...args).slice(0, MAX_MESSAGE_LENGTH);\n notifyHost(LOG_WRITE, {\n level,\n message,\n at: Date.now(),\n } satisfies PieceLogEntry);\n };\n }\n\n return () => {\n for (const [level, previous] of original) {\n console[level] = previous as typeof console.log;\n }\n };\n}\n","// Worker child: loads piece bundles and executes actions in an isolated\n// process, so piece side-effects (TLS env poisoning, crashes) never reach the host.\nimport {\n buildActionContext,\n InMemoryConnectionsProvider,\n InMemoryKeyValueStore,\n UnsupportedContextMemberError,\n} from \"../context/action.js\";\nimport { RemoteKeyValueStore } from \"../context/remote-store.js\";\nimport { RemoteReactorService } from \"../context/reactor.js\";\nimport { RemoteOutput } from \"../context/remote-output.js\";\nimport { captureConsole } from \"./logs.js\";\nimport { jsonSafe } from \"./json-safe.js\";\nimport { formatPieceError } from \"@powerhousedao/pieces-framework/host\";\nimport { redactError, redactMessage } from \"./redact.js\";\nimport { readFile } from \"node:fs/promises\";\nimport { buildCheckConnectionContext } from \"../context/check.js\";\nimport { DataUriFilesService, StagedFilesService } from \"../context/files.js\";\nimport {\n normalizePropsValue,\n type NormalizeOptions,\n} from \"../context/normalize.js\";\nimport {\n buildPropertyContext,\n findProperty,\n resolveDynamicProperty,\n} from \"../context/props.js\";\nimport { buildTriggerContext, runTriggerHook } from \"../context/trigger.js\";\nimport { buildDescriptor, describeProperties } from \"../descriptor.js\";\nimport { loadPiece, loadPieceFromDir, type LoadedPiece } from \"../loader.js\";\nimport { getActions, getTriggers, type ApProperty } from \"../types.js\";\nimport { installEgressGuard, runWithEgressPolicy } from \"./egress.js\";\nimport type {\n StagedInput,\n PieceModuleRef,\n CheckConnectionMessage,\n CheckConnectionOutcome,\n DescribePieceMessage,\n ResolveOptionsMessage,\n RunMessage,\n SerializedPieceError,\n TriggerHookMessage,\n WorkerRequestMessage,\n WorkerResponse,\n} from \"./protocol.js\";\n\n// Before any piece module is loaded, so a piece cannot keep a pristine copy of\n// the socket layer from a request that carried no policy.\ninstallEgressGuard();\n\nconst loadedPieces = new Map<string, Promise<LoadedPiece>>();\n// One store per scope, alive for the worker's lifetime (in-memory phase:\n// state survives runs but not worker replacement).\nconst stores = new Map<string, InMemoryKeyValueStore>();\n\nfunction storeForScope(scope: string): InMemoryKeyValueStore {\n let store = stores.get(scope);\n if (!store) {\n store = new InMemoryKeyValueStore();\n stores.set(scope, store);\n }\n return store;\n}\n\n// The module this request names, and the cache key for it. A package piece\n// arrives as one file; a fetched bundle as the directory holding it.\nfunction pieceRefKey(ref: PieceModuleRef): string {\n const key = ref.entryPath ?? ref.bundleDir;\n if (!key) {\n throw new Error(\"Request names no piece module (entryPath or bundleDir)\");\n }\n return key;\n}\n\nfunction loadCached(ref: PieceModuleRef): Promise<LoadedPiece> {\n const key = pieceRefKey(ref);\n let loading = loadedPieces.get(key);\n if (!loading) {\n loading = ref.entryPath ? loadPiece(key) : loadPieceFromDir(key);\n loadedPieces.set(key, loading);\n }\n return loading;\n}\n\n// The secret values this request carried, if any. Redacting here rather than\n// on the host means the host process never holds them in an error object.\nfunction redactValuesOf(message: WorkerRequestMessage): string[] {\n const request = message.request as { redactValues?: string[] };\n return request.redactValues ?? [];\n}\n\nfunction serializeError(\n error: unknown,\n values: string[] = [],\n): SerializedPieceError {\n const properties: Record<string, unknown> = {};\n if (typeof error === \"object\" && error !== null) {\n for (const key of Object.keys(error)) {\n properties[key] = jsonSafe((error as Record<string, unknown>)[key]);\n }\n }\n // The framework's own formatter first: it lifts an HTTP status, the request\n // and response, and a message out of an HTML error page. Redaction stays last.\n const { __apErrorVersion, message, errorName, ...http } =\n formatPieceError(error);\n return {\n name:\n (typeof error === \"object\" && error !== null && error.constructor.name) ||\n errorName ||\n \"Error\",\n message: redactMessage(message, { values }),\n properties: redactError(\n { ...properties, ...(jsonSafe(http) as Record<string, unknown>) },\n { values },\n ) as Record<string, unknown>,\n unsupportedMember:\n error instanceof UnsupportedContextMemberError ? error.member : undefined,\n };\n}\n\n// Read-and-clear the piece-set TLS override so each run reports its own poisoning.\nfunction consumeTlsFlag(): boolean {\n const poisoned = process.env.NODE_TLS_REJECT_UNAUTHORIZED === \"0\";\n delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;\n return poisoned;\n}\n\nasync function handleResolveOptions(\n message: ResolveOptionsMessage,\n): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const { context, touched } = buildPropertyContext({\n searchValue: request.searchValue,\n // Design-time default: an empty flows listing instead of a throwing stub.\n flows: { list: () => Promise.resolve({ data: [] }) },\n ...(request.reactorAccess ? { reactor: new RemoteReactorService() } : {}),\n });\n const refresherValues = {\n ...(request.auth !== undefined ? { auth: request.auth } : {}),\n ...request.refresherValues,\n };\n const prop = findProperty(\n piece,\n request.actionName,\n request.propName,\n request.kind,\n );\n const output = await resolveDynamicProperty({\n piece,\n actionName: request.actionName,\n kind: request.kind,\n propName: request.propName,\n refresherValues,\n context,\n });\n // DYNAMIC props() yields raw piece properties (with resolver functions);\n // the editor only ever sees descriptors, so translate before crossing IPC.\n const isDynamic =\n typeof prop.props === \"function\" && typeof prop.options !== \"function\";\n return {\n id: message.id,\n type: \"result\",\n output: isDynamic\n ? describeProperties(output as Record<string, ApProperty> | undefined)\n : jsonSafe(output),\n touched: [...touched],\n tlsPoisoned: consumeTlsFlag(),\n };\n}\n\n// Reads a FILE prop's attachment ref from the copy the host staged on disk.\n// The fork shares the filesystem with its parent, so this is what keeps a\n// 50 MB scan out of the IPC channel in both directions.\nfunction stagedInputResolver(\n inputs: StagedInput[] | undefined,\n): NormalizeOptions[\"resolveRef\"] {\n // An empty list is not the same as no list: it means the host has a store\n // and tried, so a FILE prop that still comes up short is told which\n // reference failed rather than that the context has no resolver.\n if (!inputs) return undefined;\n const byRef = new Map(inputs.map((input) => [input.ref, input]));\n return async (ref: string) => {\n const staged = byRef.get(ref);\n if (!staged) {\n throw new Error(`No staged file for reference \"${ref}\"`);\n }\n return {\n data: await readFile(staged.path),\n filename: staged.fileName,\n contentType: staged.contentType,\n };\n };\n}\n\nasync function handleRun(message: RunMessage): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const action = getActions(piece)[request.actionName] as\n | ReturnType<typeof getActions>[string]\n | undefined;\n if (!action) {\n throw new Error(\n `No action \"${request.actionName}\" in ${pieceRefKey(request)}`,\n );\n }\n const files = request.stagingDir\n ? new StagedFilesService(request.stagingDir)\n : new DataUriFilesService();\n // A durable store answers every get/put over the call channel, so a write\n // survives this worker; without one the value lives only in this heap.\n const durableStore = request.durableStore\n ? new RemoteKeyValueStore()\n : undefined;\n const liveOutput = request.liveOutput ? new RemoteOutput() : undefined;\n // Host-served reactor access, for a piece that ships inside a reactor package.\n const reactor = request.reactorAccess\n ? new RemoteReactorService()\n : undefined;\n // Before the props are normalised, not after: a processor that cannot coerce\n // says so on console.error, and the worker's stdio goes nowhere.\n const restoreConsole = request.captureLogs ? captureConsole() : undefined;\n const { context, touched } = buildActionContext({\n propsValue: await normalizePropsValue(action.props, request.propsValue, {\n resolveRef: stagedInputResolver(request.stagedInputs),\n }),\n auth: request.auth,\n store:\n durableStore ??\n (request.storeScope ? storeForScope(request.storeScope) : undefined),\n files,\n connections: request.connections\n ? new InMemoryConnectionsProvider(request.connections)\n : undefined,\n output: liveOutput,\n reactor,\n executionType: request.executionType,\n identity: request.identity,\n });\n let output: unknown;\n try {\n output = await action.run(context);\n } finally {\n restoreConsole?.();\n liveOutput?.close();\n }\n return {\n id: message.id,\n type: \"result\",\n output: jsonSafe(output),\n ...(files instanceof StagedFilesService && files.staged().length > 0\n ? { files: files.staged() }\n : {}),\n touched: [...touched],\n tlsPoisoned: consumeTlsFlag(),\n };\n}\n\nasync function handleTriggerHook(\n message: TriggerHookMessage,\n): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const trigger = getTriggers(piece)[request.triggerName] as\n | ReturnType<typeof getTriggers>[string]\n | undefined;\n if (!trigger) {\n throw new Error(\n `No trigger \"${request.triggerName}\" in bundle ${request.bundleDir}`,\n );\n }\n // The durable store answers every get/put over the call channel, so a long\n // onEnable checkpoints: registration ids survive a crash mid-hook.\n const snapshot = request.durableStore\n ? undefined\n : new InMemoryKeyValueStore(request.storeState);\n const runsPiece = request.hook === \"run\" || request.hook === \"test\";\n const handle = buildTriggerContext({\n propsValue: await normalizePropsValue(trigger.props, request.propsValue),\n auth: request.auth,\n store: snapshot ?? new RemoteKeyValueStore(),\n hostPartitionedStore: request.durableStore,\n // Test hooks write under a separate prefix, never the live cursor.\n storePrefix: request.hook === \"test\" ? \"test\" : \"\",\n identity: request.identity,\n isRepublish: request.isRepublish,\n payload: request.payload,\n webhookUrl: request.webhookUrl,\n server: request.server,\n files: runsPiece ? new DataUriFilesService() : undefined,\n });\n const output = await runTriggerHook(trigger, request.hook, handle);\n return {\n id: message.id,\n type: \"result\",\n output: jsonSafe(output),\n touched: [...handle.touched],\n tlsPoisoned: consumeTlsFlag(),\n // Only the snapshot path has state to hand back; a durable store already\n // committed everything the hook wrote.\n ...(snapshot\n ? { storeState: jsonSafe(snapshot.snapshot()) as Record<string, unknown> }\n : {}),\n schedules: handle.schedules,\n listeners: handle.listeners,\n };\n}\n\nasync function handleCheckConnection(\n message: CheckConnectionMessage,\n): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const app = piece as {\n checkConnection?: (context: unknown) => unknown;\n };\n if (typeof app.checkConnection !== \"function\") {\n const outcome: CheckConnectionOutcome = { declared: false };\n return {\n id: message.id,\n type: \"result\",\n output: outcome,\n touched: [],\n tlsPoisoned: consumeTlsFlag(),\n };\n }\n const { context, touched } = buildCheckConnectionContext({\n auth: request.auth,\n });\n const result = await app.checkConnection(context);\n const outcome: CheckConnectionOutcome = {\n declared: true,\n result: jsonSafe(result),\n };\n return {\n id: message.id,\n type: \"result\",\n output: outcome,\n touched: [...touched],\n tlsPoisoned: consumeTlsFlag(),\n };\n}\n\nasync function handleDescribe(\n message: DescribePieceMessage,\n): Promise<WorkerResponse> {\n const { request } = message;\n const { piece } = await loadCached(request);\n const descriptor = buildDescriptor(piece, {\n packageName: request.packageName,\n version: request.version,\n });\n return {\n id: message.id,\n type: \"result\",\n // A prop's defaultValue is piece-authored; jsonSafe keeps a non-cloneable\n // one from failing the IPC send.\n output: jsonSafe(descriptor),\n touched: [],\n tlsPoisoned: consumeTlsFlag(),\n };\n}\n\nfunction isWorkerMessage(value: unknown): value is WorkerRequestMessage {\n if (typeof value !== \"object\" || value === null) return false;\n const type = (value as { type?: unknown }).type;\n return (\n type === \"run\" ||\n type === \"resolve-options\" ||\n type === \"trigger-hook\" ||\n type === \"check-connection\" ||\n type === \"describe\"\n );\n}\n\nfunction dispatch(message: WorkerRequestMessage): Promise<WorkerResponse> {\n switch (message.type) {\n case \"run\":\n return handleRun(message);\n case \"resolve-options\":\n return handleResolveOptions(message);\n case \"trigger-hook\":\n return handleTriggerHook(message);\n case \"check-connection\":\n return handleCheckConnection(message);\n case \"describe\":\n return handleDescribe(message);\n }\n}\n\nprocess.on(\"message\", (message: unknown) => {\n if (!isWorkerMessage(message)) return;\n // Deferred so a synchronous throw — a malformed egress policy — becomes a\n // rejection the handler below reports, instead of killing the child.\n const handler = Promise.resolve().then(() =>\n runWithEgressPolicy(message.request.egress, () => dispatch(message)),\n );\n handler\n .catch(\n (error: unknown): WorkerResponse => ({\n id: message.id,\n type: \"error\",\n error: serializeError(error, redactValuesOf(message)),\n tlsPoisoned: consumeTlsFlag(),\n }),\n )\n .then((response) => process.send?.(response))\n .catch(() => process.exit(1));\n});\n"],"mappings":";;;;;;AASA,MAAM,+BAA+B;AASrC,MAAM,0BAAU,IAAI,KAAsB;AAC1C,IAAI,SAAS;AACb,IAAI,YAAY;AAEhB,IAAa,gBAAb,cAA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AAW,QAAQ;CAC3C,MAAM,aAAa,gBAAgB,OAAO;EACxC,aAAa,QAAQ;EACrB,SAAS,QAAQ;EAClB,CAAC;AACF,QAAO;EACL,IAAI,QAAQ;EACZ,MAAM;EAGN,QAAQ,SAAS,WAAW;EAC5B,SAAS,EAAE;EACX,aAAa,gBAAgB;EAC9B;;AAGH,SAAS,gBAAgB,OAA+C;AACtE,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,OAAQ,MAA6B;AAC3C,QACE,SAAS,SACT,SAAS,qBACT,SAAS,kBACT,SAAS,sBACT,SAAS;;AAIb,SAAS,SAAS,SAAwD;AACxE,SAAQ,QAAQ,MAAhB;EACE,KAAK,MACH,QAAO,UAAU,QAAQ;EAC3B,KAAK,kBACH,QAAO,qBAAqB,QAAQ;EACtC,KAAK,eACH,QAAO,kBAAkB,QAAQ;EACnC,KAAK,mBACH,QAAO,sBAAsB,QAAQ;EACvC,KAAK,WACH,QAAO,eAAe,QAAQ;;;AAIpC,QAAQ,GAAG,YAAY,YAAqB;AAC1C,KAAI,CAAC,gBAAgB,QAAQ,CAAE;AAGf,SAAQ,SAAS,CAAC,WAChC,oBAAoB,QAAQ,QAAQ,cAAc,SAAS,QAAQ,CAAC,CACrE,CAEE,OACE,WAAoC;EACnC,IAAI,QAAQ;EACZ,MAAM;EACN,OAAO,eAAe,OAAO,eAAe,QAAQ,CAAC;EACrD,aAAa,gBAAgB;EAC9B,EACF,CACA,MAAM,aAAa,QAAQ,OAAO,SAAS,CAAC,CAC5C,YAAY,QAAQ,KAAK,EAAE,CAAC;EAC/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerhousedao/reactor-workflow",
3
- "version": "6.2.3-dev.18",
3
+ "version": "6.2.3-dev.19",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -29,12 +29,12 @@
29
29
  "./package.json": "./package.json"
30
30
  },
31
31
  "dependencies": {
32
- "@powerhousedao/pieces-framework": "6.2.3-dev.18",
33
- "@powerhousedao/reactor": "6.2.3-dev.18",
34
- "@powerhousedao/shared": "6.2.3-dev.18",
35
- "@powerhousedao/workflow": "6.2.3-dev.18",
32
+ "@powerhousedao/pieces-framework": "6.2.3-dev.19",
33
+ "@powerhousedao/reactor": "6.2.3-dev.19",
34
+ "@powerhousedao/shared": "6.2.3-dev.19",
35
+ "@powerhousedao/workflow": "6.2.3-dev.19",
36
36
  "croner": "10.0.1",
37
- "document-model": "6.2.3-dev.18",
37
+ "document-model": "6.2.3-dev.19",
38
38
  "graphql": "^16"
39
39
  },
40
40
  "devDependencies": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"piece-registry-CzYq4sK-.js","names":["logger","gunzip","gunzipCb"],"sources":["../src/pieces/activepieces/registry-source.ts","../src/pieces/activepieces/fetch.ts","../src/pieces/activepieces/resolver.ts","../src/pieces/activepieces/worker/transport.ts","../src/pieces/activepieces/worker/host.ts","../src/pieces/activepieces/worker/pool.ts","../src/pieces/engine/secrets.ts","../src/pieces/engine/expressions.ts","../src/pieces/engine/connections.ts","../src/pieces/engine/blocks.ts","../src/pieces/engine/coordinator.ts","../src/reactor/piece-registry.ts"],"sourcesContent":["// A Powerhouse registry as a source of pieces: where this runtime reads piece\n// metadata and fetches piece code.\n\n// It serves the same three shapes cloud.activepieces.com and its CDN do — a\n// list, one piece's detail, a bundle tarball — so only the base URL differs.\n\n// The registry is the one the host already installs packages from. A package\n// installed from it ships pieces that run in the worker with the same reach, so\n// a bundle fetched from it is no more trusted than one that arrived inside a\n// package; the trust boundary is the registry, and it is already drawn.\nimport { childLogger } from \"document-model\";\n\nconst logger = childLogger([\"workflow\", \"piece-registry\"]);\n\nexport interface PieceRegistrySource {\n /** Origin the piece endpoints hang off, without a trailing slash. */\n baseUrl: string;\n /** The catalog, in cloud.activepieces.com's list shape. */\n catalogUrl(suggestions?: boolean): string;\n /** One piece's detail, in the shape their piece endpoint answers with. */\n pieceUrl(name: string): string;\n /** The bundle, under the filename their CDN would serve it as. */\n tarballUrl(name: string, version: string): string;\n}\n\nfunction source(baseUrl: string): PieceRegistrySource {\n return {\n baseUrl,\n catalogUrl: (suggestions) =>\n suggestions\n ? `${baseUrl}/pieces?suggestionType=ACTION_AND_TRIGGER`\n : `${baseUrl}/pieces`,\n // Encoded whole, slash included: a scoped name is one path segment to the\n // registry's route, not two.\n pieceUrl: (name) => `${baseUrl}/pieces/${encodeURIComponent(name)}`,\n tarballUrl: (name, version) =>\n `${baseUrl}/-/pieces/bundled/${name.replace(\"/\", \"-\")}-${version}.tgz`,\n };\n}\n\n// Set by the host at composition from the registry it resolved for package\n// installs; absent on a host that installs no packages from one, and nothing\n// changes.\nlet configured: PieceRegistrySource | undefined;\n\nexport function setPieceRegistryUrl(url: string | undefined): void {\n const trimmed = url?.trim().replace(/\\/+$/, \"\") ?? \"\";\n if (trimmed === \"\") {\n configured = undefined;\n return;\n }\n if (configured?.baseUrl === trimmed) return;\n configured = source(trimmed);\n logger.info(`Pieces may be fetched from ${configured.baseUrl}`);\n}\n\nexport function pieceRegistrySource(): PieceRegistrySource | undefined {\n return configured;\n}\n","import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, rename, rm, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { gunzip as gunzipCb } from \"node:zlib\";\nimport { pieceRegistrySource } from \"./registry-source.js\";\n\nconst gunzip = promisify(gunzipCb);\n\n// Mirrors their pieceBundle.resolve(): CDN bundle when served, else the npm\n// tarball. Tarballs are immutable per (name, version), so the cache never expires.\nconst CDN_PIECES_URL = \"https://cdn.activepieces.com/pieces/bundled/\";\nconst NPM_REGISTRY_URL = \"https://registry.npmjs.org\";\n\nexport function cdnTarballUrl(name: string, version: string): string {\n return `${CDN_PIECES_URL}${name.replace(\"/\", \"-\")}-${version}.tgz`;\n}\n\nexport function npmTarballUrl(name: string, version: string): string {\n const unscoped = name.startsWith(\"@\") ? name.split(\"/\")[1] : name;\n return `${NPM_REGISTRY_URL}/${name}/-/${unscoped}-${version}.tgz`;\n}\n\n// name/version come from a workflow step's blockType, an unconstrained string.\nconst NPM_NAME_RE = /^(@[a-z0-9][a-z0-9-_.]*\\/)?[a-z0-9][a-z0-9-_.]*$/;\nconst NPM_VERSION_RE = /^[A-Za-z0-9][A-Za-z0-9.+-]*$/;\n\nfunction assertValidPackageCoordinate(name: string, version: string): void {\n if (!NPM_NAME_RE.test(name)) {\n throw new Error(`Invalid piece package name: ${name}`);\n }\n if (!NPM_VERSION_RE.test(version)) {\n throw new Error(`Invalid piece package version: ${version}`);\n }\n}\n\n// Belt-and-suspenders: the path we're about to rm/rename must land under cacheDir.\nfunction assertWithinCacheDir(dir: string, cacheDir: string): void {\n const root = path.resolve(cacheDir);\n const resolved = path.resolve(dir);\n if (resolved !== root && !resolved.startsWith(root + path.sep)) {\n throw new Error(`Resolved piece cache path escapes cacheDir: ${dir}`);\n }\n}\n\nfunction readString(header: Buffer, offset: number, length: number): string {\n const slice = header.subarray(offset, offset + length);\n const nul = slice.indexOf(0);\n return slice.subarray(0, nul === -1 ? length : nul).toString(\"utf8\");\n}\n\n// Published piece bundles run a few hundred KB extracted; the cap is well clear\n// of that and bounds what a hostile or corrupt tarball can inflate to.\nconst MAX_EXTRACTED_BYTES = 64 * 1024 * 1024;\n\n// Caps the compressed transfer itself, before gunzip ever runs — the decompressed\n// cap above does nothing for a huge (not necessarily bomb-like) response body.\nconst MAX_COMPRESSED_BYTES = 64 * 1024 * 1024;\n\n// Minimal ustar extraction: regular files only, \"package/\" root stripped.\nasync function extractTarball(tgz: Buffer, dest: string): Promise<void> {\n // Async gunzip: the sync one blocks the reactor's event loop for every\n // request, not just this one, and inflation is unbounded without maxOutputLength.\n const tar = await gunzip(tgz, { maxOutputLength: MAX_EXTRACTED_BYTES }).catch(\n (error: unknown) => {\n throw new Error(`Failed to decompress piece bundle: ${String(error)}`);\n },\n );\n let offset = 0;\n while (offset + 512 <= tar.length) {\n const header = tar.subarray(offset, offset + 512);\n if (header.every((byte) => byte === 0)) break;\n const name = readString(header, 0, 100);\n const prefix = readString(header, 345, 155);\n const size = parseInt(readString(header, 124, 12).trim() || \"0\", 8);\n const type = String.fromCharCode(header[156]);\n offset += 512;\n const isFile = type === \"0\" || type === \"\\0\" || type === \"\";\n if (isFile && size >= 0) {\n const full = prefix ? `${prefix}/${name}` : name;\n const rel = full.replace(/^[^/]+\\//, \"\");\n const target = path.resolve(dest, rel);\n // Guard against path traversal from a hostile tarball.\n if (rel && target.startsWith(path.resolve(dest) + path.sep)) {\n await mkdir(path.dirname(target), { recursive: true });\n await writeFile(target, tar.subarray(offset, offset + size));\n }\n }\n offset += Math.ceil(size / 512) * 512;\n }\n}\n\nexport interface FetchPieceBundleOptions {\n name: string;\n version: string;\n cacheDir: string;\n timeoutMs?: number;\n}\n\n/** Where a bundle came from, \"cache\" being a copy one of the others left. */\nexport type BundleSource = \"registry\" | \"cdn\" | \"npm\";\n\nexport interface FetchedBundle {\n dir: string;\n source: BundleSource | \"cache\";\n}\n\n// Bounds the transfer before gunzip: rejects an over-limit Content-Length up\n// front, else tracks a running total as the body streams in.\nasync function readBoundedBody(\n response: Response,\n url: string,\n): Promise<Buffer> {\n const declared = response.headers.get(\"content-length\");\n if (declared && Number(declared) > MAX_COMPRESSED_BYTES) {\n throw new Error(\n `${url} exceeds the ${MAX_COMPRESSED_BYTES}-byte compressed size cap (Content-Length: ${declared})`,\n );\n }\n if (!response.body) return Buffer.from(await response.arrayBuffer());\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let total = 0;\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n total += value.byteLength;\n if (total > MAX_COMPRESSED_BYTES) {\n await reader.cancel();\n throw new Error(\n `${url} exceeds the ${MAX_COMPRESSED_BYTES}-byte compressed size cap`,\n );\n }\n chunks.push(value);\n }\n return Buffer.concat(chunks);\n}\n\n// A Powerhouse registry this deployment allowed comes first, so a piece it\n// serves is not shadowed by an Activepieces piece of the same name.\nfunction tarballSources(\n name: string,\n version: string,\n): { source: BundleSource; url: string }[] {\n const registry = pieceRegistrySource();\n return [\n ...(registry\n ? [\n {\n source: \"registry\" as const,\n url: registry.tarballUrl(name, version),\n },\n ]\n : []),\n { source: \"cdn\" as const, url: cdnTarballUrl(name, version) },\n { source: \"npm\" as const, url: npmTarballUrl(name, version) },\n ];\n}\n\nasync function downloadTarball(\n name: string,\n version: string,\n timeoutMs: number,\n): Promise<{ tgz: Buffer; source: BundleSource }> {\n const sources = tarballSources(name, version);\n let lastError: unknown;\n for (const { source, url } of sources) {\n try {\n const response = await fetch(url, {\n signal: AbortSignal.timeout(timeoutMs),\n });\n if (!response.ok) {\n lastError = new Error(`${url} responded ${response.status}`);\n continue;\n }\n return { tgz: await readBoundedBody(response, url), source };\n } catch (error) {\n lastError = error;\n }\n }\n throw new Error(\n `Failed to fetch piece bundle ${name}@${version}: ${String(lastError)}`,\n );\n}\n\n// Downloads and extracts a published piece bundle, returning the directory to\n// hand to loadPieceFromDir(). A cached extraction is reused, and re-checked.\nexport async function fetchPieceBundle(\n options: FetchPieceBundleOptions,\n): Promise<FetchedBundle> {\n const { name, version, cacheDir, timeoutMs = 30_000 } = options;\n assertValidPackageCoordinate(name, version);\n const dir = path.join(cacheDir, `${name.replace(\"/\", \"-\")}-${version}`);\n assertWithinCacheDir(dir, cacheDir);\n if (existsSync(path.join(dir, \"package.json\"))) {\n await assertSelfContained(dir, name, version);\n return { dir, source: \"cache\" };\n }\n\n const { tgz, source } = await downloadTarball(name, version, timeoutMs);\n const staging = `${dir}.tmp-${process.pid}`;\n await rm(staging, { recursive: true, force: true });\n await extractTarball(tgz, staging);\n await rm(dir, { recursive: true, force: true });\n try {\n await rename(staging, dir);\n } catch (error) {\n // Concurrent fetcher won the rename; its extraction is identical.\n await rm(staging, { recursive: true, force: true });\n if (!existsSync(path.join(dir, \"package.json\"))) throw error;\n }\n // Checked here rather than before the rename so a bundle an older build\n // already extracted is refused on its cache hit too, not only a fresh one.\n await assertSelfContained(dir, name, version);\n return { dir, source };\n}\n\n// Concurrent callers for the same bundle share one download+extract rather\n// than racing each other through it.\nconst inFlight = new Map<string, Promise<FetchedBundle>>();\n\n// The way in: a bundle arrives extracted, cached and checked, and callers that\n// ask for the same one at the same time wait on a single fetch.\nexport async function ensurePieceBundle(\n options: FetchPieceBundleOptions,\n): Promise<FetchedBundle> {\n const key = `${options.cacheDir}\\u0000${options.name}@${options.version}`;\n const pending = inFlight.get(key);\n if (pending) return pending;\n // Dropped once settled, refusals included, so a later caller re-checks the\n // bundle rather than inheriting this call's answer forever.\n const started = fetchPieceBundle(options).finally(() => inFlight.delete(key));\n inFlight.set(key, started);\n return started;\n}\n\n// The Activepieces release that began inlining a piece's dependencies into its\n// bundle. They still publish pieces to npm, which is why npm stays a source.\nconst AP_SELF_CONTAINED_SINCE = \"0.86.0\";\n\n// Enough to recognise what the bundle wants without turning the refusal into\n// a wall of text.\nconst MAX_LISTED_DEPENDENCIES = 5;\n\n// A bundle has to carry its own code: the worker imports it straight out of the\n// cache directory, where there is no node_modules and nothing to install one.\nasync function assertSelfContained(\n dir: string,\n name: string,\n version: string,\n): Promise<void> {\n const dependencies = await readDependencies(dir);\n const declared = Object.keys(dependencies);\n if (declared.length === 0) return;\n const listed = declared\n .slice(0, MAX_LISTED_DEPENDENCIES)\n .map((dep) => `${dep}@${dependencies[dep]}`);\n const rest = declared.length - listed.length;\n const count =\n declared.length === 1 ? \"a dependency\" : `${declared.length} dependencies`;\n // Only an Activepieces piece gets their release number: a bundle from\n // anywhere else would be sent chasing a version that means nothing to it.\n const since = name.startsWith(\"@activepieces/\")\n ? ` Activepieces bundles have been self-contained since ${AP_SELF_CONTAINED_SINCE}.`\n : \"\";\n throw new Error(\n `Piece bundle ${name}@${version} is not self-contained: it declares ${count} ` +\n `(${listed.join(\", \")}${rest > 0 ? `, and ${rest} more` : \"\"}). ` +\n `The reactor no longer installs a bundle's dependencies. Pin ${name} at or above ` +\n `its first self-contained release.${since}`,\n );\n}\n\nasync function readDependencies(dir: string): Promise<Record<string, string>> {\n const raw = await readFile(path.join(dir, \"package.json\"), \"utf8\");\n const pkg = JSON.parse(raw) as { dependencies?: Record<string, string> };\n return pkg.dependencies ?? {};\n}\n","// Where a piece's code comes from. Two sources, one seam.\n\n// A published piece is a bundle fetched from a registry and cached on disk; a\n// first-party piece ships inside an installed reactor package and is already\n// on disk, with no version to fetch and no cache to warm.\nimport { ensurePieceBundle } from \"./fetch.js\";\nimport type { PieceModuleRef } from \"./worker/protocol.js\";\n\nexport interface ResolvedPiece extends PieceModuleRef {\n name: string;\n version: string;\n // True when the piece is code the operator installed rather than a bundle\n // fetched from a registry. Only these are offered host capabilities.\n local: boolean;\n}\n\nexport interface PieceResolver {\n resolve(name: string, version: string): Promise<ResolvedPiece>;\n}\n\n// A piece found in an installed reactor package: a module file, or a directory\n// in npm-bundle shape when the package ships one already bundled.\nexport interface LocalPiece {\n name: string;\n version: string;\n entryPath?: string;\n bundleDir?: string;\n}\n\n// May answer asynchronously: a host whose registry loads on first use waits\n// here rather than racing every caller to have loaded it first.\nexport type LocalPieceLookup = (\n name: string,\n) => LocalPiece | undefined | Promise<LocalPiece | undefined>;\n\n// One entry of a reactor package's `pieces` export: which piece it ships and\n// where the built bundle sits, relative to the package root.\nexport type { PackagePiece } from \"@powerhousedao/pieces-framework\";\n\n// The published path: fetch (or reuse) the bundle for an exact version.\nexport function bundleResolver(options: {\n cacheDir: string;\n timeoutMs?: number;\n}): PieceResolver {\n return {\n async resolve(name: string, version: string): Promise<ResolvedPiece> {\n const bundle = await ensurePieceBundle({\n name,\n version,\n cacheDir: options.cacheDir,\n ...(options.timeoutMs ? { timeoutMs: options.timeoutMs } : {}),\n });\n return { name, version, bundleDir: bundle.dir, local: false };\n },\n };\n}\n\n// An installed package wins over the registry for its own name, whatever\n// version the block type asked for: the installed copy is the one this reactor\n// runs, and a fetched bundle of the same name would shadow it silently.\nexport function localFirstResolver(\n lookup: LocalPieceLookup,\n fallback: PieceResolver,\n): PieceResolver {\n return {\n async resolve(name: string, version: string): Promise<ResolvedPiece> {\n const local = await lookup(name);\n if (!local) return fallback.resolve(name, version);\n return {\n name,\n version: local.version,\n ...(local.entryPath ? { entryPath: local.entryPath } : {}),\n ...(local.bundleDir ? { bundleDir: local.bundleDir } : {}),\n local: true,\n };\n },\n };\n}\n\n// What a request hands the worker, from whichever source answered.\nexport function pieceModuleRef(piece: ResolvedPiece): PieceModuleRef {\n return piece.entryPath\n ? { entryPath: piece.entryPath }\n : { bundleDir: piece.bundleDir };\n}\n","// What PieceWorker needs from a connection to a worker, and nothing else.\n\n// Written against this rather than a ChildProcess so a later transport — a\n// pooled fork, a socket to another machine — slots in underneath unchanged.\nimport { fork, type ChildProcess } from \"node:child_process\";\nimport { existsSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport interface TransportExit {\n code: number | null;\n signal: NodeJS.Signals | null;\n}\n\nexport type TransportEventMap = {\n message: unknown;\n exit: TransportExit;\n};\n\nexport type TransportEvent = keyof TransportEventMap;\n\nexport type TransportListener<E extends TransportEvent> = (\n payload: TransportEventMap[E],\n) => void;\n\n// One worker's connection. An implementation must deliver `message` payloads\n// faithfully enough for the protocol above, and emit `exit` exactly once.\n\n// \"Faithfully enough\" means JSON-shaped, deliberately: the fork's structured\n// clone would carry a Date or a Map, but nothing may depend on that, because\n// no other carrier could honour it.\n\n// PieceWorker flattens what it sends and the child flattens what it answers,\n// so this is a contract a socket could meet too — a transport is not required\n// to preserve anything JSON would lose.\nexport interface IPieceWorkerTransport {\n send(message: unknown): void;\n on<E extends TransportEvent>(event: E, listener: TransportListener<E>): void;\n off<E extends TransportEvent>(event: E, listener: TransportListener<E>): void;\n // Ends the worker now; it takes any pending host calls with it.\n kill(): void;\n // False once the worker cannot receive: a send after this is dropped.\n readonly connected: boolean;\n}\n\n// Builds a fresh connection. Called on first use and again after a worker is\n// killed, so a factory must be able to produce more than one.\nexport type PieceWorkerTransportFactory = () => IPieceWorkerTransport;\n\nexport function defaultEntryPath(): string {\n let dir = path.dirname(fileURLToPath(import.meta.url));\n while (!existsSync(path.join(dir, \"package.json\"))) {\n const parent = path.dirname(dir);\n if (parent === dir) throw new Error(\"Could not locate package root\");\n dir = parent;\n }\n const entry = path.join(dir, \"dist\", \"worker-entry.js\");\n if (!existsSync(entry)) {\n throw new Error(`Worker entry not built at ${entry} — run pnpm build`);\n }\n return entry;\n}\n\n// A forked node child on this machine, over its IPC channel.\nexport function createForkTransport(entryPath: string): IPieceWorkerTransport {\n const child: ChildProcess = fork(entryPath, [], {\n // Empty env: the child gets no host secrets and no inherited TLS overrides.\n env: {},\n execArgv: [],\n // Structured clone rather than JSON, so a Buffer in a payload survives.\n serialization: \"advanced\",\n // Piece stdout/stderr are dropped for now; log capture arrives with journaling.\n stdio: [\"ignore\", \"ignore\", \"ignore\", \"ipc\"],\n });\n\n // Node reports exit as two positional arguments; the interface carries one\n // payload, so the adaptation lives here rather than in every listener.\n const exitListeners = new Map<\n TransportListener<\"exit\">,\n (code: number | null, signal: NodeJS.Signals | null) => void\n >();\n\n return {\n get connected() {\n return child.connected;\n },\n send(message) {\n child.send(message as never);\n },\n on(event, listener) {\n if (event === \"exit\") {\n const adapted = (code: number | null, signal: NodeJS.Signals | null) =>\n (listener as TransportListener<\"exit\">)({ code, signal });\n exitListeners.set(listener as TransportListener<\"exit\">, adapted);\n child.on(\"exit\", adapted);\n return;\n }\n child.on(\"message\", listener as (value: unknown) => void);\n },\n off(event, listener) {\n if (event === \"exit\") {\n const adapted = exitListeners.get(\n listener as TransportListener<\"exit\">,\n );\n if (adapted) {\n child.off(\"exit\", adapted);\n exitListeners.delete(listener as TransportListener<\"exit\">);\n }\n return;\n }\n child.off(\"message\", listener as (value: unknown) => void);\n },\n kill() {\n child.kill(\"SIGKILL\");\n },\n };\n}\n","import type { StagedFile } from \"../context/files.js\";\nimport type { RecordedListener, RecordedSchedule } from \"../context/trigger.js\";\nimport { jsonSafe } from \"./json-safe.js\";\nimport {\n createForkTransport,\n defaultEntryPath,\n type IPieceWorkerTransport,\n type PieceWorkerTransportFactory,\n type TransportExit,\n} from \"./transport.js\";\nimport type {\n CheckConnectionRequest,\n DescribePieceRequest,\n HostCallHandlers,\n HostCallMessage,\n HostCallResponse,\n HostNotifyHandlers,\n HostNotifyMessage,\n ResolveOptionsRequest,\n RunActionRequest,\n SerializedPieceError,\n TriggerHookRequest,\n WorkerResponse,\n} from \"./protocol.js\";\n\ntype WorkerRequestType =\n | \"run\"\n | \"resolve-options\"\n | \"trigger-hook\"\n | \"check-connection\"\n | \"describe\";\n\ntype WorkerRequest =\n | RunActionRequest\n | ResolveOptionsRequest\n | TriggerHookRequest\n | CheckConnectionRequest\n | DescribePieceRequest;\n\nexport class PieceWorkerError extends Error {\n readonly serialized: SerializedPieceError;\n\n constructor(serialized: SerializedPieceError) {\n super(`${serialized.name}: ${serialized.message}`);\n this.name = \"PieceWorkerError\";\n this.serialized = serialized;\n }\n}\n\nexport class PieceWorkerTimeoutError extends Error {\n constructor(timeoutMs: number) {\n super(`Piece action timed out after ${timeoutMs}ms; worker was replaced`);\n this.name = \"PieceWorkerTimeoutError\";\n }\n}\n\nexport class PieceWorkerExitError extends Error {\n constructor(code: number | null, signal: string | null) {\n super(`Piece worker exited unexpectedly (code=${code}, signal=${signal})`);\n this.name = \"PieceWorkerExitError\";\n }\n}\n\nexport interface PieceWorkerResult {\n output: unknown;\n touched: string[];\n tlsPoisoned: boolean;\n // run only: files the piece wrote through ctx.files, staged on disk for the\n // host to ingest before the output is journalled.\n files?: StagedFile[];\n // trigger-hook only: final store contents plus captured context calls.\n storeState?: Record<string, unknown>;\n schedules?: RecordedSchedule[];\n listeners?: RecordedListener[];\n}\n\n// Handlers the host offers for the duration of one request: calls it answers,\n// and one-way reports it receives.\nexport interface RequestTaps {\n hostCalls?: HostCallHandlers;\n notifications?: HostNotifyHandlers;\n}\n\n// Every request that can serve a piece takes the same shape: a deadline plus\n// the taps the host offers while it runs.\nexport interface RequestOptions extends RequestTaps {\n timeoutMs?: number;\n}\n\n/** @deprecated Named for the one request that had it; every request takes it\n * now. Kept because the old name is on main, in this package's public types. */\nexport type RunActionOptions = RequestOptions;\n\ntype ChildMessage = WorkerResponse | HostCallMessage | HostNotifyMessage;\n\n// A tap reports on the step; it never decides its outcome. Node delivers these\n// before the result, so no draining step is needed at teardown.\nfunction serveNotify(\n message: HostNotifyMessage,\n handlers: HostNotifyHandlers | undefined,\n): void {\n const handler = handlers?.[message.method];\n if (!handler) return;\n try {\n // Declared void, but TypeScript admits an async function here, and its\n // rejection would take the host down rather than the tap.\n void Promise.resolve(handler(message.payload)).catch(() => undefined);\n } catch {\n // A broken tap is not the step's problem.\n }\n}\n\nexport interface PieceWorkerOptions {\n // Absolute path to the compiled worker entry; defaults to dist/worker-entry.js.\n entryPath?: string;\n defaultTimeoutMs?: number;\n // How to reach a worker. Defaults to a forked child on this machine; a\n // remote transport replaces it without touching the protocol above.\n transport?: PieceWorkerTransportFactory;\n}\n\n// The five requests a worker serves, plus teardown. Callers hold this rather\n// than PieceWorker itself, so a child that outlives every request and a child\n// that lives for one run are interchangeable to them.\nexport interface IPieceWorker {\n runAction(\n request: RunActionRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult>;\n resolveOptions(\n request: ResolveOptionsRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult>;\n checkConnection(\n request: CheckConnectionRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult>;\n describePiece(\n request: DescribePieceRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult>;\n runTriggerHook(\n request: TriggerHookRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult>;\n // Ends the worker. A caller that was handed one it does not own must not\n // call this; PieceWorkerPool disposes the workers it hands out.\n dispose(): void;\n}\n\n// Executes piece actions in a child process. Side-effects (TLS env poisoning,\n// crashes) stay in the child; a timed-out or crashed worker is replaced.\nexport class PieceWorker implements IPieceWorker {\n private readonly connect: PieceWorkerTransportFactory;\n private readonly defaultTimeoutMs: number;\n private worker: IPieceWorkerTransport | undefined;\n private queue: Promise<unknown> = Promise.resolve();\n private nextId = 1;\n\n constructor(options: PieceWorkerOptions = {}) {\n const entryPath = options.entryPath;\n this.connect =\n options.transport ??\n (() => createForkTransport(entryPath ?? defaultEntryPath()));\n this.defaultTimeoutMs = options.defaultTimeoutMs ?? 30_000;\n }\n\n // Requests are serialized per worker; concurrency comes from holding more\n // than one, which is what PieceWorkerPool does.\n runAction(\n request: RunActionRequest,\n options: RequestOptions = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"run\", request, options.timeoutMs, options);\n }\n\n // Design-time DROPDOWN options() / DYNAMIC props() resolution. It takes the\n // same taps a run does: a package piece's resolver may read the reactor.\n resolveOptions(\n request: ResolveOptionsRequest,\n options: RequestOptions = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"resolve-options\", request, options.timeoutMs, options);\n }\n\n // A piece's app.checkConnection over resolved credentials; the output is a\n // CheckConnectionOutcome.\n checkConnection(\n request: CheckConnectionRequest,\n options: { timeoutMs?: number } = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"check-connection\", request, options.timeoutMs);\n }\n\n // The piece's design-time descriptor; the output is a PieceDescriptor.\n describePiece(\n request: DescribePieceRequest,\n options: { timeoutMs?: number } = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"describe\", request, options.timeoutMs);\n }\n\n // One trigger lifecycle hook. It takes the same taps a run does, so a\n // `durableStore` hook reaches the host's store while it is still running.\n runTriggerHook(\n request: TriggerHookRequest,\n options: RequestOptions = {},\n ): Promise<PieceWorkerResult> {\n return this.enqueue(\"trigger-hook\", request, options.timeoutMs, options);\n }\n\n private enqueue(\n type: WorkerRequestType,\n request: WorkerRequest,\n timeoutMs?: number,\n taps: RequestTaps = {},\n ): Promise<PieceWorkerResult> {\n const run = this.queue.then(() =>\n this.execute(type, request, timeoutMs ?? this.defaultTimeoutMs, taps),\n );\n this.queue = run.catch(() => undefined);\n return run;\n }\n\n dispose(): void {\n this.worker?.kill();\n this.worker = undefined;\n }\n\n private spawn(): IPieceWorkerTransport {\n if (this.worker) return this.worker;\n const worker = this.connect();\n const forget = () => {\n if (this.worker === worker) this.worker = undefined;\n worker.off(\"exit\", forget);\n };\n worker.on(\"exit\", forget);\n this.worker = worker;\n return worker;\n }\n\n private execute(\n type: WorkerRequestType,\n request: WorkerRequest,\n timeoutMs: number,\n taps: RequestTaps,\n ): Promise<PieceWorkerResult> {\n const worker = this.spawn();\n const id = this.nextId++;\n\n return new Promise<PieceWorkerResult>((resolve, reject) => {\n const timer = setTimeout(() => {\n cleanup();\n worker.kill();\n this.worker = undefined;\n reject(new PieceWorkerTimeoutError(timeoutMs));\n }, timeoutMs);\n\n const onMessage = (value: unknown) => {\n const response = value as ChildMessage;\n // Ids come from two counters; dispatch on type before comparing them.\n if (response.type === \"host-call\" || response.type === \"host-notify\") {\n return;\n }\n if (response.id !== id) return;\n cleanup();\n if (response.type === \"result\") {\n resolve({\n output: response.output,\n touched: response.touched,\n tlsPoisoned: response.tlsPoisoned,\n files: response.files,\n storeState: response.storeState,\n schedules: response.schedules,\n listeners: response.listeners,\n });\n } else {\n reject(new PieceWorkerError(response.error));\n }\n };\n\n const onExit = ({ code, signal }: TransportExit) => {\n cleanup();\n reject(new PieceWorkerExitError(code, signal));\n };\n\n // Served outside the request queue: the queue is held by this very\n // request, so routing a call through it would deadlock the step.\n const onHostCall = (value: unknown) => {\n const message = value as ChildMessage;\n if (message.type === \"host-call\") {\n void this.serveHostCall(worker, message, taps.hostCalls);\n return;\n }\n if (message.type === \"host-notify\") {\n serveNotify(message, taps.notifications);\n }\n };\n\n const cleanup = () => {\n clearTimeout(timer);\n worker.off(\"message\", onMessage);\n worker.off(\"message\", onHostCall);\n worker.off(\"exit\", onExit);\n };\n\n worker.on(\"message\", onMessage);\n worker.on(\"message\", onHostCall);\n worker.on(\"exit\", onExit);\n // Flattened here rather than per caller: config, auth and connection\n // values are piece-authored, and the contract is JSON-shaped both ways.\n worker.send(jsonSafe({ id, type, request }));\n });\n }\n\n // Answers one call from the child. The handler set belongs to the request in\n // flight, so a call arriving after the step returned is refused, not served.\n private async serveHostCall(\n worker: IPieceWorkerTransport,\n message: HostCallMessage,\n handlers: HostCallHandlers | undefined,\n ): Promise<void> {\n let response: HostCallResponse;\n try {\n const handler = handlers?.[message.method];\n if (!handler) {\n throw new Error(`No host handler for \"${message.method}\"`);\n }\n response = {\n id: message.id,\n type: \"host-result\",\n value: await handler(message.payload),\n };\n } catch (error) {\n response = {\n id: message.id,\n type: \"host-result\",\n error: error instanceof Error ? error.message : String(error),\n };\n }\n // A worker killed on timeout takes its pending calls with it.\n if (worker.connected) worker.send(response);\n }\n}\n","// A bounded set of piece workers, handed out one per run (doc 08 §7, doc 03 §5).\n\n// PieceWorker serializes its requests, so one shared worker makes every\n// connector step on the server wait for every other.\n\n// The pool answers both halves of that: N sessions run at once, and each holds\n// a child of its own, killed when the session closes.\n\n// So a run starts on a clean heap, waits only on itself, and takes nothing\n// with it when it ends.\nimport {\n PieceWorker,\n type IPieceWorker,\n type PieceWorkerOptions,\n type PieceWorkerResult,\n type RequestOptions,\n} from \"./host.js\";\nimport type {\n CheckConnectionRequest,\n DescribePieceRequest,\n ResolveOptionsRequest,\n RunActionRequest,\n TriggerHookRequest,\n} from \"./protocol.js\";\n\n// Thrown when a session asks for a slot the pool will not queue.\n\n// The pool queues without limit unless an operator caps it, so this only\n// appears where someone chose failing fast over waiting.\nexport class PieceWorkerPoolBusyError extends Error {\n constructor(size: number, waiting: number) {\n super(\n `All ${size} piece workers are busy and ${waiting} runs are already waiting`,\n );\n this.name = \"PieceWorkerPoolBusyError\";\n }\n}\n\nexport class PieceWorkerSessionClosedError extends Error {\n constructor() {\n super(\"This piece worker session is closed\");\n this.name = \"PieceWorkerSessionClosedError\";\n }\n}\n\nexport interface PieceWorkerPoolOptions extends PieceWorkerOptions {\n // How many sessions may hold a worker at once. Each one is a child process,\n // so this is the server's real connector concurrency.\n size?: number;\n // How many sessions may wait for a slot. 0 is unbounded, which is what the\n // single shared worker effectively did: latency rather than failure.\n maxQueueDepth?: number;\n // Builds one worker. Defaults to a forked child; a test or a remote\n // deployment substitutes its own.\n createWorker?: (options: PieceWorkerOptions) => IPieceWorker;\n}\n\nconst DEFAULT_SIZE = 4;\n\ninterface Waiter {\n session: PieceWorkerSession;\n resolve: () => void;\n reject: (error: unknown) => void;\n}\n\n// One run's claim on a worker. Lazy on purpose: a run whose steps are all\n// document or core blocks never takes a slot and never forks a child.\nexport class PieceWorkerSession implements IPieceWorker {\n private worker: IPieceWorker | undefined;\n private taking: Promise<IPieceWorker> | undefined;\n private held = false;\n private closed = false;\n\n constructor(private readonly pool: PieceWorkerPool) {}\n\n runAction(\n request: RunActionRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.runAction(request, options));\n }\n\n resolveOptions(\n request: ResolveOptionsRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.resolveOptions(request, options));\n }\n\n checkConnection(\n request: CheckConnectionRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.checkConnection(request, options));\n }\n\n describePiece(\n request: DescribePieceRequest,\n options?: { timeoutMs?: number },\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.describePiece(request, options));\n }\n\n runTriggerHook(\n request: TriggerHookRequest,\n options?: RequestOptions,\n ): Promise<PieceWorkerResult> {\n return this.request((worker) => worker.runTriggerHook(request, options));\n }\n\n // Kills this session's child and frees its slot for whoever is waiting.\n\n // Idempotent: a caller closing in a `finally` must not have to care whether\n // the run failed before it ever reached a piece step.\n close(): void {\n if (this.closed) return;\n this.closed = true;\n // Still queueing: the request fails now rather than when a slot happens\n // to free, which for a saturated pool may be never.\n this.pool.cancel(this);\n this.worker?.dispose();\n this.worker = undefined;\n this.pool.forget(this);\n this.giveBack();\n }\n\n // IPieceWorker's teardown is this session's close: a caller holding one\n // through the interface ends the run's child, not the pool.\n dispose(): void {\n this.close();\n }\n\n private async request<T>(fn: (worker: IPieceWorker) => Promise<T>) {\n const worker = await this.take();\n // Closed while this was waiting — a shutdown landing mid-run.\n\n // Its worker is already killed, and PieceWorker forks a replacement on the\n // next request, so dispatching now would leak a child the pool never sees.\n if (this.closed) throw new PieceWorkerSessionClosedError();\n return fn(worker);\n }\n\n private take(): Promise<IPieceWorker> {\n if (this.closed) {\n return Promise.reject(new PieceWorkerSessionClosedError());\n }\n if (this.worker) return Promise.resolve(this.worker);\n // Memoized: two steps entering at once must not take two slots, even\n // though the coordinator runs a run's steps one after another.\n this.taking ??= this.acquire();\n return this.taking;\n }\n\n private async acquire(): Promise<IPieceWorker> {\n await this.pool.acquire(this);\n this.held = true;\n // Closed while queueing: hand the slot straight back rather than fork a\n // child for a run that is already over.\n if (this.closed) {\n this.giveBack();\n throw new PieceWorkerSessionClosedError();\n }\n this.worker = this.pool.build();\n return this.worker;\n }\n\n private giveBack(): void {\n if (!this.held) return;\n this.held = false;\n this.pool.release();\n }\n}\n\n// Sized once at construction. Sessions queue for a slot in the order they ask\n// for one, so a burst of runs is served first-come rather than at random.\nexport class PieceWorkerPool {\n readonly size: number;\n private readonly maxQueueDepth: number;\n private readonly createWorker: (options: PieceWorkerOptions) => IPieceWorker;\n private readonly workerOptions: PieceWorkerOptions;\n private readonly sessions = new Set<PieceWorkerSession>();\n private readonly waiters: Waiter[] = [];\n private inUse = 0;\n private disposed = false;\n\n constructor(options: PieceWorkerPoolOptions = {}) {\n const { size, maxQueueDepth, createWorker, ...workerOptions } = options;\n this.size = Math.max(1, Math.trunc(size ?? DEFAULT_SIZE));\n this.maxQueueDepth = Math.max(0, Math.trunc(maxQueueDepth ?? 0));\n this.createWorker = createWorker ?? ((o) => new PieceWorker(o));\n this.workerOptions = workerOptions;\n }\n\n // A run's claim on a worker, for the length of the run. Free until its\n // first piece step, so opening one per run costs nothing.\n session(): PieceWorkerSession {\n if (this.disposed) throw new Error(\"Piece worker pool is disposed\");\n const session = new PieceWorkerSession(this);\n this.sessions.add(session);\n return session;\n }\n\n // Sessions holding a worker, and sessions waiting for one. The wait is what\n // a queue-depth alarm watches: it is invisible in a run's own timings.\n stats(): { size: number; active: number; waiting: number } {\n return {\n size: this.size,\n active: this.inUse,\n waiting: this.waiters.length,\n };\n }\n\n // Closes every session — killing the children mid-run — and refuses the ones\n // still queueing. For shutdown; a live run does not survive it.\n dispose(): void {\n this.disposed = true;\n // Queued sessions hear why before the closing below turns their wait into\n // the more ordinary \"your session closed\".\n for (const waiter of this.waiters.splice(0)) {\n waiter.reject(new Error(\"Piece worker pool is disposed\"));\n }\n for (const session of [...this.sessions]) session.close();\n this.sessions.clear();\n }\n\n /** @internal — a session taking its slot. */\n acquire(session: PieceWorkerSession): Promise<void> {\n if (this.disposed) {\n return Promise.reject(new Error(\"Piece worker pool is disposed\"));\n }\n if (this.inUse < this.size) {\n this.inUse++;\n return Promise.resolve();\n }\n if (this.maxQueueDepth > 0 && this.waiters.length >= this.maxQueueDepth) {\n return Promise.reject(\n new PieceWorkerPoolBusyError(this.size, this.waiters.length),\n );\n }\n return new Promise<void>((resolve, reject) => {\n this.waiters.push({ session, resolve, reject });\n });\n }\n\n /** @internal — a session that closed while queueing. */\n cancel(session: PieceWorkerSession): void {\n const index = this.waiters.findIndex((w) => w.session === session);\n if (index < 0) return;\n const [waiter] = this.waiters.splice(index, 1);\n waiter.reject(new PieceWorkerSessionClosedError());\n }\n\n /** @internal — a session giving its slot back. */\n release(): void {\n const next = this.waiters.shift();\n // Handed straight on rather than counted down and up again, so a slot\n // freed with someone waiting cannot be taken by a later arrival.\n if (next) {\n next.resolve();\n return;\n }\n this.inUse = Math.max(0, this.inUse - 1);\n }\n\n /** @internal — one child for one session. */\n build(): IPieceWorker {\n return this.createWorker(this.workerOptions);\n }\n\n /** @internal — a session that closed itself. */\n forget(session: PieceWorkerSession): void {\n this.sessions.delete(session);\n }\n}\n","// Secret references and the provider/store seams. Refs are server-minted\n// random ids — stable handles over mutable values, never content hashes.\n\nexport const SECRET_REF_PREFIX = \"secret://v1:\";\n\nconst SECRET_ID_PATTERN = /^[0-9a-f]{32}$/;\n\n// Read seam consumed by the engine (connection resolution).\nexport interface SecretProvider {\n get(ref: string): Promise<string>;\n}\n\nexport interface SecretStat {\n ref: string;\n label: string | null;\n version: number;\n status: \"ACTIVE\" | \"DELETED\";\n createdAt: string;\n updatedAt: string;\n}\n\n// Full lifecycle, implemented by managed backends. `get` is execution-context\n// only and must never be exposed over a transport.\nexport interface SecretStore extends SecretProvider {\n create(input: { value: string; label?: string }): Promise<SecretStat>;\n rotate(ref: string, value: string): Promise<SecretStat>;\n stat(ref: string): Promise<SecretStat>;\n list(): Promise<SecretStat[]>;\n delete(ref: string): Promise<void>;\n}\n\nexport class SecretNotFoundError extends Error {\n constructor(ref: string) {\n super(`No secret found for ref \"${ref}\"`);\n this.name = \"SecretNotFoundError\";\n }\n}\n\nexport class SecretDeletedError extends Error {\n constructor(ref: string) {\n super(`Secret \"${ref}\" has been deleted`);\n this.name = \"SecretDeletedError\";\n }\n}\n\nexport class InvalidSecretRefError extends Error {\n constructor(ref: string) {\n super(\n `Invalid secret ref \"${ref}\"; expected ${SECRET_REF_PREFIX}<32 hex chars>`,\n );\n this.name = \"InvalidSecretRefError\";\n }\n}\n\nexport function isSecretRef(ref: string): boolean {\n return (\n ref.startsWith(SECRET_REF_PREFIX) &&\n SECRET_ID_PATTERN.test(ref.slice(SECRET_REF_PREFIX.length))\n );\n}\n\n// Returns the 32-hex id; throws on anything else.\nexport function parseSecretRef(ref: string): string {\n if (!isSecretRef(ref)) throw new InvalidSecretRefError(ref);\n return ref.slice(SECRET_REF_PREFIX.length);\n}\n\nexport function secretRefFromId(id: string): string {\n if (!SECRET_ID_PATTERN.test(id)) throw new InvalidSecretRefError(id);\n return `${SECRET_REF_PREFIX}${id}`;\n}\n\nexport class InMemorySecretProvider implements SecretProvider {\n private readonly secrets: Map<string, string>;\n\n constructor(secrets: Record<string, string>) {\n this.secrets = new Map(Object.entries(secrets));\n }\n\n get(ref: string): Promise<string> {\n const value = this.secrets.get(ref);\n if (value === undefined)\n return Promise.reject(new SecretNotFoundError(ref));\n return Promise.resolve(value);\n }\n}\n","// Minimal {{path}} expression resolution over the run scope (doc 08 §4.6).\n// A whole-string expression yields the raw value; embedded ones interpolate.\n\nexport interface ExpressionScope {\n trigger?: unknown;\n steps: Record<string, { output: unknown }>;\n variables: Record<string, unknown>;\n}\n\nconst WHOLE_EXPRESSION = /^\\{\\{\\s*([^{}]+?)\\s*\\}\\}$/;\nconst EMBEDDED_EXPRESSION = /\\{\\{\\s*([^{}]+?)\\s*\\}\\}/g;\n\nexport function lookupPath(scope: ExpressionScope, path: string): unknown {\n let current: unknown = scope;\n for (const segment of path.split(\".\")) {\n if (current === null || typeof current !== \"object\") return undefined;\n current = (current as Record<string, unknown>)[segment];\n }\n return current;\n}\n\nconst STRING_LITERAL = /^(['\"])(.*)\\1$/;\n\n// \"a.b || c.d || 'default'\": first term that isn't undefined/null/\"\" wins.\nexport function resolveExpression(\n scope: ExpressionScope,\n expression: string,\n): unknown {\n for (const term of expression.split(\"||\")) {\n const trimmed = term.trim();\n if (!trimmed) continue;\n const literal = STRING_LITERAL.exec(trimmed);\n const value = literal ? literal[2] : lookupPath(scope, trimmed);\n if (value !== undefined && value !== null && value !== \"\") return value;\n }\n return undefined;\n}\n\nfunction interpolate(value: unknown): string {\n if (value === undefined || value === null) return \"\";\n if (typeof value === \"object\") return JSON.stringify(value);\n return String(value as string | number | boolean);\n}\n\nexport function resolveExpressions(\n value: unknown,\n scope: ExpressionScope,\n): unknown {\n if (typeof value === \"string\") {\n const whole = WHOLE_EXPRESSION.exec(value);\n if (whole) return resolveExpression(scope, whole[1]);\n return value.replaceAll(EMBEDDED_EXPRESSION, (_, path: string) =>\n interpolate(resolveExpression(scope, path)),\n );\n }\n if (Array.isArray(value)) {\n return value.map((item) => resolveExpressions(item, scope));\n }\n if (value !== null && typeof value === \"object\") {\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).map(([key, entry]) => [\n key,\n resolveExpressions(entry, scope),\n ]),\n );\n }\n return value;\n}\n\n// Truthiness of a resolved condition; the strings \"false\" and \"0\" are falsy.\nexport function evaluateCondition(\n condition: string,\n scope: ExpressionScope,\n): boolean {\n const resolved = resolveExpressions(condition, scope);\n if (resolved === \"false\" || resolved === \"0\") return false;\n return Boolean(resolved);\n}\n","// Resolves connection references into the auth value a piece reads from\n// ctx.auth, shaped per Activepieces auth kind (powerhouse/connection state).\n\nimport type { SecretProvider } from \"./secrets.js\";\nimport type { WorkflowDefinition } from \"./types.js\";\nimport {\n AppConnectionType,\n type AppConnectionValue,\n type BasicAuthConnectionValue,\n} from \"@powerhousedao/pieces-framework\";\n\n// The powerhouse/connection document model's own enum: the framework's\n// AppConnectionType, minus its OAuth2 variants, with NO_AUTH persisted as NONE.\nexport type ConnectionAuthType =\n | `${AppConnectionType.SECRET_TEXT}`\n | `${AppConnectionType.BASIC_AUTH}`\n | `${AppConnectionType.CUSTOM_AUTH}`\n | `${AppConnectionType.OAUTH2}`\n | `${AppConnectionType.OIDC}`\n | \"NONE\";\n\n// Mirrors the powerhouse/connection document state the resolver consumes.\nexport interface ConnectionSource {\n authType: ConnectionAuthType;\n config?: Record<string, unknown>;\n secretRefs?: { name: string; ref: string }[];\n}\n\n// Which step is asking. A resolver needs it to check the request against the\n// run's binding rather than trust the id it was handed.\n\n// piecePackage is the package the caller already resolved the block type to,\n// so a resolver never re-parses a block type to learn which piece is asking.\nexport interface ConnectionRequest {\n blockType: string;\n piecePackage?: string;\n stepId?: string;\n stepKey?: string;\n}\n\n// The auth a piece reads, plus the concrete secret strings behind it. The\n// second half is what value-based journal redaction matches on.\nexport interface ResolvedConnection {\n auth: unknown;\n secretValues: string[];\n}\n\nexport interface EngineConnectionResolver {\n resolve(connectionId: string, request?: ConnectionRequest): Promise<unknown>;\n // Optional: hosts that predate redaction keep working without it. It takes\n // the same request, so authorization is not skipped to get the secrets.\n resolveWithSecrets?(\n connectionId: string,\n request?: ConnectionRequest,\n ): Promise<ResolvedConnection>;\n}\n\nexport class ConnectionNotFoundError extends Error {\n constructor(connectionId: string) {\n super(`No connection registered for id \"${connectionId}\"`);\n this.name = \"ConnectionNotFoundError\";\n }\n}\n\n// A step reached for a connection its workflow definition never declared.\n// Raised before any lookup, so it cannot say whether the id exists.\nexport class ConnectionNotBoundError extends Error {\n constructor(connectionId: string) {\n super(`Connection \"${connectionId}\" is not bound to this workflow`);\n this.name = \"ConnectionNotBoundError\";\n }\n}\n\nexport class UnsupportedAuthTypeError extends Error {\n constructor(authType: string) {\n super(`Auth type \"${authType}\" is not supported yet`);\n this.name = \"UnsupportedAuthTypeError\";\n }\n}\n\nasync function resolveSecrets(\n source: ConnectionSource,\n secrets: SecretProvider,\n): Promise<Record<string, string>> {\n const entries = await Promise.all(\n (source.secretRefs ?? []).map(\n async ({ name, ref }) => [name, await secrets.get(ref)] as const,\n ),\n );\n return Object.fromEntries(entries);\n}\n\n// Values are AppConnectionValue-shaped: pieces read auth.secret_text,\n// auth.username/password or auth.props.* depending on their auth kind.\nexport async function shapeAuthValue(\n source: ConnectionSource,\n secrets: SecretProvider,\n): Promise<unknown> {\n return (await shapeConnection(source, secrets)).auth;\n}\n\n// Only the values behind `secretRefs` are reported as secret: config fields\n// (a base URL, a username) are not, and redacting them would cost debuggability.\nexport async function shapeConnection(\n source: ConnectionSource,\n secrets: SecretProvider,\n): Promise<ResolvedConnection> {\n const resolved = await resolveSecrets(source, secrets);\n return {\n auth: shapeAuth(source, resolved),\n secretValues: Object.values(resolved),\n };\n}\n\n// NONE is the persisted value; the framework's NO_AUTH case carries no value a\n// piece reads, so ctx.auth stays undefined rather than becoming that shape.\nfunction shapeAuth(\n source: ConnectionSource,\n resolved: Record<string, string>,\n): AppConnectionValue | undefined {\n switch (source.authType) {\n case \"NONE\":\n return undefined;\n case \"SECRET_TEXT\": {\n const values = Object.values(resolved);\n if (values.length !== 1) {\n throw new Error(\n `SECRET_TEXT connection must have exactly one secret ref, got ${values.length}`,\n );\n }\n return { type: AppConnectionType.SECRET_TEXT, secret_text: values[0] };\n }\n case \"BASIC_AUTH\": {\n const props = { ...source.config, ...resolved };\n return {\n type: AppConnectionType.BASIC_AUTH,\n username: props.username,\n password: props.password,\n } as BasicAuthConnectionValue;\n }\n case \"CUSTOM_AUTH\": {\n return {\n type: AppConnectionType.CUSTOM_AUTH,\n props: { ...source.config, ...resolved },\n };\n }\n default:\n throw new UnsupportedAuthTypeError(source.authType);\n }\n}\n\nexport class StaticConnectionResolver implements EngineConnectionResolver {\n private readonly connections: Map<string, ConnectionSource>;\n\n constructor(\n connections: Record<string, ConnectionSource>,\n private readonly secrets: SecretProvider,\n ) {\n this.connections = new Map(Object.entries(connections));\n }\n\n resolve(connectionId: string): Promise<unknown> {\n return this.resolveWithSecrets(connectionId).then(\n (resolved) => resolved.auth,\n );\n }\n\n resolveWithSecrets(connectionId: string): Promise<ResolvedConnection> {\n const source = this.connections.get(connectionId);\n if (!source) {\n return Promise.reject(new ConnectionNotFoundError(connectionId));\n }\n return shapeConnection(source, this.secrets);\n }\n}\n\n// Every connection a definition declares: the trigger's and each step's.\n\n// A templated id is left out — connectionId is never expression-resolved, so\n// it names no connection and a step cannot pick credentials at run time.\nexport function declaredConnectionIds(\n definition: WorkflowDefinition,\n): ReadonlySet<string> {\n const declared = new Set<string>();\n const declare = (connectionId: string | null | undefined) => {\n if (connectionId && !connectionId.includes(\"{{\"))\n declared.add(connectionId);\n };\n declare(definition.trigger?.connectionId);\n for (const step of definition.steps) declare(step.connectionId);\n return declared;\n}\n\n// The binding in force for the caller, or undefined when there is none. Read\n// per call because one executor serves every concurrent run.\nexport type ConnectionBindingLookup = () => ReadonlySet<string> | undefined;\n\n// Server-side connection binding (doc 08 §10): a step resolves only what the\n// definition its run pinned declared.\n\n// Without a binding nothing resolves, so a path that fails to establish one\n// fails closed.\nexport class BoundConnectionResolver implements EngineConnectionResolver {\n // Present only when the inner resolver has it, because its absence is what\n // tells a caller to fall back to guessing the secrets from the auth value.\n readonly resolveWithSecrets?: (\n connectionId: string,\n request?: ConnectionRequest,\n ) => Promise<ResolvedConnection>;\n\n constructor(\n private readonly inner: EngineConnectionResolver,\n private readonly binding: ConnectionBindingLookup,\n private readonly onRefused?: (\n connectionId: string,\n request?: ConnectionRequest,\n ) => void,\n ) {\n const withSecrets = inner.resolveWithSecrets?.bind(inner);\n if (!withSecrets) return;\n this.resolveWithSecrets = (connectionId, request) =>\n this.bound(connectionId, request)\n ? withSecrets(connectionId, request)\n : Promise.reject(new ConnectionNotBoundError(connectionId));\n }\n\n resolve(connectionId: string, request?: ConnectionRequest): Promise<unknown> {\n if (!this.bound(connectionId, request)) {\n return Promise.reject(new ConnectionNotBoundError(connectionId));\n }\n return this.inner.resolve(connectionId, request);\n }\n\n // Both paths ask the same question, so neither is a way around it.\n private bound(connectionId: string, request?: ConnectionRequest): boolean {\n if (this.binding()?.has(connectionId)) return true;\n this.onRefused?.(connectionId, request);\n return false;\n }\n}\n","import { randomUUID } from \"node:crypto\";\nimport { mkdir, rm } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport {\n bundleResolver,\n pieceModuleRef,\n type PieceResolver,\n} from \"../activepieces/resolver.js\";\nimport type { ReactorService } from \"../activepieces/context/reactor.js\";\nimport {\n rewriteFileRefs,\n type StagedFile,\n} from \"../activepieces/context/files.js\";\nimport { PieceWorker, type IPieceWorker } from \"../activepieces/worker/host.js\";\nimport { DEFAULT_EGRESS_POLICY } from \"../activepieces/worker/egress.js\";\nimport {\n LOG_WRITE,\n OUTPUT_UPDATE,\n REACTOR_CREATE,\n REACTOR_EXECUTE,\n REACTOR_FIND,\n REACTOR_GET,\n REACTOR_MODEL,\n REACTOR_MODELS,\n STORE_DELETE,\n STORE_GET,\n STORE_PUT,\n type EgressPolicy,\n type HostCallHandlers,\n type HostNotifyHandlers,\n type PieceLogEntry,\n type StagedInput,\n} from \"../activepieces/worker/protocol.js\";\nimport type { StoreScopeName } from \"../activepieces/context/store-scope.js\";\nimport {\n collectSecretValues,\n redactError,\n redactMessage,\n rememberSecrets,\n} from \"../activepieces/worker/redact.js\";\nimport type {\n ConnectionRequest,\n EngineConnectionResolver,\n ResolvedConnection,\n} from \"./connections.js\";\nimport type { BlockExecution, BlockExecutor, BlockResult } from \"./types.js\";\n\nexport class UnknownBlockTypeError extends Error {\n constructor(blockType: string) {\n super(`No executor registered for block type \"${blockType}\"`);\n this.name = \"UnknownBlockTypeError\";\n }\n}\n\nexport class TriggerBlockAsStepError extends Error {\n constructor(blockType: string) {\n super(`Trigger block type \"${blockType}\" cannot run as a workflow step`);\n this.name = \"TriggerBlockAsStepError\";\n }\n}\n\n// Core blocks. core#branch routes on its (already resolved) condition: equal\n// to `equals` when that is set, otherwise truthiness. core#assert fails the\n// run on blank or rejected values.\nexport class CoreBlockExecutor implements BlockExecutor {\n static handles(blockType: string): boolean {\n return blockType.startsWith(\"core#\");\n }\n\n execute(execution: BlockExecution): Promise<BlockResult> {\n if (execution.blockType === \"core#branch\") {\n const { condition, equals } = execution.config as {\n condition?: unknown;\n equals?: unknown;\n };\n // Trimmed and case-insensitive: the condition is often model output.\n const normalize = (value: unknown) =>\n (typeof value === \"string\"\n ? value\n : value === undefined || value === null\n ? \"\"\n : JSON.stringify(value)\n )\n .trim()\n .toLowerCase();\n const taken =\n typeof equals === \"string\"\n ? normalize(condition) === normalize(equals)\n : Boolean(condition) && condition !== \"false\" && condition !== \"0\";\n return Promise.resolve({\n output: { condition: condition ?? null },\n port: taken ? \"true\" : \"false\",\n });\n }\n if (execution.blockType === \"core#assert\") {\n return this.assert(execution);\n }\n return Promise.reject(new UnknownBlockTypeError(execution.blockType));\n }\n\n // core#assert fails the step when its value is blank or is one of the\n // rejected values. Model output is the motivating case: an empty\n // completion, or a classifier answering the wrong question, must not flow\n // on to a step with a side effect.\n private assert(execution: BlockExecution): Promise<BlockResult> {\n const { value, rejectValues, allowValues, allowEmpty, message } =\n execution.config as {\n value?: unknown;\n rejectValues?: unknown;\n allowValues?: unknown;\n allowEmpty?: unknown;\n message?: unknown;\n };\n const text =\n typeof value === \"string\"\n ? value\n : value === undefined || value === null\n ? \"\"\n : JSON.stringify(value);\n const trimmed = text.trim();\n const fail = (reason: string) =>\n Promise.reject(\n new Error(\n typeof message === \"string\" && message\n ? message\n : `core#assert: ${reason}`,\n ),\n );\n\n if (!trimmed && allowEmpty !== true) {\n return fail(\"value is empty\");\n }\n const normalizeList = (entries: unknown) =>\n (typeof entries === \"string\"\n ? [entries]\n : Array.isArray(entries)\n ? entries\n : []\n )\n .map((entry) => String(entry).trim().toLowerCase())\n .filter(Boolean);\n\n if (normalizeList(rejectValues).includes(trimmed.toLowerCase())) {\n return fail(`value is a rejected value (\"${trimmed}\")`);\n }\n // An allow-list is the safer gate for model output: anything unforeseen\n // fails here rather than reaching a step that writes.\n const allowed = normalizeList(allowValues);\n if (allowed.length > 0 && !allowed.includes(trimmed.toLowerCase())) {\n return fail(\n `value \"${trimmed}\" is not one of the allowed values (${allowed.join(\", \")})`,\n );\n }\n return Promise.resolve({ output: { value }, port: \"next\" });\n }\n}\n\n// The host's attachment store, as the engine needs it: materialize a\n// reference to a path the worker can read, and ingest a path the worker wrote.\n// Both directions go through the filesystem, so bytes never enter IPC.\nexport interface AttachmentPort {\n read(\n ref: string,\n destPath: string,\n ): Promise<{ fileName?: string; contentType?: string }>;\n write(file: {\n path: string;\n fileName: string;\n size: number;\n contentType?: string;\n }): Promise<string>;\n}\n\nconst ATTACHMENT_REF = /^attachment:\\/\\//i;\n\n// Collects every attachment reference appearing as a string in a step config.\n// Deliberately type-agnostic: the worker decides which of them to hydrate\n// (only FILE props go through toApFile), so staging a reference no one reads\n// costs one file, while missing one would fail the step.\nfunction collectRefs(value: unknown, found: Set<string>): void {\n if (typeof value === \"string\") {\n if (ATTACHMENT_REF.test(value)) found.add(value);\n return;\n }\n if (Array.isArray(value)) {\n for (const entry of value) collectRefs(entry, found);\n return;\n }\n if (typeof value === \"object\" && value !== null) {\n for (const entry of Object.values(value)) collectRefs(entry, found);\n }\n}\n\n// The durable `ctx.store`, as the engine needs it: one call per operation, so\n// a piece that checkpoints mid-loop keeps what it wrote if the step then dies.\n\n// Which scope a step's keys belong to is the host's business; the executor is\n// shared across runs and must not decide it.\nexport interface PieceStorePort {\n get(key: string, scope: StoreScopeName): Promise<unknown>;\n put(key: string, value: unknown, scope: StoreScopeName): Promise<void>;\n delete(key: string, scope: StoreScopeName): Promise<void>;\n}\n\n// One key operation as it arrives from the worker.\ninterface StoreCallPayload {\n key?: unknown;\n value?: unknown;\n scope?: unknown;\n}\n\n// An unrecognised scope is treated as FLOW, the narrower partition: a bad\n// name must never widen what a step can reach.\nfunction storeScopeOf(payload: unknown): StoreScopeName {\n const scope = (payload as StoreCallPayload | undefined)?.scope;\n return scope === \"PROJECT\" ? \"PROJECT\" : \"FLOW\";\n}\n\nfunction storeKeyOf(payload: unknown): string {\n const key = (payload as StoreCallPayload | undefined)?.key;\n if (typeof key !== \"string\" || key === \"\") {\n throw new Error(\"Store call carried no key\");\n }\n return key;\n}\n\n// The host's half of `ctx.reactor`: the same operations the piece calls, run\n// against the reactor this host serves. See activepieces/context/reactor.ts.\n\n// Registered per step and only for a piece the host resolved locally, so a\n// fetched bundle forging these calls finds no handler and is refused.\nexport type ReactorPort = ReactorService;\n\n// Payloads arrive from the child, which runs piece code: a call is checked\n// here rather than trusted to have come from our own proxy.\nfunction reactorInput(payload: unknown): Record<string, unknown> {\n if (\n typeof payload !== \"object\" ||\n payload === null ||\n Array.isArray(payload)\n ) {\n throw new Error(\"Reactor call carried no input object\");\n }\n return payload as Record<string, unknown>;\n}\n\nfunction requiredString(\n payload: Record<string, unknown>,\n field: string,\n): string {\n const value = payload[field];\n if (typeof value !== \"string\" || value === \"\") {\n throw new Error(`Reactor call carried no \"${field}\"`);\n }\n return value;\n}\n\nfunction optionalString(\n payload: Record<string, unknown>,\n field: string,\n): string | undefined {\n const value = payload[field];\n return typeof value === \"string\" && value !== \"\" ? value : undefined;\n}\n\nfunction reactorActions(payload: Record<string, unknown>) {\n const actions = payload.actions;\n if (!Array.isArray(actions) || actions.length === 0) {\n throw new Error(\"Reactor call carried no actions\");\n }\n return actions.map((entry, index) => {\n const action = entry as Record<string, unknown> | null;\n if (!action || typeof action.type !== \"string\") {\n throw new Error(`Reactor call: actions[${index}] needs a string \"type\"`);\n }\n return {\n type: action.type,\n input: action.input,\n ...(typeof action.scope === \"string\" ? { scope: action.scope } : {}),\n };\n });\n}\n\n// A page size the host will serve. The value arrives from piece code, so it\n// is clamped here rather than trusted; a host may cap it further.\nconst MAX_FIND_LIMIT = 100;\n\nfunction findLimit(value: unknown): number | undefined {\n if (typeof value !== \"number\" || !Number.isFinite(value)) return undefined;\n return Math.min(Math.max(Math.floor(value), 1), MAX_FIND_LIMIT);\n}\n\n// The state match, as the host will accept it. Both halves must be strings and\n// the path must name something: a match with an empty path would silently pass\n// every document, which is the opposite of what a step asking to match wants.\nfunction findMatch(\n value: unknown,\n): { path: string; value: string } | undefined {\n if (typeof value !== \"object\" || value === null) return undefined;\n const record = value as Record<string, unknown>;\n const path = record.path;\n const wanted = record.value;\n if (typeof path !== \"string\" || path.trim() === \"\") return undefined;\n if (typeof wanted !== \"string\") return undefined;\n return { path: path.trim(), value: wanted };\n}\n\nexport function reactorHandlers(port: ReactorPort): HostCallHandlers {\n return {\n [REACTOR_MODELS]: () => port.models(),\n [REACTOR_MODEL]: (payload) =>\n port.model(requiredString(reactorInput(payload), \"documentType\")),\n [REACTOR_GET]: (payload) => {\n const input = reactorInput(payload);\n return port.get({\n documentId: requiredString(input, \"documentId\"),\n ...(optionalString(input, \"branch\")\n ? { branch: optionalString(input, \"branch\") }\n : {}),\n });\n },\n [REACTOR_FIND]: (payload) => {\n const input = reactorInput(payload);\n return port.find({\n ...(optionalString(input, \"documentType\")\n ? { documentType: optionalString(input, \"documentType\") }\n : {}),\n ...(optionalString(input, \"parentId\")\n ? { parentId: optionalString(input, \"parentId\") }\n : {}),\n ...(findLimit(input.limit) !== undefined\n ? { limit: findLimit(input.limit) }\n : {}),\n ...(findMatch(input.match) ? { match: findMatch(input.match) } : {}),\n ...(input.withState === true ? { withState: true } : {}),\n });\n },\n [REACTOR_CREATE]: (payload) => {\n const input = reactorInput(payload);\n return port.create({\n documentType: requiredString(input, \"documentType\"),\n ...(optionalString(input, \"name\")\n ? { name: optionalString(input, \"name\") }\n : {}),\n ...(optionalString(input, \"parentId\")\n ? { parentId: optionalString(input, \"parentId\") }\n : {}),\n });\n },\n [REACTOR_EXECUTE]: (payload) => {\n const input = reactorInput(payload);\n return port.execute({\n documentId: requiredString(input, \"documentId\"),\n ...(optionalString(input, \"branch\")\n ? { branch: optionalString(input, \"branch\") }\n : {}),\n actions: reactorActions(input),\n });\n },\n };\n}\n\n// The handlers served to a running step or trigger hook. A rejection becomes\n// the error the piece sees, which is what an over-limit write should do.\nexport function storeHandlers(port: PieceStorePort): HostCallHandlers {\n return {\n [STORE_GET]: (payload) =>\n port.get(storeKeyOf(payload), storeScopeOf(payload)),\n [STORE_PUT]: async (payload) => {\n await port.put(\n storeKeyOf(payload),\n (payload as StoreCallPayload).value,\n storeScopeOf(payload),\n );\n return null;\n },\n [STORE_DELETE]: async (payload) => {\n await port.delete(storeKeyOf(payload), storeScopeOf(payload));\n return null;\n },\n };\n}\n\nexport interface ActivepiecesBlockExecutorOptions {\n cacheDir: string;\n // Piece package name -> pinned version; the connector registry for this run.\n // A blockType may instead pin inline: \"@scope/pkg@1.2.3#action\".\n\n // A function is awaited per step, so a host whose registry loads lazily —\n // package pieces are pinned by what is installed, not by the block type —\n // answers with what it has by the time a step actually runs.\n packages?:\n | Record<string, string>\n | (() => Record<string, string> | Promise<Record<string, string>>);\n connections?: EngineConnectionResolver;\n // The worker piece steps go to. A function is asked once per step, so a\n // host handing each run its own child answers with that run's.\n worker?: IPieceWorker | (() => IPieceWorker | undefined);\n defaultTimeoutMs?: number;\n // Both are needed for ctx.files to work: a directory the host and the forked\n // worker share, and somewhere to put what the piece wrote. Without them a\n // piece calling ctx.files falls back to inline data URIs.\n stagingRoot?: string;\n attachments?: AttachmentPort;\n // Without it `ctx.store` falls back to the worker's heap, which a step\n // timeout discards.\n pieceStore?: PieceStorePort;\n // Where a block type's piece comes from. Defaults to fetching the pinned\n // version into `cacheDir`, which is what a published piece needs.\n resolver?: PieceResolver;\n // Serves `ctx.reactor`, and only to a piece the resolver answered locally.\n // Without it even a package piece finds the member throwing.\n reactor?: ReactorPort;\n // Where a step's piece may connect to. Left unset it is the default policy,\n // which refuses private address space; `null` runs the piece unrestricted.\n egress?: EgressPolicy | null;\n // Taps on a running step. Each is opt-in because it costs the worker an IPC\n // message per event, and neither is asked for unless someone reads it.\n onPieceLog?: (entry: PieceLogEntry, execution: BlockExecution) => void;\n onPartialOutput?: (output: unknown, execution: BlockExecution) => void;\n}\n\n// The notify handlers served to one step. Unlike a store call, nothing here\n// answers the piece: these are reports, and the step never waits on them.\nfunction stepTaps(\n options: ActivepiecesBlockExecutorOptions,\n execution: BlockExecution,\n values: string[],\n): HostNotifyHandlers | undefined {\n const { onPieceLog, onPartialOutput } = options;\n if (!onPieceLog && !onPartialOutput) return undefined;\n const handlers: HostNotifyHandlers = {};\n if (onPieceLog) {\n // A piece logging its own outgoing request is a common idiom, so this is\n // one of the likeliest places for a credential to reach the host log.\n handlers[LOG_WRITE] = (payload) => {\n const entry = payload as PieceLogEntry;\n // Returned, not discarded: a sink that rejects is the host's to catch.\n return onPieceLog(\n { ...entry, message: redactMessage(entry.message, { values }) },\n execution,\n );\n };\n }\n if (onPartialOutput) {\n handlers[OUTPUT_UPDATE] = (payload) => onPartialOutput(payload, execution);\n }\n return handlers;\n}\n\n// Mutated in place rather than rewrapped: callers classify on the error's\n// class, and a new one would lose that.\n\n// `stack` embeds the message as it was at construction, so a caller logging\n// the error object rather than `.message` would otherwise still print it.\nfunction redactThrown(error: unknown, values: string[]): unknown {\n if (error instanceof Error) {\n error.message = redactMessage(error.message, { values });\n if (error.stack) error.stack = redactMessage(error.stack, { values });\n return rememberSecrets(error, values);\n }\n return rememberSecrets(redactError(error, { values }), values);\n}\n\nexport type BlockKind = \"action\" | \"trigger\";\n\nexport interface ParsedBlockType {\n packageName: string;\n version: string;\n kind: BlockKind;\n // Action or trigger name within the piece.\n name: string;\n}\n\nconst TRIGGER_FRAGMENT = \"trigger:\";\n\n// \"<pkg>[@<version>]#<action>\" or \"<pkg>[@<version>]#trigger:<trigger>\" —\n// the version after the scope-less \"@\" wins over the registry.\nexport function parseBlockType(\n blockType: string,\n packages: Record<string, string> = {},\n): ParsedBlockType | undefined {\n const separator = blockType.lastIndexOf(\"#\");\n if (separator <= 0) return undefined;\n const packageSpec = blockType.slice(0, separator);\n const fragment = blockType.slice(separator + 1);\n const isTrigger = fragment.startsWith(TRIGGER_FRAGMENT);\n const name = isTrigger ? fragment.slice(TRIGGER_FRAGMENT.length) : fragment;\n if (!name) return undefined;\n const kind: BlockKind = isTrigger ? \"trigger\" : \"action\";\n const versionAt = packageSpec.indexOf(\"@\", 1);\n if (versionAt > 0) {\n return {\n packageName: packageSpec.slice(0, versionAt),\n version: packageSpec.slice(versionAt + 1),\n kind,\n name,\n };\n }\n const version = packages[packageSpec] as string | undefined;\n if (!version) return undefined;\n return { packageName: packageSpec, version, kind, name };\n}\n\n// Executes \"<packageName>#<actionName>\" block types through the piece worker.\nexport class ActivepiecesBlockExecutor implements BlockExecutor {\n // Only set when nothing was supplied: the fallback this executor owns and\n // must dispose. A supplied worker belongs to whoever supplied it.\n private own: PieceWorker | undefined;\n\n private readonly resolver: PieceResolver;\n\n constructor(private readonly options: ActivepiecesBlockExecutorOptions) {\n this.resolver =\n options.resolver ?? bundleResolver({ cacheDir: options.cacheDir });\n }\n\n private worker(): IPieceWorker {\n const supplied = this.options.worker;\n if (typeof supplied === \"function\") {\n const worker = supplied();\n if (worker) return worker;\n } else if (supplied) {\n return supplied;\n }\n return (this.own ??= new PieceWorker());\n }\n\n private packages(): Promise<Record<string, string>> {\n const supplied = this.options.packages;\n return Promise.resolve(\n typeof supplied === \"function\" ? supplied() : (supplied ?? {}),\n );\n }\n\n async execute(execution: BlockExecution): Promise<BlockResult> {\n const parsed = parseBlockType(execution.blockType, await this.packages());\n if (!parsed) {\n throw new UnknownBlockTypeError(execution.blockType);\n }\n if (parsed.kind !== \"action\") {\n throw new TriggerBlockAsStepError(execution.blockType);\n }\n\n // One staging directory per execution, removed in the finally below. A\n // host crash can still leave one behind, which is why it lives under a\n // root the host can sweep at startup.\n const stagingDir = this.options.stagingRoot\n ? path.join(this.options.stagingRoot, randomUUID())\n : undefined;\n\n // Bundle fetch and connection resolution belong inside the catch: a secret\n // provider or a resolver can fail with the credential in its own message.\n let redactValues: string[] = [];\n try {\n const piece = await this.resolver.resolve(\n parsed.packageName,\n parsed.version,\n );\n const connection = await this.resolveConnection(execution.connectionId, {\n blockType: execution.blockType,\n piecePackage: parsed.packageName,\n stepId: execution.step.id,\n stepKey: execution.step.key,\n });\n const auth = connection?.auth;\n redactValues = connection?.secretValues ?? [];\n\n const timeoutMs = execution.step.timeoutSeconds\n ? execution.step.timeoutSeconds * 1000\n : this.options.defaultTimeoutMs;\n const stagedInputs = await this.stageInputs(execution.config, stagingDir);\n const pieceStore = this.options.pieceStore;\n const notifications = stepTaps(this.options, execution, redactValues);\n const egress =\n this.options.egress === undefined\n ? DEFAULT_EGRESS_POLICY\n : this.options.egress;\n // A fetched bundle never reaches the reactor: the handlers below are the\n // only way in, and they are registered for a local piece alone.\n const reactor = piece.local ? this.options.reactor : undefined;\n const result = await this.worker().runAction(\n {\n ...pieceModuleRef(piece),\n actionName: parsed.name,\n propsValue: execution.config as Record<string, unknown>,\n auth,\n ...(redactValues.length > 0 ? { redactValues } : {}),\n ...(stagingDir ? { stagingDir } : {}),\n ...(stagedInputs ? { stagedInputs } : {}),\n ...(pieceStore ? { durableStore: true } : {}),\n ...(reactor ? { reactorAccess: true } : {}),\n ...(this.options.onPieceLog ? { captureLogs: true } : {}),\n ...(this.options.onPartialOutput ? { liveOutput: true } : {}),\n ...(egress ? { egress } : {}),\n },\n {\n ...(timeoutMs ? { timeoutMs } : {}),\n ...(pieceStore || reactor\n ? {\n hostCalls: {\n ...(pieceStore ? storeHandlers(pieceStore) : {}),\n ...(reactor ? reactorHandlers(reactor) : {}),\n },\n }\n : {}),\n ...(notifications ? { notifications } : {}),\n },\n );\n return {\n output: await this.ingestFiles(result.output, result.files),\n redactValues,\n };\n } catch (error) {\n // The child already stripped what it threw; this covers what the host\n // itself raises (bundle fetch, connection resolution, file ingest).\n throw redactThrown(error, redactValues);\n } finally {\n if (stagingDir) await rm(stagingDir, { recursive: true, force: true });\n }\n }\n\n private async resolveConnection(\n connectionId: string | null | undefined,\n request: ConnectionRequest,\n ): Promise<ResolvedConnection | undefined> {\n const connections = this.options.connections;\n if (!connectionId || !connections) return undefined;\n // The request travels with both, so taking the secret-bearing path never\n // means skipping the check on who is asking.\n if (connections.resolveWithSecrets) {\n return connections.resolveWithSecrets(connectionId, request);\n }\n const auth = await connections.resolve(connectionId, request);\n return { auth, secretValues: [...collectSecretValues(auth)] };\n }\n\n private async stageInputs(\n config: unknown,\n stagingDir: string | undefined,\n ): Promise<StagedInput[] | undefined> {\n const port = this.options.attachments;\n if (!stagingDir || !port) return undefined;\n const refs = new Set<string>();\n collectRefs(config, refs);\n if (refs.size === 0) return undefined;\n await mkdir(stagingDir, { recursive: true });\n const staged: StagedInput[] = [];\n let index = 0;\n for (const ref of refs) {\n const destPath = path.join(stagingDir, `in-${index++}`);\n const meta = await port.read(ref, destPath);\n staged.push({ ref, path: destPath, ...meta });\n }\n return staged;\n }\n\n // A provisional apfile:// token only becomes a real reference once the step\n // has returned, so a piece that writes a file and then reads it back by URL\n // within the same run would not work. No action needs that today; the fix is\n // a bidirectional worker channel, which is its own design.\n private async ingestFiles(\n output: unknown,\n files: StagedFile[] | undefined,\n ): Promise<unknown> {\n if (!files || files.length === 0) return output;\n const port = this.options.attachments;\n if (!port) {\n throw new Error(\n `The action wrote ${files.length} file(s) through ctx.files, but no attachment store is configured for this reactor`,\n );\n }\n const refs = new Map<string, string>();\n for (const file of files) {\n refs.set(\n file.token,\n await port.write({\n path: file.path,\n fileName: file.fileName,\n size: file.size,\n contentType: file.contentType,\n }),\n );\n }\n return rewriteFileRefs(output, refs);\n }\n\n dispose(): void {\n this.own?.dispose();\n this.own = undefined;\n }\n}\n\n// Routes explicit handlers first, then core#*, then the piece executor.\n// Handlers let a host add block types of its own, served in its process.\nexport class CompositeBlockExecutor implements BlockExecutor {\n private readonly core = new CoreBlockExecutor();\n\n constructor(\n private readonly pieces: BlockExecutor,\n private readonly handlers: Record<string, BlockExecutor> = {},\n ) {}\n\n execute(execution: BlockExecution): Promise<BlockResult> {\n const handler = this.handlers[execution.blockType] as\n | BlockExecutor\n | undefined;\n if (handler) return handler.execute(execution);\n if (CoreBlockExecutor.handles(execution.blockType)) {\n return this.core.execute(execution);\n }\n return this.pieces.execute(execution);\n }\n}\n","import {\n containsRedactedMarker,\n redact,\n redactMessage,\n secretsFor,\n} from \"../activepieces/worker/redact.js\";\nimport {\n evaluateCondition,\n resolveExpressions,\n type ExpressionScope,\n} from \"./expressions.js\";\nimport type {\n BlockExecutor,\n StepExecutionRecord,\n WorkflowDefinition,\n WorkflowRunResult,\n WorkflowStepDef,\n} from \"./types.js\";\n\nexport interface RunWorkflowOptions {\n definition: WorkflowDefinition;\n executor: BlockExecutor;\n // Exposed to expressions as {{trigger.payload...}}.\n triggerPayload?: unknown;\n // Journaled outputs from a prior run, keyed by step id; matching steps\n // replay (output injected, port re-taken) instead of executing.\n completedSteps?: Map<string, { output?: unknown; port?: string | null }>;\n // Called as each step reaches a terminal state, so a run that dies\n // mid-flight leaves the steps it finished behind. Ordinal is execution\n // order; skips are excluded, being knowable only once the run completes.\n onStep?: (\n record: StepExecutionRecord,\n ordinal: number,\n ) => void | Promise<void>;\n}\n\nfunction errorMessage(error: unknown): string {\n if (error instanceof Error) return error.message;\n return String(error);\n}\n\n// A record is journal material, read back by the editor and kept in the\n// database, so it never carries the live value a downstream step reads.\nfunction journaled(value: unknown, values: string[] | undefined): unknown {\n return value === undefined ? undefined : redact(value, { values });\n}\n\n// Sequential v1 of the RunCoordinator (doc 08 §7.3): walks the steps+edges\n// graph, resolving each step's config against prior outputs before executing.\nexport async function runWorkflow(\n options: RunWorkflowOptions,\n): Promise<WorkflowRunResult> {\n const { definition, executor } = options;\n const scope: ExpressionScope = {\n trigger: { payload: options.triggerPayload },\n steps: {},\n variables: Object.fromEntries(\n (definition.variables ?? []).map((v) => [v.key, v.value ?? null]),\n ),\n };\n\n const records = new Map<string, StepExecutionRecord>();\n // edgeId -> taken; an edge is decided once its source ran or was skipped.\n const edgeDecisions = new Map<string, boolean>();\n let runFailed: string | undefined;\n let executedCount = 0;\n\n // A failing journal write must not cost us the step's completed work: the\n // run carries on, and finishRun's final sweep repairs the missing row.\n const journal = async (record: StepExecutionRecord) => {\n if (!options.onStep) return;\n const ordinal = executedCount++;\n try {\n await options.onStep(record, ordinal);\n } catch {\n // Durability is the bonus here; run correctness is not at stake.\n }\n };\n\n const decideOutgoing = (sourceId: string, port: string | undefined) => {\n for (const edge of definition.edges) {\n if (edge.from !== sourceId) continue;\n const portMatches = port !== undefined && edge.port === port;\n const taken =\n portMatches &&\n (!edge.condition || evaluateCondition(edge.condition, scope));\n edgeDecisions.set(edge.id, taken);\n }\n };\n\n // Trigger edges fire on the trigger's implicit \"next\" port.\n if (definition.trigger) {\n decideOutgoing(definition.trigger.id, \"next\");\n }\n\n const inboundEdges = (step: WorkflowStepDef) =>\n definition.edges.filter((edge) => edge.to === step.id);\n\n const isEntryStep = (step: WorkflowStepDef) =>\n !definition.trigger && inboundEdges(step).length === 0;\n\n const skipStep = (step: WorkflowStepDef) => {\n records.set(step.id, {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"SKIPPED\",\n });\n decideOutgoing(step.id, undefined);\n };\n\n // The journal keeps a redacted copy, so a replay would hand the marker to\n // the next step. Refusing is loud; replaying it would be silently wrong.\n const refuseReplay = (step: WorkflowStepDef) => {\n const error =\n `Journaled output of step \"${step.key}\" was redacted and cannot be ` +\n \"replayed; fire the workflow again instead of rerunning it\";\n records.set(step.id, {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"FAILED\",\n error,\n });\n runFailed = error;\n };\n\n const executeStep = async (step: WorkflowStepDef) => {\n const replay = options.completedSteps?.get(step.id);\n if (replay) {\n if (containsRedactedMarker(replay.output)) {\n refuseReplay(step);\n return;\n }\n const port = replay.port ?? \"next\";\n const record: StepExecutionRecord = {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"REPLAYED\",\n output: replay.output,\n port,\n };\n records.set(step.id, record);\n await journal(record);\n scope.steps[step.key] = { output: replay.output };\n decideOutgoing(step.id, port);\n return;\n }\n const input = resolveExpressions(step.config, scope);\n try {\n const result = await executor.execute({\n blockType: step.blockType,\n config: input,\n connectionId: step.connectionId,\n step,\n });\n const port = result.port ?? \"next\";\n const record: StepExecutionRecord = {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"SUCCEEDED\",\n input: journaled(input, result.redactValues),\n output: journaled(result.output, result.redactValues),\n port,\n };\n records.set(step.id, record);\n await journal(record);\n scope.steps[step.key] = { output: result.output };\n decideOutgoing(step.id, port);\n } catch (error) {\n // A failed step is exactly where an input gets inspected, so it is\n // redacted with the same secrets the successful path uses.\n const values = secretsFor(error);\n const detail = redactMessage(errorMessage(error), { values });\n const record: StepExecutionRecord = {\n stepId: step.id,\n key: step.key,\n blockType: step.blockType,\n status: \"FAILED\",\n input: journaled(input, values),\n error: detail,\n };\n records.set(step.id, record);\n await journal(record);\n decideOutgoing(step.id, \"error\");\n const errorHandled = definition.edges.some(\n (edge) => edge.from === step.id && edgeDecisions.get(edge.id),\n );\n if (!errorHandled) {\n runFailed = `Step \"${step.key}\" failed: ${detail}`;\n }\n }\n };\n\n let progressed = true;\n while (progressed && !runFailed) {\n progressed = false;\n for (const step of definition.steps) {\n if (records.has(step.id)) continue;\n const inbound = inboundEdges(step);\n if (isEntryStep(step)) {\n await executeStep(step);\n progressed = true;\n // Independent roots are otherwise free to run their side effects\n // before the outer loop notices the run is already over.\n if (runFailed) break;\n continue;\n }\n if (inbound.length === 0) continue;\n const decided = inbound.every((edge) => edgeDecisions.has(edge.id));\n if (!decided) continue;\n const reachable = inbound.some((edge) => edgeDecisions.get(edge.id));\n if (reachable) {\n await executeStep(step);\n } else {\n skipStep(step);\n }\n progressed = true;\n if (runFailed) break;\n }\n }\n\n // Steps never reached (dangling, cyclic, or after a terminal failure).\n for (const step of definition.steps) {\n if (!records.has(step.id)) skipStep(step);\n }\n\n // A FAILED record with a taken error edge is a handled failure; only\n // unhandled ones set runFailed above.\n const steps = definition.steps.map((step) => records.get(step.id)!);\n return runFailed\n ? { status: \"FAILED\", steps, error: runFailed }\n : { status: \"SUCCEEDED\", steps };\n}\n","// The pieces this reactor holds locally, by piece name.\n\n// A holder, not a finder: resolving a package is the host's package manager's\n// job, and this runtime must not depend on reactor-api to have it done.\nimport { childLogger } from \"document-model\";\nimport type { LocalPiece } from \"../pieces/index.js\";\n\nconst logger = childLogger([\"workflow\", \"piece-registry\"]);\n\nexport class PieceRegistry {\n private byName = new Map<string, LocalPiece>();\n\n // Replaces the whole set: what the host reports is everything it holds, so\n // a piece missing from it is a piece the reactor no longer has.\n setPieces(pieces: readonly LocalPiece[]): void {\n const found = new Map<string, LocalPiece>();\n for (const piece of pieces) {\n // The first to claim a name keeps it, so a project can override a piece\n // one of its dependencies ships.\n if (!found.has(piece.name)) found.set(piece.name, piece);\n }\n this.byName = found;\n const names = [...found.keys()].join(\", \");\n // Names go through the logger's values: it substitutes `@`-prefixed\n // tokens, and a scoped package name printed inline comes out as null/pack.\n if (found.size > 0) {\n logger.info(`Holding ${found.size} package piece(s): @names`, names);\n } else {\n logger.debug(\"Holding no package pieces\");\n }\n }\n\n lookup = (name: string): LocalPiece | undefined => this.byName.get(name);\n\n entries(): LocalPiece[] {\n return [...this.byName.values()];\n }\n\n // Name -> installed version, the registry parseBlockType resolves an\n // unversioned block type against.\n versions(): Record<string, string> {\n return Object.fromEntries(\n [...this.byName.values()].map((piece) => [piece.name, piece.version]),\n );\n }\n\n /** Test seam: a suite that filled the registry starts the next from nothing. */\n reset(): void {\n this.byName = new Map();\n }\n}\n\n// One registry for the runtime, the way the bundle cache is one directory.\nexport const packagePieces = new PieceRegistry();\n"],"mappings":";;;;;;;;;;;;AAYA,MAAMA,WAAS,YAAY,CAAC,YAAY,iBAAiB,CAAC;AAa1D,SAAS,OAAO,SAAsC;AACpD,QAAO;EACL;EACA,aAAa,gBACX,cACI,GAAG,QAAQ,6CACX,GAAG,QAAQ;EAGjB,WAAW,SAAS,GAAG,QAAQ,UAAU,mBAAmB,KAAK;EACjE,aAAa,MAAM,YACjB,GAAG,QAAQ,oBAAoB,KAAK,QAAQ,KAAK,IAAI,CAAC,GAAG,QAAQ;EACpE;;AAMH,IAAI;AAEJ,SAAgB,oBAAoB,KAA+B;CACjE,MAAM,UAAU,KAAK,MAAM,CAAC,QAAQ,QAAQ,GAAG,IAAI;AACnD,KAAI,YAAY,IAAI;AAClB,eAAa,KAAA;AACb;;AAEF,KAAI,YAAY,YAAY,QAAS;AACrC,cAAa,OAAO,QAAQ;AAC5B,UAAO,KAAK,8BAA8B,WAAW,UAAU;;AAGjE,SAAgB,sBAAuD;AACrE,QAAO;;;;AClDT,MAAMC,WAAS,UAAUC,OAAS;AAIlC,MAAM,iBAAiB;AACvB,MAAM,mBAAmB;AAEzB,SAAgB,cAAc,MAAc,SAAyB;AACnE,QAAO,GAAG,iBAAiB,KAAK,QAAQ,KAAK,IAAI,CAAC,GAAG,QAAQ;;AAG/D,SAAgB,cAAc,MAAc,SAAy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