@powerhousedao/reactor-workflow 6.2.3-dev.42 → 6.2.3-dev.44

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
- import { G as unsupportedTrigger, H as UnsupportedPieceFeatureError, S as maxFileBytes, U as authMethodFor, W as unsupportedAuth, a as redactMessage, c as DEFAULT_EGRESS_POLICY, d as parseAddress, m as extractDedupeKey, n as containsRedactedMarker, o as rememberSecrets, r as redact, s as secretsFor, u as isPrivateAddress, y as FileTooLargeError } from "./redact-DW7W5rrV.js";
2
- import { A as resolveStepInput, B as PieceWorker, C as describeBuiltinPiece, E as BoundConnectionResolver, F as parseSecretRef, G as sourcedResolver, H as PieceWorkerTimeoutError, I as secretRefFromId, J as npmRegistryBaseUrl, L as stepBlock, N as SecretDeletedError, O as declaredConnectionIds, P as SecretNotFoundError, R as triggerBlock, S as builtinPiece, T as CORE_PIECE_VERSION, U as bundleResolver, V as PieceWorkerError, W as pieceModuleRef, X as setPieceRegistryUrl, Y as pieceRegistrySource, _ as servesReactorPort, a as runWorkflow, b as unpinnedNote, c as stepConfigHash, d as ActivepiecesBlockExecutor, f as CompositeBlockExecutor, g as resolvedBlock, h as reactorHandlers, i as packagePieces, j as expressionsIn, k as shapeConnection, l as DynamicPropertiesError, m as isHostBound, n as installedPiece, o as canonicalJson, p as REACTOR_PORT_PIECE, r as installedPieces, s as hashOf, t as PieceRegistry, u as checkDynamicProperties, v as storeHandlers, w as CORE_PIECE_NAME, x as blockPorts, y as blockLabel, z as PieceWorkerPool } from "./piece-registry-DCy7g8sC.js";
1
+ import { G as unsupportedTrigger, H as UnsupportedPieceFeatureError, S as maxFileBytes, U as authMethodFor, W as unsupportedAuth, a as redactMessage, c as DEFAULT_EGRESS_POLICY, d as parseAddress, m as extractDedupeKey, n as containsRedactedMarker, o as rememberSecrets, r as redact, s as secretsFor, u as isPrivateAddress, y as FileTooLargeError } from "./redact-BlKAG3f0.js";
2
+ import { A as resolveStepInput, B as PieceWorker, C as describeBuiltinPiece, E as BoundConnectionResolver, F as parseSecretRef, G as sourcedResolver, H as PieceWorkerTimeoutError, I as secretRefFromId, J as npmRegistryBaseUrl, L as stepBlock, N as SecretDeletedError, O as declaredConnectionIds, P as SecretNotFoundError, R as triggerBlock, S as builtinPiece, T as CORE_PIECE_VERSION, U as bundleResolver, V as PieceWorkerError, W as pieceModuleRef, X as setPieceRegistryUrl, Y as pieceRegistrySource, _ as servesReactorPort, a as runWorkflow, b as unpinnedNote, c as stepConfigHash, d as ActivepiecesBlockExecutor, f as CompositeBlockExecutor, g as resolvedBlock, h as reactorHandlers, i as packagePieces, j as expressionsIn, k as shapeConnection, l as DynamicPropertiesError, m as isHostBound, n as installedPiece, o as canonicalJson, p as REACTOR_PORT_PIECE, r as installedPieces, s as hashOf, t as PieceRegistry, u as checkDynamicProperties, v as storeHandlers, w as CORE_PIECE_NAME, x as blockPorts, y as blockLabel, z as PieceWorkerPool } from "./piece-registry-DMhdxKrs.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";
@@ -2272,6 +2272,7 @@ function untestedError(label, sample) {
2272
2272
  case "stale": return `Test ${label} first: it changed since its last test`;
2273
2273
  case "hidden": return `Test ${label} first: its last test is not visible to you`;
2274
2274
  case "failed": return `Test ${label} first: its last test failed`;
2275
+ case "truncated": return `Test ${label} again: the journal kept only a truncated copy of its last output`;
2275
2276
  default: return `Test ${label} first`;
2276
2277
  }
2277
2278
  }
@@ -7096,6 +7097,36 @@ function assertPieceStoreEntry(key, value) {
7096
7097
  const size = Buffer.byteLength(encoded, "utf8");
7097
7098
  if (size > 524288) throw new PieceStoreLimitError(`Store value for "${key}" is ${size} bytes, over the ${PIECE_STORE_MAX_VALUE_BYTES} byte limit`);
7098
7099
  }
7100
+ const STEP_PAYLOAD_PREFIX_CHARS = 32768;
7101
+ function isTruncatedStepPayload(value) {
7102
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
7103
+ const record = value;
7104
+ return record.truncated === true && typeof record.bytes === "number" && typeof record.prefix === "string";
7105
+ }
7106
+ function topLevelDocumentIds(value) {
7107
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return {};
7108
+ const { documentId, driveId } = value;
7109
+ return {
7110
+ ...typeof documentId === "string" ? { documentId } : {},
7111
+ ...typeof driveId === "string" ? { driveId } : {}
7112
+ };
7113
+ }
7114
+ function cappedPayload(value) {
7115
+ const json = jsonOrNull(value);
7116
+ if (json === null) return null;
7117
+ const bytes = Buffer.byteLength(json, "utf8");
7118
+ if (bytes <= 262144) return json;
7119
+ let prefix = json.slice(0, STEP_PAYLOAD_PREFIX_CHARS);
7120
+ const last = prefix.charCodeAt(prefix.length - 1);
7121
+ if (last >= 55296 && last <= 56319) prefix = prefix.slice(0, -1);
7122
+ const marker = {
7123
+ truncated: true,
7124
+ bytes,
7125
+ prefix,
7126
+ ...topLevelDocumentIds(value)
7127
+ };
7128
+ return JSON.stringify(marker);
7129
+ }
7099
7130
  function stepValues(runId, ordinal, step) {
7100
7131
  return {
7101
7132
  run_id: runId,
@@ -7105,8 +7136,8 @@ function stepValues(runId, ordinal, step) {
7105
7136
  piece_name: step.pieceName,
7106
7137
  block_name: step.blockName,
7107
7138
  status: step.status,
7108
- input: jsonOrNull(redact(step.input)),
7109
- output: jsonOrNull(redact(step.output)),
7139
+ input: cappedPayload(redact(step.input)),
7140
+ output: cappedPayload(redact(step.output)),
7110
7141
  port: step.port ?? null,
7111
7142
  error: step.error ? redactMessage(step.error) : null,
7112
7143
  started_at: step.startedAt ?? null,
@@ -7260,7 +7291,7 @@ var WorkflowRunStore = class WorkflowRunStore {
7260
7291
  workflow_name: "",
7261
7292
  workflow_version: 0,
7262
7293
  trigger_kind: options.triggerKind,
7263
- trigger_payload: jsonOrNull(redact(options.triggerPayload)),
7294
+ trigger_payload: cappedPayload(redact(options.triggerPayload)),
7264
7295
  status: PENDING_RUN_STATUS,
7265
7296
  error: null,
7266
7297
  enqueued_at: now,
@@ -7289,7 +7320,7 @@ var WorkflowRunStore = class WorkflowRunStore {
7289
7320
  workflow_name: options.workflowName,
7290
7321
  workflow_version: options.workflowVersion,
7291
7322
  trigger_kind: options.triggerKind,
7292
- trigger_payload: jsonOrNull(redact(options.triggerPayload)),
7323
+ trigger_payload: cappedPayload(redact(options.triggerPayload)),
7293
7324
  status: "RUNNING",
7294
7325
  error: null,
7295
7326
  enqueued_at: now,
@@ -7885,6 +7916,7 @@ var TriggerSupervisor = class {
7885
7916
  const piece = await this.resolver().resolve(targetOf$1(binding));
7886
7917
  const auth = await this.options.resolveAuth(binding.connectionId, { piecePackage: binding.packageName });
7887
7918
  const redactValues = secretsFor(auth);
7919
+ const reactor = servesReactorPort(binding.packageName) ? this.options.reactor : void 0;
7888
7920
  return this.worker.runTriggerHook({
7889
7921
  ...pieceModuleRef(piece),
7890
7922
  triggerName: binding.triggerName,
@@ -7893,6 +7925,7 @@ var TriggerSupervisor = class {
7893
7925
  auth,
7894
7926
  ...redactValues.length > 0 ? { redactValues } : {},
7895
7927
  ...pieceStore ? { durableStore: true } : {},
7928
+ ...reactor ? { reactorAccess: true } : {},
7896
7929
  identity: {
7897
7930
  flowId: binding.workflowId,
7898
7931
  projectId: PROJECT_SCOPE_KEY
@@ -7903,7 +7936,10 @@ var TriggerSupervisor = class {
7903
7936
  ...this.egress ? { egress: this.egress } : {}
7904
7937
  }, {
7905
7938
  timeoutMs: this.hookTimeoutMs,
7906
- ...pieceStore ? { hostCalls: storeHandlers(pieceStore) } : {}
7939
+ ...pieceStore || reactor ? { hostCalls: {
7940
+ ...pieceStore ? storeHandlers(pieceStore) : {},
7941
+ ...reactor ? reactorHandlers(reactor) : {}
7942
+ } } : {}
7907
7943
  });
7908
7944
  }
7909
7945
  async deliveryFor(binding) {
@@ -9295,6 +9331,7 @@ var WorkflowRuntimeService = class {
9295
9331
  cacheDir: bundleCacheDir(),
9296
9332
  resolver: pieceResolver(),
9297
9333
  egress: configuredEgress(),
9334
+ reactor: new SubgraphReactorPort(this.host),
9298
9335
  defaultIntervalMs: Number(process.env.PH_WORKFLOWS_POLL_INTERVAL_MS) || void 0,
9299
9336
  reconcileIntervalMs: Number(process.env.PH_WORKFLOWS_WEBHOOK_RECONCILE_MS) || void 0
9300
9337
  });
@@ -10394,6 +10431,7 @@ var WorkflowRuntimeService = class {
10394
10431
  if (run.trigger_kind === "test") throw new Error(`Run "${runId}" tested a single step or trigger; test it again instead of rerunning it`);
10395
10432
  if (run.status !== "FAILED") throw new Error(`Only FAILED runs can be rerun; run is ${run.status}`);
10396
10433
  const triggerPayload = run.trigger_payload === null ? void 0 : JSON.parse(run.trigger_payload);
10434
+ if (isTruncatedStepPayload(triggerPayload)) throw new Error(`Trigger payload of run "${runId}" was truncated by the journal and cannot be replayed; fire the workflow again instead of rerunning it`);
10397
10435
  if (containsRedactedMarker(triggerPayload)) throw new Error(`Trigger payload of run "${runId}" was redacted and cannot be replayed; fire the workflow again instead of rerunning it`);
10398
10436
  const document = await this.host.reactorClient.get(run.workflow_id);
10399
10437
  const currentSteps = new Map(runnableDefinition(document.state.global).steps.map((step) => [step.id, stepDefinition(step)]));
@@ -10402,8 +10440,10 @@ var WorkflowRuntimeService = class {
10402
10440
  if (row.status !== "SUCCEEDED" && row.status !== "REPLAYED") continue;
10403
10441
  const current = currentSteps.get(row.step_id);
10404
10442
  if (!current || current.key !== row.step_key || row.config_hash === null || stepConfigHash(current) !== row.config_hash) continue;
10443
+ const output = row.output === null ? void 0 : JSON.parse(row.output);
10444
+ if (isTruncatedStepPayload(output)) continue;
10405
10445
  completedSteps.set(row.step_id, {
10406
- output: row.output === null ? void 0 : JSON.parse(row.output),
10446
+ output,
10407
10447
  port: row.port
10408
10448
  });
10409
10449
  }
@@ -10597,11 +10637,13 @@ var WorkflowRuntimeService = class {
10597
10637
  testedAt,
10598
10638
  error: row.error ?? ""
10599
10639
  };
10640
+ const output = row.output === null ? null : JSON.parse(row.output);
10641
+ if (isTruncatedStepPayload(output)) return { kind: "truncated" };
10600
10642
  return {
10601
10643
  kind: "succeeded",
10602
10644
  runId,
10603
10645
  testedAt,
10604
- output: row.output === null ? null : JSON.parse(row.output)
10646
+ output
10605
10647
  };
10606
10648
  }
10607
10649
  async stepOutputTree(workflowId, stepId, ctx) {