{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/errorCause.ts","../src/guard.ts","../src/dormancy.ts","../src/context.ts","../src/errorClassification.ts","../src/externalization/constants.ts","../src/limits.ts","../src/config.ts","../src/clients/memory.ts","../src/wire-version.ts","../src/clients/shared.ts","../src/clients/filesystem.ts","../src/clients/rest.ts","../src/externalization/decompress.ts","../src/externalization/bundle.ts","../src/externalization/resolver.ts","../src/runner.ts","../src/define.ts"],"sourcesContent":["/**\n * @zapier/zapier-durable\n *\n * Root barrel — re-exports everything for convenience. Targeted subpaths\n * are also available:\n *   @zapier/zapier-durable/runner  — server-only tick execution\n *   @zapier/zapier-durable/node    — Node config, filesystem adapter\n *   @zapier/zapier-durable/testing — MemoryClient\n */\n\n// ─── Definition ──────────────────────────────────────────────────────────────\n\nexport { defineDurable } from \"./define\";\nexport type {\n  DefineDurableOptions,\n  CallableDurable,\n  DurableCallOptions,\n  DurableDefinition,\n  DurableResult,\n} from \"./define\";\n\n// ─── Context ─────────────────────────────────────────────────────────────────\n\nexport { DurableContext, defaultClock } from \"./context\";\nexport type {\n  StepOptions,\n  WaitOptions,\n  CallbackOptions,\n  CallbackOptionsWithTimeout,\n  CallbackResult,\n  Clock,\n} from \"./context\";\n\n// ─── Wire versioning ───────────────────────────────────────────────────────\n\nexport { SDK_WIRE_VERSION_MAX, WIRE_VERSION_HEADER } from \"./wire-version\";\n\n// ─── Runner ──────────────────────────────────────────────────────────────────\n\nexport { runTick, executeTick } from \"./runner\";\nexport type { RunTickOptions, ExecuteTickOptions } from \"./runner\";\n\n// ─── Configuration ───────────────────────────────────────────────────────────\n\nexport {\n  getConfig,\n  configureDurable,\n  resetConfig,\n  createClient,\n} from \"./config\";\nexport type { DurableConfig, AdapterType } from \"./config\";\n\n// ─── Protocol types ──────────────────────────────────────────────────────────\n\nexport type {\n  DurableClient,\n  Execution,\n  Operation,\n  ExecutionStatus,\n  OperationType,\n  OperationStatus,\n  CheckpointOperationStatus,\n  CreateExecutionRequest,\n  CreateExecutionResponse,\n  CheckoutRequest,\n  CheckoutResponse,\n  CheckpointRequest,\n  CheckpointResponse,\n  ErrorMetadata,\n  HeldReason,\n  RunStateDirective,\n  ReleaseRequest,\n  ReleaseResponse,\n  CallbackRequest,\n  CallbackResponse,\n  PresignedBlock,\n  DeferredFieldsResponse,\n} from \"./types\";\n\n// ─── Errors ──────────────────────────────────────────────────────────────────\n\nexport {\n  DuplicateNameError,\n  NestedStepError,\n  SuspendInsideStepError,\n  StepExhaustedError,\n  LeaseConflictError,\n  RequestOutcomeUnknownError,\n  OperationTypeMismatchError,\n  ResultTooLargeError,\n  ResultNotFoundError,\n  ResultCorruptError,\n  ReservedOperationNameError,\n  TickReleasedError,\n  WireVersionMismatchError,\n  CallbackExpiredError,\n  CallbackConflictError,\n  ExecutionTerminalError,\n  IdempotencyConflictError,\n  isSdkError,\n} from \"./errors\";\n\n// ─── Determinism guard ───────────────────────────────────────────────────────\n\nexport {\n  DeterminismGuard,\n  DeterminismViolation,\n  guardedImportsPlugin,\n  generateShimSource,\n  generatePreloadSource,\n} from \"./guard\";\nexport type { GlobalGuardConfig, ModuleShimConfig } from \"./guard\";\n\n// ─── Dormancy ────────────────────────────────────────────────────────────────\n\nexport { DormancyTracker, TrackedPromise } from \"./dormancy\";\nexport type { TerminationResult } from \"./dormancy\";\n\n// ─── Clients ─────────────────────────────────────────────────────────────────\n\nexport { MemoryClient, FilesystemClient, RestClient } from \"./clients\";\nexport type { FilesystemClientOptions, RestClientOptions } from \"./clients\";\n\n// ─── Limits ──────────────────────────────────────────────────────────────────\n\nexport {\n  DURATION_LIMITS,\n  RETRY_LIMITS,\n  WAIT_LIMITS,\n  CALLBACK_LIMITS,\n  RETRY_DELAY_LIMITS,\n} from \"./limits\";\n","/**\n * Error classes for the Durable Execution SDK.\n */\n\nexport class DuplicateNameError extends Error {\n  constructor(name: string) {\n    super(\n      `Duplicate operation name: \"${name}\". Each step/wait/callback must have a unique name.`,\n    );\n    this.name = \"DuplicateNameError\";\n  }\n}\n\nexport class NestedStepError extends Error {\n  constructor(innerName: string, outerName: string | null) {\n    super(\n      `Cannot nest step \"${innerName}\" inside step \"${outerName}\". ` +\n        `Steps must be flat. Use separate steps and pass data between them.`,\n    );\n    this.name = \"NestedStepError\";\n  }\n}\n\nexport class SuspendInsideStepError extends Error {\n  constructor(\n    type: \"wait\" | \"callback\",\n    name: string,\n    stepName: string | null,\n  ) {\n    super(\n      `Cannot call ${type}(\"${name}\") inside step \"${stepName}\". ` +\n        `Waits and callbacks must be at the top level, not inside steps.`,\n    );\n    this.name = \"SuspendInsideStepError\";\n  }\n}\n\nexport class StepExhaustedError extends Error {\n  constructor(name: string, cause: unknown) {\n    super(`Step \"${name}\" exhausted all retry attempts.`, { cause });\n    this.name = \"StepExhaustedError\";\n  }\n}\n\nconst LEASE_CONFLICT_SYMBOL = Symbol.for(\n  \"@zapier/zapier-durable/LeaseConflictError\",\n);\n\nexport class LeaseConflictError extends Error {\n  static [Symbol.hasInstance](error: unknown): boolean {\n    if (this !== LeaseConflictError) {\n      return Function.prototype[Symbol.hasInstance].call(this, error);\n    }\n    return error instanceof Error && LEASE_CONFLICT_SYMBOL in error;\n  }\n\n  constructor(executionId: string) {\n    super(\n      `Lease conflict for execution \"${executionId}\". Ownership could not be established; any prior write outcome is unknown.`,\n    );\n    this.name = \"LeaseConflictError\";\n    Object.defineProperty(this, LEASE_CONFLICT_SYMBOL, { value: true });\n  }\n}\n\n/**\n * Thrown when a request to the durable server ran out of attempts on a\n * retriable failure (timeout, network error, 5xx, 408, 429). The server may\n * or may not have applied it: a response can be lost after the write\n * commits. The tick must stop without writing anything else, so a later tick\n * replays whatever the server actually saved.\n */\nconst REQUEST_OUTCOME_UNKNOWN_SYMBOL = Symbol.for(\n  \"@zapier/zapier-durable/RequestOutcomeUnknownError\",\n);\n\nexport class RequestOutcomeUnknownError extends Error {\n  // Like LeaseConflictError: each entry point bundles its own copy of this\n  // class, and the runner must recognize one thrown by the other copy.\n  static [Symbol.hasInstance](error: unknown): boolean {\n    if (this !== RequestOutcomeUnknownError) {\n      return Function.prototype[Symbol.hasInstance].call(this, error);\n    }\n    return error instanceof Error && REQUEST_OUTCOME_UNKNOWN_SYMBOL in error;\n  }\n\n  constructor(operation: string, attempts: number, lastError: string) {\n    super(\n      `${operation} outcome unknown after ${attempts} attempt(s); the server may or may not have applied it. Last error: ${lastError}`,\n    );\n    this.name = \"RequestOutcomeUnknownError\";\n    Object.defineProperty(this, REQUEST_OUTCOME_UNKNOWN_SYMBOL, {\n      value: true,\n    });\n  }\n}\n\n/**\n * Thrown when an operation name is reused with a different type (e.g., step vs wait).\n * This can only happen with non-deterministic control flow - which the DeterminismGuard\n * should catch first. If user somehow bypasses the guard (unguarded non-determinism source),\n * catching this error and continuing could lead to invalid state. In practice, the guard\n * catches common sources (Date.now, Math.random, etc.) before this error is reachable.\n */\nexport class OperationTypeMismatchError extends Error {\n  constructor(name: string, expected: string, actual: string) {\n    super(\n      `Operation \"${name}\" was previously recorded as type \"${actual}\" but is now called as \"${expected}\". ` +\n        `This indicates non-deterministic control flow.`,\n    );\n    this.name = \"OperationTypeMismatchError\";\n  }\n}\n\n/**\n * Result exceeded the documented size limit. Surfaced from a 413 on\n * checkpoint. Sizes/ratio/guidance mirror the structured 413 body so\n * callers can build accurate user-facing messages. Terminal — the SDK\n * does not retry.\n */\nexport class ResultTooLargeError extends Error {\n  readonly kind: \"uncompressed_exceeds_limit\" | \"compressed_exceeds_limit\";\n  readonly operationName: string;\n  readonly resultSizeBytes: number;\n  readonly resultSizeAfterCompressionBytes: number;\n  readonly maxSizeBytes: number;\n  readonly maxSizeAfterCompressionBytes: number;\n  readonly compressionRatio: number;\n  readonly guidance: string;\n  readonly docsUrl?: string;\n  readonly correlationId?: string;\n\n  constructor(args: {\n    message: string;\n    kind: \"uncompressed_exceeds_limit\" | \"compressed_exceeds_limit\";\n    operationName: string;\n    resultSizeBytes: number;\n    resultSizeAfterCompressionBytes: number;\n    maxSizeBytes: number;\n    maxSizeAfterCompressionBytes: number;\n    compressionRatio: number;\n    guidance: string;\n    docsUrl?: string;\n    correlationId?: string;\n  }) {\n    super(args.message);\n    this.name = \"ResultTooLargeError\";\n    this.kind = args.kind;\n    this.operationName = args.operationName;\n    this.resultSizeBytes = args.resultSizeBytes;\n    this.resultSizeAfterCompressionBytes = args.resultSizeAfterCompressionBytes;\n    this.maxSizeBytes = args.maxSizeBytes;\n    this.maxSizeAfterCompressionBytes = args.maxSizeAfterCompressionBytes;\n    this.compressionRatio = args.compressionRatio;\n    this.guidance = args.guidance;\n    this.docsUrl = args.docsUrl;\n    this.correlationId = args.correlationId;\n  }\n}\n\n/**\n * Externalized result's S3 object is missing — sentinel points to a key\n * that returned 404 (or a fetchDeferred fallback returned not-found).\n * Possible causes: lifecycle expiration with stale Postgres reference,\n * GDPR purge mid-replay, or a writer/reader binding inconsistency.\n * Terminal.\n */\nexport class ResultNotFoundError extends Error {\n  readonly executionId?: string;\n  readonly operationId?: string;\n  readonly correlationId?: string;\n\n  constructor(\n    message: string,\n    args: {\n      executionId?: string;\n      operationId?: string;\n      correlationId?: string;\n    } = {},\n  ) {\n    super(message);\n    this.name = \"ResultNotFoundError\";\n    this.executionId = args.executionId;\n    this.operationId = args.operationId;\n    this.correlationId = args.correlationId;\n  }\n}\n\n/**\n * Externalized result failed integrity verification. `kind` discriminates\n * the failure mode so callers can branch on it for diagnostics. Terminal —\n * the SDK does not retry, since retry would surface the same corruption.\n */\nexport class ResultCorruptError extends Error {\n  readonly kind:\n    | \"checksum_mismatch\"\n    | \"decompress_error\"\n    | \"zstd_version_mismatch\"\n    | \"envelope_sig_invalid\";\n  readonly executionId?: string;\n  readonly operationId?: string;\n  readonly correlationId?: string;\n\n  constructor(\n    message: string,\n    args: {\n      kind:\n        | \"checksum_mismatch\"\n        | \"decompress_error\"\n        | \"zstd_version_mismatch\"\n        | \"envelope_sig_invalid\";\n      executionId?: string;\n      operationId?: string;\n      correlationId?: string;\n    },\n  ) {\n    super(message);\n    this.name = \"ResultCorruptError\";\n    this.kind = args.kind;\n    this.executionId = args.executionId;\n    this.operationId = args.operationId;\n    this.correlationId = args.correlationId;\n  }\n}\n\n/**\n * Thrown when an operation name starts with a reserved prefix used by the\n * SDK for internal dormancy tracker bookkeeping. Without this guard, a\n * user-named operation could collide with a synthetic tracker id (e.g.\n * the checkpoint protectors registered in the step and wait paths) and\n * cause the synthetic worker's complete() to terminate the user's\n * operation prematurely.\n */\nexport class ReservedOperationNameError extends Error {\n  constructor(name: string, prefix: string) {\n    super(\n      `Operation name \"${name}\" uses the reserved prefix \"${prefix}\" -- ` +\n        `this prefix is used by the SDK for internal bookkeeping. ` +\n        `Pick a different name.`,\n    );\n    this.name = \"ReservedOperationNameError\";\n  }\n}\n\n/**\n * Thrown when user code starts a durable operation after its tick released\n * the lease. This happens when work outlives the run: for example, one\n * branch of a Promise.all rejects, the run ends, and another branch goes on\n * to its next step. The operation cannot be saved, so it must not run.\n */\nconst TICK_RELEASED_SYMBOL = Symbol.for(\n  \"@zapier/zapier-durable/TickReleasedError\",\n);\n\nexport class TickReleasedError extends Error {\n  // Like LeaseConflictError: user code imports the main entry point, and the\n  // runner that throws this is a separate bundled copy.\n  static [Symbol.hasInstance](error: unknown): boolean {\n    if (this !== TickReleasedError) {\n      return Function.prototype[Symbol.hasInstance].call(this, error);\n    }\n    return error instanceof Error && TICK_RELEASED_SYMBOL in error;\n  }\n\n  constructor(name: string) {\n    super(\n      `Operation \"${name}\" started after this tick released its lease; it was not run.`,\n    );\n    this.name = \"TickReleasedError\";\n    Object.defineProperty(this, TICK_RELEASED_SYMBOL, { value: true });\n  }\n}\n\n/**\n * Checkout refused with 426: the execution was stamped with a wire_version\n * higher than this package advertises it understands (the\n * x-zapier-durable-wire-version header). Terminal — upgrade the SDK; the\n * runtime does not retry.\n */\nexport class WireVersionMismatchError extends Error {\n  constructor(executionId: string) {\n    super(\n      `Execution \"${executionId}\" requires a newer SDK: its wire ` +\n        `version exceeds the maximum this SDK understands.`,\n    );\n    this.name = \"WireVersionMismatchError\";\n  }\n}\n\n/**\n * Checkout was refused because the execution is already terminal (server\n * responded 409 Conflict on a `completed` or `failed` execution). The common\n * cause is a duplicate event replayed against an inbox execution that already\n * finished: create matched the existing execution by (inbox, idempotencyKey),\n * but there is no tick left to run. Terminal — read the outcome with\n * `GET /api/v0/executions/{id}` rather than retrying.\n */\nexport class ExecutionTerminalError extends Error {\n  readonly executionId: string;\n\n  constructor(executionId: string) {\n    super(\n      `Execution \"${executionId}\" is already completed or failed and cannot ` +\n        `be checked out.`,\n    );\n    this.name = \"ExecutionTerminalError\";\n    this.executionId = executionId;\n  }\n}\n\n/**\n * Create was refused because the `idempotencyKey` is already in use within the\n * inbox for a structurally different request (server responded 409 Conflict).\n * An identical re-create returns the existing execution instead. Terminal —\n * retrying sends the same conflicting body; pick a distinct key.\n */\nexport class IdempotencyConflictError extends Error {\n  readonly inbox: string;\n  readonly idempotencyKey: string;\n\n  constructor(inbox: string, idempotencyKey: string) {\n    super(\n      `Idempotency key \"${idempotencyKey}\" in inbox \"${inbox}\" is already ` +\n        `used by an execution created from a different request.`,\n    );\n    this.name = \"IdempotencyConflictError\";\n    this.inbox = inbox;\n    this.idempotencyKey = idempotencyKey;\n  }\n}\n\n/**\n * Callback delivery was refused because the callback has expired and can no\n * longer be delivered (server responded 410 Gone): a gated callback past its\n * server deadline, or a legacy callback that crossed its advisory expiry while\n * the deciding update ran. Terminal — the payload was not recorded and the\n * deliverer remains the source of truth; the SDK does not retry.\n */\nexport class CallbackExpiredError extends Error {\n  readonly token: string;\n\n  constructor(token: string) {\n    super(`Callback \"${token}\" has expired and can no longer be delivered.`);\n    this.name = \"CallbackExpiredError\";\n    this.token = token;\n  }\n}\n\n/**\n * Callback delivery conflicted with a settled state (server responded 409\n * Conflict): the callback already completed with a structurally different\n * payload, or it is otherwise no longer deliverable (a rare delivery-race\n * re-read where the row moved on or vanished). An idempotent, structurally\n * identical re-delivery returns 200 instead. Terminal — the SDK does not retry.\n *\n * Note: the server sends `{ error: \"already_completed\" }` as the 409 body; this\n * error is keyed on the 409 status, not that string, so the mapping holds\n * across all three server cases (different-payload, non-pending, vanished).\n */\nexport class CallbackConflictError extends Error {\n  readonly token: string;\n\n  constructor(token: string) {\n    super(\n      `Callback \"${token}\" could not be delivered: it was already settled ` +\n        `(completed with a different payload, or no longer deliverable).`,\n    );\n    this.name = \"CallbackConflictError\";\n    this.token = token;\n  }\n}\n\n/**\n * A user-supplied value failed SDK-side validation before any checkpoint was\n * sent (e.g. an out-of-range or non-integer wait duration). Carries the\n * offending value. Terminal — a deterministic input error fails identically on\n * every replay, so the runtime does not retry.\n */\nexport class DurableValidationError extends Error {\n  readonly value: unknown;\n\n  constructor(value: unknown, message: string) {\n    super(message);\n    this.name = \"DurableValidationError\";\n    this.value = value;\n  }\n}\n\n/**\n * Check if an error is an SDK error that should NOT be retried.\n * Note: DeterminismViolation is checked separately in runner.ts.\n */\nexport function isSdkError(error: unknown): boolean {\n  return (\n    error instanceof DuplicateNameError ||\n    error instanceof NestedStepError ||\n    error instanceof SuspendInsideStepError ||\n    error instanceof StepExhaustedError ||\n    error instanceof LeaseConflictError ||\n    error instanceof RequestOutcomeUnknownError ||\n    error instanceof OperationTypeMismatchError ||\n    error instanceof ResultTooLargeError ||\n    error instanceof ResultNotFoundError ||\n    error instanceof ResultCorruptError ||\n    error instanceof ReservedOperationNameError ||\n    error instanceof TickReleasedError ||\n    error instanceof WireVersionMismatchError ||\n    error instanceof DurableValidationError ||\n    error instanceof CallbackExpiredError ||\n    error instanceof CallbackConflictError ||\n    error instanceof ExecutionTerminalError ||\n    error instanceof IdempotencyConflictError\n  );\n}\n","/**\n * Error cause capture for durable steps.\n *\n * A step that exhausts its retries throws a StepExhaustedError whose `cause`\n * is the underlying failure. That cause must serve two readers with opposite\n * needs:\n *\n *   - Observability: when the StepExhaustedError is left uncaught, the host\n *     (in-sandbox harness, CLI, test runner) must be able to report the\n *     underlying error in full — name, message, stack, own properties, and any\n *     nested cause.\n *   - Stable contract: when workflow code catches the error, it sees only the\n *     blessed fields. Both the live exhaustion and every replay rehydrate the\n *     cause from the same journaled bytes, so any field already reads the same\n *     across replays; bounding the visible set instead lets the rest of the\n *     captured cause's shape evolve later without changing how an\n *     already-journaled workflow behaves on replay.\n *\n * We reconcile the two by (1) journaling the full serialized error so both\n * ticks rehydrate an identical cause, and (2) wrapping the cause in a Proxy\n * that hides non-blessed fields while the determinism guard reports GUARDED\n * mode. Outside GUARDED mode — inside a step, or once the error has propagated\n * out of the workflow — the full cause is visible.\n */\nimport type { DeterminismGuard } from \"./guard\";\n\n/**\n * Fields a caught cause exposes to workflow code while the determinism guard\n * reports GUARDED mode. The journal rehydrates an identical cause on the live\n * exhaustion and every replay, so determinism doesn't constrain this set; it's\n * a forward-compatibility bound. Restricting catch logic to a small stable set\n * lets the rest of the captured cause's shape evolve without changing how an\n * already-journaled workflow behaves on replay. `statusCode` is blessed so\n * catch logic can branch on a failed SDK call's HTTP status.\n */\nexport const BLESSED_CAUSE_FIELDS: ReadonlySet<string> = new Set([\n  \"name\",\n  \"message\",\n  \"statusCode\",\n]);\n\n/** Cap the cause chain we walk so a self-referential chain can't loop forever. */\nconst MAX_CAUSE_DEPTH = 8;\n\ninterface SerializedError {\n  name?: unknown;\n  message?: unknown;\n  stack?: unknown;\n  cause?: unknown;\n  [key: string]: unknown;\n}\n\n/**\n * Convert a thrown value into a JSON-safe representation. Errors become a plain\n * object carrying name/message/stack, their own enumerable properties, and a\n * recursively serialized `cause`. Non-error values pass through unchanged (a\n * thrown string stays a string). Circular references collapse to \"[Circular]\".\n */\nexport function serializeError(\n  value: unknown,\n  seen: WeakSet<object> = new WeakSet(),\n  depth = 0,\n): unknown {\n  if (value === null) {\n    return null;\n  }\n  if (typeof value !== \"object\") {\n    // Coerce to a JSON-round-trip-stable value. The journal stores the\n    // JSON-encoded bytes while the live cause is rehydrated from this object,\n    // so anything JSON would change (BigInt, NaN/Infinity, functions, symbols)\n    // must be normalized here or the two would diverge across replays — and a\n    // BigInt would make the checkpoint's JSON encoding throw outright.\n    if (typeof value === \"string\" || typeof value === \"boolean\") {\n      return value;\n    }\n    if (typeof value === \"number\") {\n      if (!Number.isFinite(value)) {\n        return null;\n      }\n      // Normalize -0, which JSON encodes (and parses back) as 0.\n      return value === 0 ? 0 : value;\n    }\n    if (typeof value === \"bigint\") {\n      return value.toString();\n    }\n    // function, symbol, or undefined — JSON cannot represent these.\n    return null;\n  }\n  if (seen.has(value)) {\n    return \"[Circular]\";\n  }\n  seen.add(value);\n\n  if (value instanceof Error) {\n    // name/message are non-enumerable (the loop below won't see them) and are\n    // typed as strings but can be mutated to anything at runtime, so coerce\n    // them through serializeError like every other field to keep the output\n    // JSON-safe.\n    const out: SerializedError = {\n      name: serializeError(value.name, seen, depth + 1),\n      message: serializeError(value.message, seen, depth + 1),\n    };\n    if (typeof value.stack === \"string\") {\n      out.stack = value.stack;\n    }\n    for (const key of Object.keys(value)) {\n      if (\n        key === \"name\" ||\n        key === \"message\" ||\n        key === \"stack\" ||\n        key === \"cause\"\n      ) {\n        continue;\n      }\n      out[key] = serializeError(\n        (value as unknown as Record<string, unknown>)[key],\n        seen,\n        depth + 1,\n      );\n    }\n    const cause = (value as { cause?: unknown }).cause;\n    if (cause !== undefined && depth < MAX_CAUSE_DEPTH) {\n      out.cause = serializeError(cause, seen, depth + 1);\n    }\n    return out;\n  }\n\n  if (Array.isArray(value)) {\n    // Array.from (not map) materializes sparse holes as undefined, which then\n    // serialize to null — matching how JSON encodes holes — so the output\n    // stays round-trip-stable.\n    return Array.from(value, (item) => serializeError(item, seen, depth + 1));\n  }\n\n  const out: Record<string, unknown> = {};\n  for (const key of Object.keys(value)) {\n    out[key] = serializeError(\n      (value as Record<string, unknown>)[key],\n      seen,\n      depth + 1,\n    );\n  }\n  return out;\n}\n\n/**\n * Rebuild a thrown value from its serialized form. An object carrying a string\n * `name` or `message` becomes a real Error (so `cause instanceof Error` holds\n * consistently) with its stack, own properties, and nested cause restored;\n * anything else passes through. The function is pure, so applying it to the\n * journaled bytes on a replay tick yields a cause identical to the live tick's.\n */\nexport function deserializeError(value: unknown, depth = 0): unknown {\n  if (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n    return value;\n  }\n  const obj = value as Record<string, unknown>;\n  const looksLikeError =\n    typeof obj.name === \"string\" || typeof obj.message === \"string\";\n  if (!looksLikeError) {\n    return value;\n  }\n\n  const err = new Error(typeof obj.message === \"string\" ? obj.message : \"\");\n  if (typeof obj.name === \"string\") {\n    err.name = obj.name;\n  }\n  if (typeof obj.stack === \"string\") {\n    err.stack = obj.stack;\n  }\n  for (const key of Object.keys(obj)) {\n    if (\n      key === \"name\" ||\n      key === \"message\" ||\n      key === \"stack\" ||\n      key === \"cause\"\n    ) {\n      continue;\n    }\n    (err as unknown as Record<string, unknown>)[key] = obj[key];\n  }\n  if (obj.cause !== undefined && depth < MAX_CAUSE_DEPTH) {\n    (err as { cause?: unknown }).cause = deserializeError(obj.cause, depth + 1);\n  }\n  return err;\n}\n\n/**\n * Wrap a cause so that, while the determinism guard reports GUARDED mode, only\n * the blessed fields are readable; non-blessed data fields read as `undefined`\n * and don't enumerate. Methods and symbol-keyed members always pass through so\n * the value still logs and stringifies. Outside GUARDED mode the wrapper is\n * transparent, exposing the full cause to step code and to the host that\n * reports an uncaught error.\n *\n * A non-blessed field has a deterministic safe value here (`undefined`), so we\n * redact rather than throw — unlike the global guards, which throw because no\n * deterministic value exists for Date.now()/random/etc.\n */\nexport function guardErrorCause(\n  cause: unknown,\n  guard: DeterminismGuard,\n): unknown {\n  if (cause === null || typeof cause !== \"object\") {\n    return cause;\n  }\n\n  const isHidden = (prop: string | symbol): boolean => {\n    if (typeof prop === \"symbol\") {\n      return false;\n    }\n    if (BLESSED_CAUSE_FIELDS.has(prop)) {\n      return false;\n    }\n    return guard.mode === \"GUARDED\";\n  };\n\n  return new Proxy(cause as object, {\n    get(target, prop) {\n      // Read against the target, not the proxy: Error's lazy `stack` accessor\n      // returns undefined when invoked with a proxy as its receiver.\n      const value = Reflect.get(target, prop);\n      // Methods (e.g. toString) stay callable so the value still stringifies.\n      if (typeof value === \"function\") {\n        return value;\n      }\n      if (isHidden(prop)) {\n        // A non-configurable, non-writable own data property can't legally\n        // report a different value from a get trap; surface the real value.\n        const desc = Reflect.getOwnPropertyDescriptor(target, prop);\n        if (desc && desc.configurable === false && desc.writable === false) {\n          return value;\n        }\n        return undefined;\n      }\n      return value;\n    },\n    has(target, prop) {\n      if (isHidden(prop)) {\n        // A non-configurable own property can't be hidden from `in` either\n        // (e.g. an array cause's `length`), so report it to avoid a TypeError.\n        const desc = Reflect.getOwnPropertyDescriptor(target, prop);\n        if (desc && desc.configurable === false) {\n          return true;\n        }\n        return false;\n      }\n      return Reflect.has(target, prop);\n    },\n    ownKeys(target) {\n      const keys = Reflect.ownKeys(target);\n      if (guard.mode !== \"GUARDED\") {\n        return keys;\n      }\n      // A non-configurable own key must be reported, so keep it regardless.\n      return keys.filter((key) => {\n        const desc = Reflect.getOwnPropertyDescriptor(target, key);\n        if (desc && desc.configurable === false) {\n          return true;\n        }\n        return !isHidden(key);\n      });\n    },\n    getOwnPropertyDescriptor(target, prop) {\n      const desc = Reflect.getOwnPropertyDescriptor(target, prop);\n      if (desc && desc.configurable === false) {\n        return desc;\n      }\n      if (isHidden(prop)) {\n        return undefined;\n      }\n      return desc;\n    },\n  });\n}\n","/**\n * Determinism Guard\n *\n * Provides runtime protection against non-deterministic API usage\n * outside of steps. Uses AsyncLocalStorage for mode tracking.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\n\n// ============================================================================\n//  CONFIGURATION SCHEMA\n// ============================================================================\n\n/**\n * Kind of global to patch - affects how patching works.\n */\ntype GlobalKind = \"function\" | \"constructor\" | \"method\" | \"getter\";\n\n/**\n * Configuration for a global property to guard.\n */\nexport interface GlobalGuardConfig {\n  /** Path to the global (e.g., \"Math.random\", \"Date.now\", \"fetch\") */\n  path: string;\n  /** Kind of global - affects patching strategy */\n  kind?: GlobalKind;\n  /** Custom guard function (optional, defaults to standard assert) */\n  guard?: (guard: DeterminismGuard) => (...args: unknown[]) => unknown;\n}\n\n/**\n * Configuration for a module to shim.\n */\nexport interface ModuleShimConfig {\n  /** Primary module specifier (e.g., \"node:crypto\") */\n  module: string;\n  /** Additional specifiers to match (e.g., [\"crypto\"] for bare import) */\n  match?: string[];\n  /** Functions to guard (calls assert before invoking) */\n  guarded: string[];\n  /** Functions to pass through unchanged (or \"*\" for all others) */\n  passthrough: string[] | \"*\";\n}\n\n/**\n * Full configuration for the determinism guard system.\n */\nexport interface DeterminismGuardConfig {\n  globals: GlobalGuardConfig[];\n  modules: ModuleShimConfig[];\n}\n\n// ============================================================================\n//  DEFAULT CONFIGURATIONS\n// ============================================================================\n\nexport const NODE_GLOBALS: GlobalGuardConfig[] = [\n  // Random\n  { path: \"Math.random\", kind: \"method\" },\n\n  // Time - Date proxy handles Date(), new Date(), AND Date.now()\n  { path: \"Date\", kind: \"constructor\" },\n  // NOTE: Date.now is NOT listed separately - it's handled by the Date proxy\n\n  // Network\n  { path: \"fetch\", kind: \"function\" },\n\n  // Timers\n  { path: \"setTimeout\", kind: \"function\" },\n  { path: \"setInterval\", kind: \"function\" },\n  { path: \"setImmediate\", kind: \"function\" },\n\n  // High-resolution time\n  { path: \"performance.now\", kind: \"method\" },\n  { path: \"performance.timeOrigin\", kind: \"getter\" },\n\n  // Process (node-specific, guarded at global level)\n  { path: \"process.hrtime\", kind: \"method\" },\n  { path: \"process.hrtime.bigint\", kind: \"method\" },\n  { path: \"process.uptime\", kind: \"method\" },\n  { path: \"process.pid\", kind: \"getter\" },\n];\n\nexport const NODE_MODULES: ModuleShimConfig[] = [\n  // Crypto - random functions\n  {\n    module: \"node:crypto\",\n    match: [\"crypto\"],\n    guarded: [\n      \"randomUUID\",\n      \"randomBytes\",\n      \"randomInt\",\n      \"randomFill\",\n      \"randomFillSync\",\n      \"getRandomValues\",\n    ],\n    passthrough: \"*\",\n  },\n\n  // HTTP/HTTPS - network requests\n  {\n    module: \"node:http\",\n    match: [\"http\"],\n    guarded: [\"request\", \"get\", \"createServer\"],\n    passthrough: \"*\",\n  },\n  {\n    module: \"node:https\",\n    match: [\"https\"],\n    guarded: [\"request\", \"get\", \"createServer\"],\n    passthrough: \"*\",\n  },\n\n  // Timers\n  {\n    module: \"node:timers\",\n    match: [\"timers\"],\n    guarded: [\"setTimeout\", \"setInterval\", \"setImmediate\"],\n    passthrough: \"*\",\n  },\n\n  // File system - external state\n  {\n    module: \"node:fs\",\n    match: [\"fs\"],\n    guarded: [\n      \"readFile\",\n      \"readFileSync\",\n      \"writeFile\",\n      \"writeFileSync\",\n      \"readdir\",\n      \"readdirSync\",\n      \"stat\",\n      \"statSync\",\n      \"access\",\n      \"accessSync\",\n    ],\n    passthrough: \"*\",\n  },\n  {\n    module: \"node:fs/promises\",\n    match: [\"fs/promises\"],\n    guarded: [\"readFile\", \"writeFile\", \"readdir\", \"stat\", \"access\"],\n    passthrough: \"*\",\n  },\n\n  // DNS - network lookups\n  {\n    module: \"node:dns\",\n    match: [\"dns\"],\n    guarded: [\"lookup\", \"resolve\", \"resolve4\", \"resolve6\"],\n    passthrough: \"*\",\n  },\n\n  // Child process - external execution\n  {\n    module: \"node:child_process\",\n    match: [\"child_process\"],\n    guarded: [\"exec\", \"execSync\", \"spawn\", \"spawnSync\", \"fork\", \"execFile\"],\n    passthrough: \"*\",\n  },\n\n  // Net - raw sockets\n  {\n    module: \"node:net\",\n    match: [\"net\"],\n    guarded: [\"connect\", \"createConnection\", \"createServer\"],\n    passthrough: \"*\",\n  },\n\n  // Performance hooks\n  {\n    module: \"node:perf_hooks\",\n    match: [\"perf_hooks\"],\n    guarded: [\"performance\"],\n    passthrough: \"*\",\n  },\n];\n\nexport const BROWSER_GLOBALS: GlobalGuardConfig[] = [\n  { path: \"Math.random\", kind: \"method\" },\n  { path: \"Date\", kind: \"constructor\" },\n  { path: \"Date.now\", kind: \"method\" },\n  { path: \"fetch\", kind: \"function\" },\n  { path: \"setTimeout\", kind: \"function\" },\n  { path: \"setInterval\", kind: \"function\" },\n  { path: \"crypto.getRandomValues\", kind: \"method\" },\n  { path: \"crypto.randomUUID\", kind: \"method\" },\n];\n\nexport const CLOUDFLARE_GLOBALS: GlobalGuardConfig[] = [\n  { path: \"Math.random\", kind: \"method\" },\n  { path: \"Date\", kind: \"constructor\" },\n  { path: \"Date.now\", kind: \"method\" },\n  { path: \"fetch\", kind: \"function\" },\n  { path: \"setTimeout\", kind: \"function\" },\n  { path: \"crypto.getRandomValues\", kind: \"method\" },\n];\n\n// ============================================================================\n//  CORE GUARD\n// ============================================================================\n\n/** Symbol key for marking functions as already patched */\nconst PATCHED_SYMBOL = Symbol.for(\"@zapier/determinism-guard/patched\");\n\n/** Symbol key for storing the true original Date constructor */\nconst ORIGINAL_DATE_SYMBOL = Symbol.for(\n  \"@zapier/determinism-guard/original-date\",\n);\n\ntype Mode = \"GUARDED\" | \"ALLOWED\";\n\ninterface Store {\n  readonly stack: readonly Mode[];\n}\n\nexport class DeterminismViolation extends Error {\n  constructor(api: string) {\n    super(\n      `Non-deterministic API \"${api}\" called in GUARDED mode. Move this call into a step.`,\n    );\n    this.name = \"DeterminismViolation\";\n  }\n}\n\n/** Global symbol key for guard singleton - avoids duplicate package issues */\nconst GUARD_SYMBOL_KEY = \"@zapier/determinism-guard\";\n\nexport class DeterminismGuard {\n  private als = new AsyncLocalStorage<Store>();\n  private logging = false;\n  private violationCallback?: (error: DeterminismViolation) => void;\n\n  // Singleton via global symbol - survives duplicate package instances\n  private static _instance: DeterminismGuard;\n  static get instance(): DeterminismGuard {\n    // Check global symbol first (set by initGlobal or preload)\n    const global = (globalThis as any)[Symbol.for(GUARD_SYMBOL_KEY)];\n    if (global?.instance) {\n      return global.instance;\n    }\n    // Fallback to module-level singleton\n    if (!DeterminismGuard._instance) {\n      DeterminismGuard._instance = new DeterminismGuard();\n    }\n    return DeterminismGuard._instance;\n  }\n\n  /**\n   * Initialize global symbol for shims to find us.\n   * Call this once at startup (SDK does this automatically).\n   * This ensures shims work even with duplicate package copies.\n   */\n  initGlobal(): void {\n    const sym = Symbol.for(GUARD_SYMBOL_KEY);\n    (globalThis as any)[sym] = {\n      instance: this,\n      mode: null as Mode | null,\n      assert: this.assert.bind(this),\n    };\n    // Keep mode getter updated\n    Object.defineProperty((globalThis as any)[sym], \"mode\", {\n      get: () => this.mode,\n    });\n  }\n\n  // Default configs (exported as static data for ESLint plugins to consume)\n  static readonly NODE_GLOBALS = NODE_GLOBALS;\n  static readonly NODE_MODULES = NODE_MODULES;\n  static readonly BROWSER_GLOBALS = BROWSER_GLOBALS;\n  static readonly CLOUDFLARE_GLOBALS = CLOUDFLARE_GLOBALS;\n\n  setLogging(enabled: boolean): void {\n    this.logging = enabled;\n  }\n\n  /**\n   * Set a callback to be invoked when a violation is detected.\n   * Called BEFORE the error is thrown, allowing the SDK to signal\n   * a race condition even if user code catches the error.\n   */\n  setViolationCallback(\n    cb: ((error: DeterminismViolation) => void) | undefined,\n  ): void {\n    this.violationCallback = cb;\n  }\n\n  get mode(): Mode | null {\n    const store = this.als.getStore();\n    if (!store || store.stack.length === 0) return null;\n    return store.stack[store.stack.length - 1];\n  }\n\n  runGuarded<T>(fn: () => T): T {\n    return this.runWithMode(\"GUARDED\", fn);\n  }\n\n  runAllowed<T>(fn: () => T): T {\n    return this.runWithMode(\"ALLOWED\", fn);\n  }\n\n  private runWithMode<T>(mode: Mode, fn: () => T): T {\n    const parent = this.als.getStore();\n    const stack = parent ? [...parent.stack, mode] : [mode];\n    this.log(`-> ${mode} (depth ${stack.length})`);\n    try {\n      return this.als.run({ stack }, fn);\n    } finally {\n      this.log(`<- ${mode} (depth ${stack.length})`);\n    }\n  }\n\n  assert(api: string): void {\n    if (this.mode === \"GUARDED\") {\n      this.log(`BLOCKED: ${api}`);\n      const error = new DeterminismViolation(api);\n      this.violationCallback?.(error); // Signal before throwing\n      throw error;\n    }\n    this.log(`allowed: ${api}`);\n  }\n\n  wrap<T extends (...args: unknown[]) => unknown>(api: string, fn: T): T {\n    const self = this;\n    return function (this: unknown, ...args: unknown[]) {\n      self.assert(api);\n      return fn.apply(this, args);\n    } as T;\n  }\n\n  // -------------------------------------------------------------------------\n  // EXTENSIBLE GLOBAL PATCHING\n  // -------------------------------------------------------------------------\n\n  installGlobalGuards(configs: GlobalGuardConfig[] = NODE_GLOBALS): void {\n    // Idempotent: each global is tagged with PATCHED_SYMBOL to prevent double-wrapping.\n    for (const config of configs) {\n      this.patchGlobal(config);\n    }\n    this.log(`Processed ${configs.length} global guard configs`);\n  }\n\n  private patchGlobal(config: GlobalGuardConfig): void {\n    const { path: apiPath, guard: customGuard } = config;\n    const parts = apiPath.split(\".\");\n\n    // Special case for Date constructor\n    if (apiPath === \"Date\") {\n      this.patchDateConstructor();\n      return;\n    }\n\n    // Safety: Date.now is handled by the Date proxy - patching it separately causes recursion\n    if (apiPath === \"Date.now\") {\n      this.log(`Skipping Date.now (handled by Date proxy)`);\n      return;\n    }\n\n    if (parts.length === 1) {\n      const name = parts[0];\n      const current = (globalThis as Record<string, unknown>)[name];\n      if (typeof current === \"function\") {\n        // Skip if already patched (idempotent)\n        if ((current as any)[PATCHED_SYMBOL] === apiPath) {\n          this.log(`Skipping ${apiPath} (already patched)`);\n          return;\n        }\n\n        let wrapped: (...args: unknown[]) => unknown;\n        if (customGuard) {\n          wrapped = customGuard(this) as (...args: unknown[]) => unknown;\n        } else {\n          wrapped = this.wrap(\n            apiPath,\n            current as (...args: unknown[]) => unknown,\n          );\n        }\n        (wrapped as any)[PATCHED_SYMBOL] = apiPath;\n        (globalThis as Record<string, unknown>)[name] = wrapped;\n      }\n    } else if (parts.length === 2) {\n      const [obj, prop] = parts;\n      const target = (\n        globalThis as unknown as Record<string, Record<string, unknown>>\n      )[obj];\n      if (target && typeof target[prop] === \"function\") {\n        const current = target[prop] as (...args: unknown[]) => unknown;\n        // Skip if already patched (idempotent)\n        if ((current as any)[PATCHED_SYMBOL] === apiPath) {\n          this.log(`Skipping ${apiPath} (already patched)`);\n          return;\n        }\n\n        const wrapped = this.wrap(apiPath, current.bind(target));\n        (wrapped as any)[PATCHED_SYMBOL] = apiPath;\n        target[prop] = wrapped;\n      }\n    }\n  }\n\n  private patchDateConstructor(): void {\n    const self = this;\n\n    // Check if already patched (idempotent)\n    const existing = (globalThis as any).Date;\n    if (existing && (existing as any)[PATCHED_SYMBOL] === \"Date\") {\n      this.log(`Skipping Date (already patched)`);\n      return;\n    }\n\n    // Always wrap the TRUE original Date, not the current (possibly proxied) Date.\n    // This prevents recursive calls when Date.now() is invoked.\n    const OriginalDate: typeof Date =\n      (globalThis as any)[ORIGINAL_DATE_SYMBOL] ?? Date;\n\n    // Store the original Date once (survives multiple package copies via Symbol.for)\n    if (!(globalThis as any)[ORIGINAL_DATE_SYMBOL]) {\n      (globalThis as any)[ORIGINAL_DATE_SYMBOL] = OriginalDate;\n    }\n\n    const GuardedDate = new Proxy(OriginalDate, {\n      apply(_target, _thisArg, argArray) {\n        self.assert(\"Date()\");\n        return (OriginalDate as unknown as (...args: unknown[]) => unknown)(\n          ...argArray,\n        );\n      },\n      construct(_target, argArray, newTarget) {\n        self.assert(\"new Date()\");\n        return Reflect.construct(OriginalDate, argArray, newTarget);\n      },\n      get(target, prop, receiver) {\n        if (prop === \"now\") {\n          // CRITICAL: Call OriginalDate.now, NOT target.now (which could be patched)\n          const fn = () => {\n            self.assert(\"Date.now()\");\n            return OriginalDate.now();\n          };\n          (fn as any)[PATCHED_SYMBOL] = \"Date.now()\";\n          return fn;\n        }\n        return Reflect.get(target, prop, receiver);\n      },\n    });\n\n    (GuardedDate as any)[PATCHED_SYMBOL] = \"Date\";\n    (globalThis as { Date: typeof Date }).Date = GuardedDate as typeof Date;\n  }\n\n  private log(msg: string): void {\n    if (this.logging) {\n      console.log(`  [guard] ${msg}`);\n    }\n  }\n}\n\n// ============================================================================\n//  SHIM GENERATOR\n// ============================================================================\n\n/**\n * Generate ESM shim source code.\n * Uses global symbol for guard lookup to avoid duplicate singleton issues\n * when bundlers create multiple copies of the package.\n */\nexport function generateShimSource(config: ModuleShimConfig): string {\n  const { module: moduleName, guarded } = config;\n  const requireName = moduleName.replace(/^node:/, \"\");\n  const apiPrefix = requireName;\n\n  // Get all exports from the real module\n  let realExports: string[] = [];\n  try {\n    const req = createRequire(import.meta.url);\n    realExports = Object.keys(req(requireName)).filter(\n      (k) =>\n        !guarded.includes(k) && !k.startsWith(\"_\") && /^[a-zA-Z_$]/.test(k),\n    );\n  } catch {\n    realExports = [];\n  }\n\n  return `// Generated shim for ${moduleName}\n// Uses global symbol to avoid duplicate singleton issues\nimport { createRequire } from \"node:module\";\n\nconst require = createRequire(import.meta.url);\nconst real = require(\"${requireName}\");\n\n// Guard lookup via global symbol - set by DeterminismGuard.initGlobal()\nconst GUARD_SYMBOL = Symbol.for(\"@zapier/determinism-guard\");\n\nfunction getGuard() {\n  return globalThis[GUARD_SYMBOL];\n}\n\nfunction assert(api) {\n  const guard = getGuard();\n  if (guard && guard.mode === \"GUARDED\") {\n    throw new Error(\\`Non-deterministic API \"\\${api}\" called in GUARDED mode. Move this call into a step.\\`);\n  }\n}\n\n// Guarded exports\n${guarded\n  .map(\n    (fn) => `\nexport function ${fn}(...args) {\n  assert(\"${apiPrefix}.${fn}\");\n  return real.${fn}.apply(real, args);\n}`,\n  )\n  .join(\"\\n\")}\n\n// Default export with guarded functions\nexport default {\n  ...real,\n${guarded.map((fn) => `  ${fn},`).join(\"\\n\")}\n};\n\n// Re-export non-guarded items (deterministic functions pass through)\n${realExports.map((k) => `export const ${k} = real.${k};`).join(\"\\n\")}\n`;\n}\n\n// ============================================================================\n//  ESBUILD PLUGIN\n// ============================================================================\n\ninterface EsbuildPluginOptions {\n  modules?: ModuleShimConfig[];\n  shimDir?: string;\n  inline?: boolean;\n  /** Log every shimmed module to stdout. Default false. */\n  verbose?: boolean;\n}\n\nexport function guardedImportsPlugin(options: EsbuildPluginOptions = {}) {\n  const {\n    modules = NODE_MODULES,\n    shimDir = \"./node_modules/.determinism-guard-shims\",\n    inline = true,\n    verbose = false,\n  } = options;\n\n  // Build lookup map from all specifiers\n  const moduleMap = new Map<string, ModuleShimConfig>();\n  for (const config of modules) {\n    moduleMap.set(config.module, config);\n    if (config.match) {\n      for (const alias of config.match) {\n        moduleMap.set(alias, config);\n      }\n    }\n    if (config.module.startsWith(\"node:\")) {\n      const bare = config.module.slice(5);\n      if (!moduleMap.has(bare)) {\n        moduleMap.set(bare, config);\n      }\n    }\n  }\n\n  // Build regex from config (not hardcoded)\n  const specifiers = Array.from(moduleMap.keys()).map((s) =>\n    s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"),\n  );\n  const filterRegex = new RegExp(`^(${specifiers.join(\"|\")})$`);\n\n  return {\n    name: \"determinism-guard\",\n    setup(build: any) {\n      build.onResolve({ filter: filterRegex }, (args: any) => {\n        const config = moduleMap.get(args.path);\n        if (config) {\n          if (verbose) {\n            console.log(`[determinism-guard] Shimming: ${args.path}`);\n          }\n          return {\n            path: args.path,\n            namespace: \"determinism-guard-shim\",\n          };\n        }\n        return null;\n      });\n\n      build.onLoad(\n        { filter: /.*/, namespace: \"determinism-guard-shim\" },\n        (args: any) => {\n          const config = moduleMap.get(args.path);\n          if (!config) {\n            return { contents: `export * from \"${args.path}\";` };\n          }\n\n          if (inline) {\n            return {\n              contents: generateShimSource(config),\n              loader: \"js\",\n            };\n          } else {\n            const shimPath = path.join(\n              shimDir,\n              `${config.module.replace(\"node:\", \"\")}.mjs`,\n            );\n            return {\n              contents: `export * from \"${shimPath}\";`,\n              loader: \"js\",\n              resolveDir: process.cwd(),\n            };\n          }\n        },\n      );\n    },\n  };\n}\n\n// ============================================================================\n//  CJS PRELOAD GENERATOR\n// ============================================================================\n\nexport function generatePreloadSource(\n  config: {\n    globals?: GlobalGuardConfig[];\n    modules?: ModuleShimConfig[];\n  } = {},\n): string {\n  const { globals = NODE_GLOBALS, modules = NODE_MODULES } = config;\n\n  return `// Generated determinism guard preload\n// Use: NODE_OPTIONS=\"--require ./preload.cjs\" node app.mjs\n\nconst { AsyncLocalStorage } = require(\"node:async_hooks\");\n\nconst als = new AsyncLocalStorage();\n\nfunction getMode() {\n  const store = als.getStore();\n  return store?.stack?.[store.stack.length - 1] ?? null;\n}\n\nfunction assert(api) {\n  if (getMode() === \"GUARDED\") {\n    throw new Error(\\`Non-deterministic API \"\\${api}\" called in GUARDED mode. Move this call into a step.\\`);\n  }\n}\n\n// Exports for SDK to control mode\nmodule.exports.runGuarded = function(fn) {\n  const parent = als.getStore();\n  const stack = parent ? [...parent.stack, \"GUARDED\"] : [\"GUARDED\"];\n  return als.run({ stack }, fn);\n};\n\nmodule.exports.runAllowed = function(fn) {\n  const parent = als.getStore();\n  const stack = parent ? [...parent.stack, \"ALLOWED\"] : [\"ALLOWED\"];\n  return als.run({ stack }, fn);\n};\n\nmodule.exports.getMode = getMode;\n\n// ---- GLOBAL PATCHES ----\n${globals\n  .map((g) => {\n    const parts = g.path.split(\".\");\n    if (g.path === \"Date\") {\n      return `\nconst OriginalDate = Date;\nglobal.Date = new Proxy(OriginalDate, {\n  apply(target, thisArg, args) {\n    assert(\"Date()\");\n    return target(...args);\n  },\n  construct(target, args, newTarget) {\n    assert(\"new Date()\");\n    return Reflect.construct(target, args, newTarget);\n  },\n  get(target, prop, receiver) {\n    if (prop === \"now\") {\n      return () => { assert(\"Date.now()\"); return target.now(); };\n    }\n    return Reflect.get(target, prop, receiver);\n  },\n});`;\n    } else if (parts.length === 1) {\n      return `\nif (typeof global.${g.path} === \"function\") {\n  const original_${parts[0]} = global.${g.path};\n  global.${g.path} = function(...args) {\n    assert(\"${g.path}\");\n    return original_${parts[0]}.apply(this, args);\n  };\n}`;\n    } else if (parts.length === 2) {\n      return `\nif (global.${parts[0]} && typeof global.${parts[0]}.${parts[1]} === \"function\") {\n  const original_${parts.join(\"_\")} = global.${parts[0]}.${parts[1]}.bind(global.${parts[0]});\n  global.${parts[0]}.${parts[1]} = function(...args) {\n    assert(\"${g.path}\");\n    return original_${parts.join(\"_\")}(...args);\n  };\n}`;\n    }\n    return \"\";\n  })\n  .join(\"\\n\")}\n\n// ---- MODULE PATCHES ----\n${modules\n  .map((m) => {\n    const requireName = m.module.replace(/^node:/, \"\");\n    const varName = requireName.replace(/[^a-z]/gi, \"_\");\n    return `\ntry {\n  const ${varName} = require(\"${requireName}\");\n  ${m.guarded\n    .map(\n      (fn) => `\n  if (typeof ${varName}.${fn} === \"function\") {\n    const original_${varName}_${fn} = ${varName}.${fn};\n    ${varName}.${fn} = function(...args) {\n      assert(\"${requireName}.${fn}\");\n      return original_${varName}_${fn}.apply(this, args);\n    };\n  }`,\n    )\n    .join(\"\")}\n} catch (e) {}`;\n  })\n  .join(\"\\n\")}\n`;\n}\n","/**\n * Dormancy Detection Library\n *\n * Tracks runtime phases and detects when it's safe to suspend execution.\n * The SDK calls our methods with opaque IDs. We don't validate or interpret\n * them - we just track phases and detect dormancy.\n */\n\n// ----------------------------------------------------------------------------\n// Types\n// ----------------------------------------------------------------------------\n\n/**\n * Runtime phases for dormancy detection.\n * These are tick-local and transient - not persisted.\n */\ntype RuntimePhase =\n  | \"ACTIVE\" // User code running (blocks termination)\n  | \"REGISTERED\" // Wait registered, not yet awaited\n  | \"WAITING\" // Wait awaited, waiting on external event\n  | \"PAUSED\" // Retry scheduled (SDK told us)\n  | \"COMPLETE\"; // Done (SDK told us)\n\n/**\n * Internal tracking - the library only cares about id and phase.\n * No name, no type - those are SDK concerns.\n */\ninterface TrackedOperation {\n  id: string;\n  phase: RuntimePhase;\n  createdAt: number;\n}\n\n/**\n * Entry in the ready queue for race disambiguation.\n * Operations register here when they become ready; tracker releases in sortKey order.\n */\ninterface ReadyEntry {\n  name: string;\n  sortKey: number; // opaque - SDK provides timestamps, tracker just sorts\n  resolve: () => void;\n}\n\nexport interface TerminationResult {\n  reason: \"blockers_only\";\n  pendingBlockers: string[]; // IDs of waits - SDK decides what they mean\n}\n\n// ----------------------------------------------------------------------------\n// TrackedPromise - Instrumented thenable\n// ----------------------------------------------------------------------------\n\n/**\n * A thenable wrapper that intercepts .then() to detect when user code awaits.\n *\n * This is the dormancy library's contribution: observe when promises are awaited.\n * The inner promise and its resolution mechanism are owned by the caller (SDK).\n *\n * Usage:\n *   let resolve: (v: T) => void;\n *   const inner = new Promise<T>(r => { resolve = r; });\n *   const tracked = new TrackedPromise(inner, () => tracker.activateWait(id));\n *   // Later: resolve(value)\n */\nexport class TrackedPromise<T> implements PromiseLike<T> {\n  private _innerPromise: Promise<T>;\n  private _awaited = false;\n  private _onAwaited: () => void;\n\n  constructor(innerPromise: Promise<T>, onAwaited: () => void) {\n    this._innerPromise = innerPromise;\n    this._onAwaited = onAwaited;\n  }\n\n  then<TResult1 = T, TResult2 = never>(\n    onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,\n    onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null,\n  ): Promise<TResult1 | TResult2> {\n    if (!this._awaited) {\n      this._awaited = true;\n      this._onAwaited();\n    }\n    return this._innerPromise.then(onfulfilled, onrejected);\n  }\n\n  catch<TResult = never>(\n    onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null,\n  ): Promise<T | TResult> {\n    return this.then(null, onrejected);\n  }\n\n  finally(onfinally?: (() => void) | null): Promise<T> {\n    return this.then(\n      (value) => {\n        onfinally?.();\n        return value;\n      },\n      (reason) => {\n        onfinally?.();\n        throw reason;\n      },\n    );\n  }\n\n  /** For debugging - check if .then() was called */\n  get isAwaited(): boolean {\n    return this._awaited;\n  }\n}\n\n// ----------------------------------------------------------------------------\n// DormancyTracker - The core state machine\n// ----------------------------------------------------------------------------\n\n/**\n * Tracks runtime phases and detects when it's safe to suspend.\n *\n * The SDK calls our methods to update state. We don't know WHY\n * transitions happen - we just maintain the state machine and\n * detect dormancy (no ACTIVE + at least one WAITING/PAUSED).\n *\n * IDs are opaque strings - could be names, UUIDs, anything.\n * We don't validate or interpret them.\n */\nexport class DormancyTracker {\n  private operations = new Map<string, TrackedOperation>();\n  private terminationResolve?: (result: TerminationResult) => void;\n  private settleTimeout?: ReturnType<typeof setTimeout>;\n  private terminated = false;\n  private logging = true;\n\n  // Ready queue for race disambiguation\n  private readyQueue: ReadyEntry[] = [];\n\n  readonly termination: Promise<TerminationResult>;\n\n  constructor(private settleDelayMs = 50) {\n    this.termination = new Promise((resolve) => {\n      this.terminationResolve = resolve;\n    });\n  }\n\n  setLogging(enabled: boolean): void {\n    this.logging = enabled;\n  }\n\n  // ---------------------------------------------------------------------------\n  // Phase transitions (SDK calls these)\n  // ---------------------------------------------------------------------------\n\n  /** SDK calls this when starting work */\n  beginWork(id: string): void {\n    this.operations.set(id, {\n      id,\n      phase: \"ACTIVE\",\n      createdAt: Date.now(),\n    });\n    this.log(`[${id}] → ACTIVE`);\n    this.cancelPendingTermination();\n  }\n\n  /** SDK calls this when registering a wait (wait/callback) */\n  registerWait(id: string): void {\n    this.operations.set(id, {\n      id,\n      phase: \"REGISTERED\",\n      createdAt: Date.now(),\n    });\n    this.log(`[${id}] → REGISTERED`);\n    // Don't schedule termination - REGISTERED doesn't trigger it\n  }\n\n  /** Called via TrackedPromise.onAwaited when user code awaits */\n  activateWait(id: string): void {\n    const op = this.operations.get(id);\n    if (op && op.phase === \"REGISTERED\") {\n      op.phase = \"WAITING\";\n      this.log(`[${id}] REGISTERED → WAITING`);\n      this.maybeScheduleTermination();\n    }\n  }\n\n  /** SDK calls this when operation completes (success or permanent failure) */\n  complete(id: string): void {\n    const op = this.operations.get(id);\n    if (op && op.phase !== \"COMPLETE\") {\n      const prev = op.phase;\n      op.phase = \"COMPLETE\";\n      this.log(`[${id}] ${prev} → COMPLETE`);\n      this.maybeScheduleTermination();\n    }\n  }\n\n  /** SDK calls this when scheduling a retry */\n  pause(id: string): void {\n    const op = this.operations.get(id);\n    if (op) {\n      op.phase = \"PAUSED\";\n      this.log(`[${id}] → PAUSED`);\n      this.maybeScheduleTermination();\n    }\n  }\n\n  /** SDK calls this when resuming work after retry timer */\n  resumeWork(id: string): void {\n    const op = this.operations.get(id);\n    if (op) {\n      op.phase = \"ACTIVE\";\n      this.log(`[${id}] → ACTIVE`);\n      this.cancelPendingTermination();\n    }\n  }\n\n  // ---------------------------------------------------------------------------\n  // Ready queue for race disambiguation\n  // ---------------------------------------------------------------------------\n\n  /**\n   * Register an operation as ready with a sortable key.\n   * SDK provides timestamps as sortKeys; tracker releases in order.\n   */\n  registerReady(name: string, sortKey: number, resolve: () => void): void {\n    this.readyQueue.push({ name, sortKey, resolve });\n    // Keep sorted by sortKey (ascending - earliest first)\n    this.readyQueue.sort((a, b) => a.sortKey - b.sortKey);\n    this.log(\n      `[${name}] ready (sortKey=${sortKey}, queue=${this.readyQueue.length})`,\n    );\n  }\n\n  /**\n   * Release the earliest ready operation. Returns true if one was released.\n   * Called during settle loop when dormancy is detected.\n   */\n  private releaseNextReady(): boolean {\n    if (this.readyQueue.length === 0) return false;\n    const earliest = this.readyQueue.shift()!;\n    this.log(`[${earliest.name}] releasing (sortKey=${earliest.sortKey})`);\n    earliest.resolve();\n    return true;\n  }\n\n  // ---------------------------------------------------------------------------\n  // Termination detection (internal)\n  // ---------------------------------------------------------------------------\n\n  private shouldTerminate(): TerminationResult | null {\n    if (this.terminated) return null;\n\n    const ops = Array.from(this.operations.values());\n\n    // Can't terminate if any work in flight\n    if (ops.some((op) => op.phase === \"ACTIVE\")) {\n      return null;\n    }\n\n    // Must have at least one WAITING or PAUSED blocker\n    const blockers = ops.filter(\n      (op) => op.phase === \"WAITING\" || op.phase === \"PAUSED\",\n    );\n    if (blockers.length === 0) {\n      return null;\n    }\n\n    return {\n      reason: \"blockers_only\",\n      pendingBlockers: blockers.map((b) => b.id),\n    };\n  }\n\n  private maybeScheduleTermination(): void {\n    if (this.terminated) return;\n\n    const result = this.shouldTerminate();\n    if (result) {\n      this.cancelPendingTermination();\n      this.settleTimeout = setTimeout(() => {\n        this.runSettleLoop();\n      }, this.settleDelayMs);\n    }\n  }\n\n  /**\n   * Settle loop: release ready operations in order, re-check dormancy after each.\n   * This handles both Promise.race (earliest wins, tick continues) and Promise.all\n   * (all eventually resolve) semantics correctly.\n   */\n  private runSettleLoop(): void {\n    if (this.terminated) return;\n\n    // Check if we should terminate\n    const result = this.shouldTerminate();\n    if (!result) {\n      // Not dormant anymore - user code continued\n      return;\n    }\n\n    // Try to release a ready operation\n    if (this.releaseNextReady()) {\n      // Released one - schedule re-check after settle delay\n      // (releasing might trigger new work, or just resolve a Promise.race)\n      this.settleTimeout = setTimeout(() => {\n        this.runSettleLoop();\n      }, this.settleDelayMs);\n      return;\n    }\n\n    // No ready operations and still dormant - actually terminate\n    this.terminated = true;\n    this.log(`TERMINATING: ${result.pendingBlockers.join(\", \")}`);\n    this.terminationResolve?.(result);\n  }\n\n  private cancelPendingTermination(): void {\n    if (this.settleTimeout) {\n      clearTimeout(this.settleTimeout);\n      this.settleTimeout = undefined;\n    }\n  }\n\n  private log(msg: string): void {\n    if (this.logging) {\n      console.log(`  [dormancy] ${msg}`);\n    }\n  }\n\n  get stats() {\n    const ops = Array.from(this.operations.values());\n    return {\n      total: ops.length,\n      active: ops.filter((o) => o.phase === \"ACTIVE\").length,\n      registered: ops.filter((o) => o.phase === \"REGISTERED\").length,\n      waiting: ops.filter((o) => o.phase === \"WAITING\").length,\n      paused: ops.filter((o) => o.phase === \"PAUSED\").length,\n      complete: ops.filter((o) => o.phase === \"COMPLETE\").length,\n    };\n  }\n}\n","/**\n * DurableContext - The context object passed to durable execution functions.\n *\n * Provides:\n * - step(name, fn) - Execute a durable step\n * - wait(name, seconds) - Wait for a duration\n * - createCallback(name) - Create a callback and get [promise, url]\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { z } from \"zod\";\nimport type {\n  DurableClient,\n  CheckpointRequest,\n  ErrorMetadata,\n  Operation,\n  OperationType,\n  HeldRunState,\n} from \"./types\";\nimport { classifyError, heldReasonFor } from \"./errorClassification\";\nimport {\n  DuplicateNameError,\n  NestedStepError,\n  SuspendInsideStepError,\n  StepExhaustedError,\n  OperationTypeMismatchError,\n  ReservedOperationNameError,\n  TickReleasedError,\n  ResultCorruptError,\n  RequestOutcomeUnknownError,\n  LeaseConflictError,\n  isSdkError,\n} from \"./errors\";\nimport type { DeterminismGuard } from \"./guard\";\nimport { DeterminismViolation } from \"./guard\";\nimport type { DormancyTracker } from \"./dormancy\";\nimport type { OperationBundleResolver } from \"./externalization/resolver\";\nimport {\n  isSentinelPrefix,\n  type DeferrableField,\n} from \"./externalization/constants\";\nimport {\n  validateMaxAttempts,\n  validateWaitSeconds,\n  validateCallbackSeconds,\n  clampRetryDelayMs,\n} from \"./limits\";\nimport { getConfig } from \"./config\";\nimport {\n  serializeError,\n  deserializeError,\n  guardErrorCause,\n} from \"./errorCause\";\nimport { TrackedPromise } from \"./dormancy\";\n\n/**\n * Clock interface for time operations.\n * Allows injecting a mock clock for testing.\n */\nexport interface Clock {\n  /** Returns current time in milliseconds since epoch (like Date.now()). */\n  now(): number;\n}\n\n/** Default clock using global Date. */\nexport const defaultClock: Clock = {\n  now: () => Date.now(),\n};\n\n/**\n * Reserved prefix for synthetic DormancyTracker ids the SDK uses to\n * protect in-flight checkpoint HTTP calls from being abandoned by\n * dormancy. User operation names that start with this prefix are\n * rejected at validation time so a user-named operation cannot collide\n * with a synthetic id and cause the synthetic worker's complete() to\n * terminate a real operation's tracker entry.\n */\nexport const INTERNAL_TRACKER_PREFIX = \"__zapier_internal__:\";\n\n/** Real-time sleep, used only to absorb a sub-threshold ctx.wait in-process. */\nfunction sleep(ms: number): Promise<void> {\n  return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/** Strip $schema URI from JSON Schema - AJV draft-07 doesn't understand draft 2020-12 URIs. */\nfunction stripSchemaUri<T extends object>(schema: T): Omit<T, \"$schema\"> {\n  const copy = { ...schema } as T & { $schema?: string };\n  delete copy.$schema;\n  return copy as Omit<T, \"$schema\">;\n}\n\n/**\n * Tracks whether execution is inside a step, for enforcing step boundaries.\n * Prevents nested steps and waits/callbacks inside steps.\n */\nclass StepScope {\n  private als = new AsyncLocalStorage<{ name: string }>();\n\n  /** Returns true if currently executing inside a step. */\n  isInside(): boolean {\n    return this.als.getStore() !== undefined;\n  }\n\n  /** Returns the current step name, or null if not inside a step. */\n  currentName(): string | null {\n    return this.als.getStore()?.name ?? null;\n  }\n\n  /** Execute fn inside a step scope. */\n  enter<T>(name: string, fn: () => T): T {\n    return this.als.run({ name }, fn);\n  }\n}\n\nexport interface DurableContextOptions {\n  client: DurableClient;\n  tracker: DormancyTracker;\n  guard: DeterminismGuard;\n  executionId: string;\n  leaseToken: string;\n  operations: Map<string, Operation>;\n  /**\n   * Resolver for externalized field bags.\n   *\n   * `runTick` always constructs one and passes it in. The field is\n   * `optional` only to support direct construction of `DurableContext`\n   * outside the runner (test fixtures, future embeddings) — no in-tree\n   * caller does that today.\n   *\n   * Behavior when a sentinel-shaped value is read from a completed\n   * operation:\n   *   - resolver present (production path): fetches the bundle. If the\n   *     underlying client lacks `fetchDeferred` and the presigned path\n   *     is unavailable, the resolver's `deferredFetcher` wrapper throws\n   *     and the tick fails.\n   *   - resolver absent (direct-construction only): the sentinel string\n   *     flows through verbatim as the step result.\n   */\n  bundleResolver?: OperationBundleResolver;\n  maxAttempts?: number;\n  /** Clock for time operations. Defaults to Date.now(). Inject a mock for testing. */\n  clock?: Clock;\n  /** `execution.wire_version ?? 0`, immutably stamped by the server at the start of the execution. */\n  wireVersion?: number;\n}\n\n// Type for step options\nexport interface StepOptions<T> {\n  name: string;\n  run: () => Promise<T>;\n  maxAttempts?: number;\n  retryDelaySeconds?: number;\n  outputSchema?: z.ZodSchema<T>;\n}\n\n// Type for wait options\nexport interface WaitOptions {\n  name: string;\n  seconds: number;\n}\n\n// No deadline: awaiting resolves the bare payload.\nexport interface CallbackOptions<T = unknown> {\n  name: string;\n  payloadSchema?: z.ZodSchema<T>;\n}\n\n// Has a deadline: awaiting resolves a CallbackResult<T>.\nexport interface CallbackOptionsWithTimeout<T = unknown>\n  extends CallbackOptions<T> {\n  timeoutSeconds: number;\n}\n\nexport type CallbackResult<T = unknown> =\n  | { status: \"delivered\"; value: T; at: string }\n  | { status: \"expired\"; at: string };\n\n/**\n * A step that failed on this tick but still has attempts left, so the\n * execution suspended to retry rather than exhausting. Recorded on the tick's\n * DurableResult so a host can observe the failure that occurred without\n * waiting for the step to exhaust.\n *\n * This records the failure event, not the retry state: a step that is still\n * in backoff on a later tick (replayed via the time gate without executing)\n * is not recorded again.\n */\nexport interface RetryingStep {\n  /** The step (operation) name that failed. */\n  name: string;\n  /**\n   * The underlying error, already serialized (JSON-safe) by `serializeError`:\n   * name, message, stack, own properties, and the recursive `cause`. The same\n   * bytes journaled with the failed checkpoint.\n   */\n  error: unknown;\n  /** 1-based attempt number that just failed. */\n  attempt: number;\n  /** ISO timestamp when the step is next eligible to run. */\n  nextRetryAt: string;\n}\n\nexport class DurableContext {\n  private client: DurableClient;\n  private tracker: DormancyTracker;\n  private guard: DeterminismGuard;\n  private stepScope = new StepScope();\n  private usedNames = new Set<string>();\n  private operations: Map<string, Operation>;\n  private executionId: string;\n  private leaseToken: string;\n  private maxAttempts: number;\n  private clock: Clock;\n  // Execution's stamped wire version (execution.wire_version ?? 0), fixed for\n  // the execution's life. Dispatches callback resolution: v0 replays legacy,\n  // v1+ resolves a timeoutSeconds callback as a CallbackResult. Under v0 such a\n  // callback is typed CallbackResult but resolves the bare payload — the\n  // \"type-lie\" the createCallbackV0 warn flags.\n  private wireVersion: number;\n  private bundleResolver?: OperationBundleResolver;\n\n  // For resolving callbacks externally (test helper)\n  private callbackResolvers = new Map<string, (payload: unknown) => void>();\n\n  // Stores checkpoint errors for runner to check after dormancy\n  private checkpointError?: Error;\n\n  // Numbers each checkpoint request's DormancyTracker id.\n  private checkpointRequests = 0;\n\n  // Seconds absorbed by in-process waits so far this tick. The context is\n  // rebuilt fresh every tick, so this doubles as the per-tick budget counter.\n  private inProcessWaitSecondsUsed = 0;\n\n  // Set by the runner immediately before it releases this tick's lease. An\n  // in-process sleep still in flight when this flips checks it after waking\n  // to skip a completed checkpoint that could only fail against the\n  // already-released lease.\n  private tickReleased = false;\n\n  // Set when a checkpoint leaves the tick unable to write: its outcome is\n  // unknown (the server may have saved it even though no response arrived),\n  // or the server rejected it because this tick no longer holds a valid\n  // lease. From then on the tick must not write or start anything, even if\n  // user code catches the error, so the next tick replays exactly what the\n  // server saved. Release accepts an expired lease whose token still\n  // matches, so a tick that kept going could otherwise complete or fail the\n  // execution without the rejected step.\n  private writeError?: RequestOutcomeUnknownError | LeaseConflictError;\n\n  /** The first checkpoint error that ended this tick's writes, if any. */\n  getWriteError(): RequestOutcomeUnknownError | LeaseConflictError | undefined {\n    return this.writeError;\n  }\n\n  /** Returns any checkpoint error that occurred during the tick. */\n  getCheckpointError(): Error | undefined {\n    return this.checkpointError;\n  }\n\n  /** Runner calls this immediately before every client.release call. */\n  markReleased(): void {\n    this.tickReleased = true;\n  }\n\n  // Steps that failed this tick with attempts remaining, so the execution\n  // suspended to retry. The runner reads this on the \"waiting\" return so a\n  // suspended tick can report the error that occurred without waiting for\n  // exhaustion. Distinct from checkpointError (an SDK-internal checkpoint\n  // failure); this is a user step's failure.\n  private retryingSteps: RetryingStep[] = [];\n\n  /** Steps that failed this tick with retries remaining (empty if none). */\n  getRetryingSteps(): RetryingStep[] {\n    return this.retryingSteps;\n  }\n\n  // Set when a step's failure on this tick is classified as should be held.\n  // Saved in-memory only, so each tick builds a fresh context, and re-derives from\n  // the live error every time.\n  private pendingHold?: HeldRunState;\n\n  /** Returns held run override for this tick's release, if any step earned one. */\n  getPendingHold(): HeldRunState | undefined {\n    return this.pendingHold;\n  }\n\n  /** Dormancy termination promise — resolves when all work is done and execution is suspended. */\n  get termination(): Promise<unknown> {\n    return this.tracker.termination;\n  }\n\n  /**\n   * Creates a TrackedPromise that runs its onAwaited callback in ALLOWED mode.\n   *\n   * TrackedPromise callbacks execute when user code awaits - which happens in\n   * GUARDED context. This helper centralizes the mode switch for SDK internals.\n   */\n  private guardedPromise<T>(\n    inner: Promise<T>,\n    onAwaited: () => void,\n  ): TrackedPromise<T> {\n    return new TrackedPromise(inner, () => this.guardAllowed(onAwaited));\n  }\n\n  /** Runs fn in ALLOWED mode (permits non-deterministic APIs). */\n  private guardAllowed<T>(fn: () => T): T {\n    return this.guard.runAllowed(fn);\n  }\n\n  /**\n   * Replay a settled callback outcome, ordered by the journaled readyAt.\n   */\n  private replaySettled<V>(\n    name: string,\n    readyAt: number,\n    value: V,\n  ): TrackedPromise<V> {\n    let resolve: (v: V) => void;\n    const inner = new Promise<V>((r) => {\n      resolve = r;\n    });\n    return this.guardedPromise(inner, () => {\n      this.tracker.activateWait(name);\n      this.tracker.registerReady(name, readyAt, () => {\n        resolve(value);\n        this.tracker.complete(name);\n      });\n    });\n  }\n\n  /**\n   * Suspend a pending callback. The stored resolver fires only via the\n   * resolveCallback test helper — production deliveries replay from the\n   * journal.\n   */\n  private suspendPending<V>(\n    name: string,\n    toValue: (payload: unknown) => V,\n  ): TrackedPromise<V> {\n    let resolve: (v: V) => void;\n    const inner = new Promise<V>((r) => {\n      resolve = r;\n    });\n    this.callbackResolvers.set(name, (payload: unknown) => {\n      resolve(toValue(payload));\n    });\n    return this.guardedPromise(inner, () => this.tracker.activateWait(name));\n  }\n\n  /** Returns a promise that never resolves - signals suspension to the runtime. */\n  private suspend(): Promise<never> {\n    return new Promise(() => {});\n  }\n\n  /**\n   * Checkpoints an operation and updates local cache with server response.\n   *\n   * The request counts as ACTIVE work until it settles, so dormancy cannot\n   * release the tick while a write is in flight. Without this, a parallel\n   * branch that is already WAITING or PAUSED lets the tick release under a\n   * createCallback checkpoint. The callback then resolves after the release,\n   * and user code runs its next step against a released lease.\n   */\n  private async checkpoint(\n    operation: CheckpointRequest[\"operation\"],\n  ): Promise<Operation> {\n    if (this.writeError) throw this.writeError;\n    const workId = `${INTERNAL_TRACKER_PREFIX}checkpoint-request:${++this.checkpointRequests}`;\n    this.tracker.beginWork(workId);\n    let response;\n    try {\n      response = await this.client.checkpoint(this.executionId, {\n        lease_token: this.leaseToken,\n        operation,\n      });\n    } catch (error) {\n      if (\n        error instanceof RequestOutcomeUnknownError ||\n        error instanceof LeaseConflictError\n      ) {\n        this.writeError ??= error;\n      }\n      throw error;\n    } finally {\n      this.tracker.complete(workId);\n    }\n    // Sync local cache with server-generated fields\n    this.operations.set(response.operation.name, response.operation);\n    return response.operation;\n  }\n\n  /** Constructs callback URL from token using client's base URL. */\n  private callbackUrl(token: string): string {\n    return `${this.client.callbackBaseUrl}/${token}`;\n  }\n\n  /**\n   * Validates operation invariants and returns existing operation if any.\n   *\n   * Checks:\n   * - Name uniqueness (throws DuplicateNameError)\n   * - Not inside a step (throws NestedStepError or SuspendInsideStepError)\n   * - Type consistency with existing operation (throws OperationTypeMismatchError)\n   */\n  private validateOperation(\n    name: string,\n    type: OperationType,\n  ): Operation | undefined {\n    // Nothing new starts once the tick can no longer write.\n    if (this.writeError) throw this.writeError;\n    // Nothing new starts once the tick has released: it could not be saved.\n    if (this.tickReleased) throw new TickReleasedError(name);\n    if (name.startsWith(INTERNAL_TRACKER_PREFIX)) {\n      throw new ReservedOperationNameError(name, INTERNAL_TRACKER_PREFIX);\n    }\n    if (this.usedNames.has(name)) {\n      throw new DuplicateNameError(name);\n    }\n    this.usedNames.add(name);\n\n    if (this.stepScope.isInside()) {\n      throw type === \"step\"\n        ? new NestedStepError(name, this.stepScope.currentName())\n        : new SuspendInsideStepError(type, name, this.stepScope.currentName());\n    }\n\n    const existing = this.operations.get(name);\n    if (existing && existing.type !== type) {\n      throw new OperationTypeMismatchError(name, type, existing.type);\n    }\n\n    return existing;\n  }\n\n  constructor(options: DurableContextOptions) {\n    this.client = options.client;\n    this.tracker = options.tracker;\n    this.guard = options.guard;\n    this.executionId = options.executionId;\n    this.leaseToken = options.leaseToken;\n    this.operations = options.operations;\n    this.bundleResolver = options.bundleResolver;\n    this.maxAttempts = validateMaxAttempts(options.maxAttempts);\n    this.clock = options.clock ?? defaultClock;\n    this.wireVersion = options.wireVersion ?? 0;\n  }\n\n  /**\n   * Returns the materialized value of a deferrable field on a completed\n   * operation, handling the externalized-bundle case transparently. If the\n   * inline value is a sentinel string, the bundle is fetched (or read from\n   * cache) via the resolver and the requested field is read from it.\n   * Without a resolver (e.g. memory client), sentinels pass through as\n   * raw strings — those clients don't produce sentinels anyway.\n   *\n   * `field` is typed against `DEFERRABLE_FIELDS`, so adding a new field to\n   * the externalization contract requires updating the constants module —\n   * the call sites won't compile against a stale list.\n   */\n  private async readDeferredField<T>(\n    existing: Operation,\n    field: DeferrableField,\n  ): Promise<T> {\n    const inline = (existing as unknown as Record<string, unknown>)[field];\n    if (this.bundleResolver && isSentinelPrefix(inline)) {\n      // Register the S3/fetchDeferred round-trip as ACTIVE work so dormancy\n      // cannot terminate the tick while hydration is in flight. Without this,\n      // a completed externalized step replayed alongside a live blocker (e.g.\n      // inside Promise.all) is invisible to shouldTerminate() (no ACTIVE op),\n      // so the settle loop suspends the tick mid-fetch, abandons this promise,\n      // and strands the run. Mirrors the checkpoint guard below.\n      const hydrateWorkId = `${INTERNAL_TRACKER_PREFIX}hydrate:${existing.name}`;\n      this.tracker.beginWork(hydrateWorkId);\n      try {\n        const bag = await this.bundleResolver.resolve(existing);\n        if (!(field in bag)) {\n          throw new ResultCorruptError(\n            `Bundle for operation ${existing.id} missing expected field \"${field}\"`,\n            {\n              kind: \"decompress_error\",\n              executionId: this.executionId,\n              operationId: existing.id,\n            },\n          );\n        }\n        return bag[field] as T;\n      } finally {\n        this.tracker.complete(hydrateWorkId);\n      }\n    }\n    return inline as T;\n  }\n\n  // Overloaded step signatures\n  step<T>(name: string, fn: () => Promise<T>): Promise<T>;\n  step<T>(options: StepOptions<T>): Promise<T>;\n  async step<T>(\n    nameOrOptions: string | StepOptions<T>,\n    fn?: () => Promise<T>,\n  ): Promise<T> {\n    const name =\n      typeof nameOrOptions === \"string\" ? nameOrOptions : nameOrOptions.name;\n    const run = typeof nameOrOptions === \"string\" ? fn! : nameOrOptions.run;\n    const maxAttempts =\n      typeof nameOrOptions === \"string\"\n        ? this.maxAttempts\n        : validateMaxAttempts(nameOrOptions.maxAttempts ?? this.maxAttempts);\n    const retryDelaySeconds =\n      typeof nameOrOptions === \"string\"\n        ? 5\n        : (nameOrOptions.retryDelaySeconds ?? 5);\n    const existing = this.validateOperation(name, \"step\");\n\n    if (existing?.status === \"completed\") {\n      // SDK-internal transport (fetch / crypto.subtle) — run in ALLOWED so\n      // the determinism guard's globals patch doesn't trip user code that\n      // happens to be awaiting a sentinel-bearing step replay.\n      return this.guardAllowed(() =>\n        this.readDeferredField<T>(existing, \"result\"),\n      );\n    }\n    if (existing?.status === \"exhausted\") {\n      throw new StepExhaustedError(\n        name,\n        guardErrorCause(deserializeError(existing.error), this.guard),\n      );\n    }\n\n    // Entire step body in ALLOWED - SDK internals + user fn\n    return this.stepScope.enter(name, () => {\n      return this.guardAllowed(async () => {\n        // Time gating: if retry not due yet, suspend without executing\n        // Uses operation's next_retry_at from server, compared against current time\n        if (existing?.status === \"failed\" && existing.next_retry_at) {\n          const nextRetry = new Date(existing.next_retry_at).getTime();\n          if (nextRetry > this.clock.now()) {\n            this.tracker.beginWork(name);\n            this.tracker.pause(name);\n            return this.suspend();\n          }\n        }\n\n        this.tracker.beginWork(name);\n\n        try {\n          const result = await run();\n          await this.checkpoint({\n            name,\n            type: \"step\",\n            status: \"completed\",\n            result,\n          });\n          this.tracker.complete(name);\n          return result;\n        } catch (error) {\n          if (isSdkError(error) || error instanceof DeterminismViolation) {\n            this.tracker.complete(name);\n            throw error;\n          }\n\n          // Serialize once: the journaled bytes are both what we checkpoint\n          // and what the live-exhaustion cause is rehydrated from, so the\n          // cause a workflow catches on this tick is identical to the one it\n          // catches on every replay tick.\n          const serializedError = serializeError(error);\n          const classification = classifyError({ error });\n          const errorMetadata: ErrorMetadata = { cause: classification.cause };\n          if (classification.statusCode !== undefined) {\n            errorMetadata.statusCode = classification.statusCode;\n          }\n          const attempt = (existing?.retry_count ?? 0) + 1;\n          // SDK is authoritative on exhaustion; server uses max_attempts only\n          // for wake scheduling (retry_count < max_attempts).\n\n          // Wrap the failure/exhausted checkpoint in a synthetic ACTIVE\n          // worker so dormancy cannot fire while the checkpoint is in\n          // flight. Without this guard, pause(name) below would transition\n          // the step to PAUSED before the HTTP call completes; the runner\n          // would then race ahead, call release(), null the lease, and the\n          // checkpoint would land as 409 \"Lease invalid or expired\" with the\n          // operation never recorded.\n          //\n          // The id uses INTERNAL_TRACKER_PREFIX so it cannot collide with\n          // a user-named operation -- validateOperation rejects any user\n          // name that starts with that prefix.\n          const checkpointWorkId = `${INTERNAL_TRACKER_PREFIX}checkpoint:${name}`;\n\n          if (attempt < maxAttempts) {\n            const baseMs = retryDelaySeconds * 1000;\n            const backoffMs = clampRetryDelayMs(\n              baseMs * Math.pow(2, attempt - 1),\n            );\n            // Compute next_retry_at client-side (SDK owns retry policy)\n            const nextRetryAt = new Date(\n              this.clock.now() + backoffMs,\n            ).toISOString();\n            this.tracker.beginWork(checkpointWorkId);\n            try {\n              await this.checkpoint({\n                name,\n                type: \"step\",\n                status: \"failed\",\n                error: serializedError,\n                error_metadata: errorMetadata,\n                retry_count: attempt,\n                max_attempts: maxAttempts,\n                next_retry_at: nextRetryAt,\n              });\n            } finally {\n              this.tracker.complete(checkpointWorkId);\n            }\n            this.tracker.pause(name);\n            // Record the failure so the runner can report it on this tick's\n            // \"waiting\" return. serializedError is the same JSON-safe chain\n            // journaled above.\n            this.retryingSteps.push({\n              name,\n              error: serializedError,\n              attempt,\n              nextRetryAt,\n            });\n            // The `!this.pendingHold` check is for cases like\n            // `Promise.all()` where multiple steps are in the `held` condition\n            // The first one to resolve with a hold will populate the held reason.\n            const heldReason = heldReasonFor(classification.cause);\n            if (heldReason && !this.pendingHold) {\n              this.pendingHold = {\n                status: \"held\",\n                reason: heldReason,\n                ...(classification.detail !== undefined\n                  ? { detail: classification.detail }\n                  : {}),\n              };\n            }\n            return this.suspend();\n          } else {\n            this.tracker.beginWork(checkpointWorkId);\n            try {\n              await this.checkpoint({\n                name,\n                type: \"step\",\n                status: \"exhausted\",\n                error: serializedError,\n                error_metadata: errorMetadata,\n                retry_count: attempt,\n                max_attempts: maxAttempts,\n              });\n            } finally {\n              this.tracker.complete(checkpointWorkId);\n            }\n            this.tracker.complete(name);\n            throw new StepExhaustedError(\n              name,\n              guardErrorCause(deserializeError(serializedError), this.guard),\n            );\n          }\n        }\n      });\n    });\n  }\n\n  /**\n   * Await-time absorption decision: eligible waits sleep out the remainder\n   * in-process and checkpoint completed; ineligible ones just activateWait\n   * and suspend as today. Shared by a wait's first tick (pendingSucceeded\n   * settles its call-time pending checkpoint) and a replay that finds it\n   * already pending (pendingSucceeded is a resolved-true promise; the\n   * journaled resume_at is already in this.operations from checkout).\n   *\n   * The decision and the sleep both derive from the server-stamped\n   * resume_at -- never a local clock snapshot taken before the checkpoint\n   * response lands.\n   */\n  private async absorbWaitAtAwait(\n    name: string,\n    pendingSucceeded: Promise<boolean>,\n    resolve: () => void,\n  ): Promise<void> {\n    this.tracker.activateWait(name);\n\n    // The wait is now a WAITING blocker, not ACTIVE work, so it alone\n    // wouldn't stop dormancy from firing while we're still awaiting the\n    // pending checkpoint's response. Cover that gap with our own ACTIVE\n    // work rather than relying on the call site's checkpointWorkId, whose\n    // `finally` may already have completed by the time we get here.\n    const pendingWaitWorkId = `${INTERNAL_TRACKER_PREFIX}wait-pending:${name}`;\n    this.tracker.beginWork(pendingWaitWorkId);\n    let ok: boolean;\n    try {\n      ok = await pendingSucceeded;\n    } finally {\n      this.tracker.complete(pendingWaitWorkId);\n    }\n    // Checkpoint failed (checkpointError is already stored for the runner\n    // to surface): suspend as a normal blocker. No absorption, no budget\n    // charge -- the sticky checkpointError makes this tick's eventual\n    // release report failed, same as any other checkpoint failure.\n    if (!ok) return;\n\n    // Authoritative: the pending checkpoint landed, so this.operations\n    // carries the server-stamped resume_at.\n    const resumeAtIso = this.operations.get(name)!.resume_at!;\n    const resumeAtMs = new Date(resumeAtIso).getTime();\n    const remainingSeconds = Math.max(0, resumeAtMs - this.clock.now()) / 1000;\n\n    const config = getConfig();\n    const eligible =\n      config.waitInProcessThresholdSeconds > 0 &&\n      remainingSeconds <= config.waitInProcessThresholdSeconds &&\n      this.inProcessWaitSecondsUsed + remainingSeconds <=\n        config.waitInProcessBudgetSeconds;\n    if (!eligible) return;\n\n    this.inProcessWaitSecondsUsed += remainingSeconds;\n    const sleepWorkId = `${INTERNAL_TRACKER_PREFIX}inprocess-sleep:${name}`;\n    this.tracker.beginWork(sleepWorkId);\n\n    await sleep(remainingSeconds * 1000);\n\n    if (this.tickReleased) {\n      // The tick released mid-sleep; the pending row already covers the\n      // wait, so a post-release checkpoint could only fail against the\n      // released lease. This branch skips registerReady below, so it must\n      // complete the wait's own tracker id itself.\n      this.tracker.complete(sleepWorkId);\n      this.tracker.complete(name);\n      resolve();\n      return;\n    }\n\n    try {\n      await this.checkpoint({\n        name,\n        type: \"wait\",\n        status: \"completed\",\n        resume_at: resumeAtIso,\n      });\n    } catch {\n      // A completed checkpoint that fails after a successful pending\n      // checkpoint does not poison the run: the pending row already covers\n      // durability, and replay resolves this wait on the same branch below.\n    }\n\n    this.tracker.complete(sleepWorkId);\n    this.tracker.registerReady(name, resumeAtMs, () => {\n      resolve();\n      this.tracker.complete(name);\n    });\n  }\n\n  // Overloaded wait signatures\n  wait(name: string, seconds: number): TrackedPromise<void>;\n  wait(options: WaitOptions): TrackedPromise<void>;\n  wait(\n    nameOrOptions: string | WaitOptions,\n    secondsArg?: number,\n  ): TrackedPromise<void> {\n    const name =\n      typeof nameOrOptions === \"string\" ? nameOrOptions : nameOrOptions.name;\n    const seconds = validateWaitSeconds(\n      typeof nameOrOptions === \"string\" ? secondsArg! : nameOrOptions.seconds,\n    );\n    const existing = this.validateOperation(name, \"wait\");\n\n    // Entire wait body in ALLOWED (no user code here, just SDK internals)\n    return this.guardAllowed(() => {\n      // Completed wait (either from replay or server-side auto-completion at\n      // checkout) — register with ready queue.\n      if (existing?.status === \"completed\") {\n        this.tracker.registerWait(name);\n\n        let resolve: () => void;\n        const inner = new Promise<void>((r) => {\n          resolve = r;\n        });\n\n        // Use resume_at if available, otherwise use created_at as fallback\n        const readyAt = existing.resume_at\n          ? new Date(existing.resume_at).getTime()\n          : new Date(existing.created_at).getTime();\n\n        return this.guardedPromise(inner, () => {\n          this.tracker.activateWait(name);\n          // Register with ready queue for proper ordering\n          this.tracker.registerReady(name, readyAt, () => {\n            resolve();\n            this.tracker.complete(name);\n          });\n        });\n      }\n\n      // First time or pending: register, and on first encounter always\n      // checkpoint pending (the in-process threshold/budget decision moves\n      // entirely to await time, in absorbWaitAtAwait). Until awaited this\n      // is indistinguishable from an above-threshold wait: an unawaited\n      // wait is a journaled pending row and nothing more, and no timer\n      // exists before the first await, matching the suspend path.\n      let resolve: () => void;\n      const inner = new Promise<void>((r) => {\n        resolve = r;\n      });\n\n      if (!existing) {\n        this.tracker.registerWait(name);\n\n        // See INTERNAL_TRACKER_PREFIX docs: this id cannot collide with a\n        // user-named operation because validateOperation rejects names with\n        // the reserved prefix.\n        const checkpointWorkId = `${INTERNAL_TRACKER_PREFIX}checkpoint:${name}`;\n        this.tracker.beginWork(checkpointWorkId);\n        // Send the duration; the server stamps resume_at from its own clock.\n        // pendingSucceeded conveys success: true once the response landed\n        // and this.operations carries the server-stamped resume_at, false\n        // on failure (the error is still stored to checkpointError below).\n        const pendingSucceeded: Promise<boolean> = this.checkpoint({\n          name,\n          type: \"wait\",\n          status: \"pending\",\n          duration_seconds: seconds,\n        })\n          .then(() => true)\n          .catch((error) => {\n            this.checkpointError = error; // Store for runner to check after dormancy\n            return false;\n          })\n          .finally(() => {\n            this.tracker.complete(checkpointWorkId); // Always complete - enables dormancy\n          });\n\n        return this.guardedPromise(inner, () =>\n          this.absorbWaitAtAwait(name, pendingSucceeded, resolve),\n        );\n      }\n\n      // Replay: journal already has this wait pending from an earlier tick,\n      // with its server-stamped resume_at already in this.operations from\n      // checkout. Same await-time decision as first encounter; no checkpoint\n      // to send here since a previous tick already did.\n      this.tracker.registerWait(name);\n\n      return this.guardedPromise(inner, () =>\n        this.absorbWaitAtAwait(name, Promise.resolve(true), resolve),\n      );\n    });\n  }\n\n  // Overloaded createCallback signatures\n  createCallback(name: string): Promise<[TrackedPromise<unknown>, string]>;\n  createCallback<T>(\n    options: CallbackOptionsWithTimeout<T>,\n  ): Promise<[TrackedPromise<CallbackResult<T>>, string]>;\n  createCallback<T>(\n    options: CallbackOptions<T>,\n  ): Promise<[TrackedPromise<T>, string]>;\n  async createCallback<T = unknown>(\n    nameOrOptions: string | CallbackOptions<T> | CallbackOptionsWithTimeout<T>,\n  ): Promise<[TrackedPromise<T> | TrackedPromise<CallbackResult<T>>, string]> {\n    const name =\n      typeof nameOrOptions === \"string\" ? nameOrOptions : nameOrOptions.name;\n    const timeoutSeconds =\n      typeof nameOrOptions !== \"string\" && \"timeoutSeconds\" in nameOrOptions\n        ? nameOrOptions.timeoutSeconds\n        : undefined;\n    const payloadSchema =\n      typeof nameOrOptions === \"string\"\n        ? undefined\n        : nameOrOptions.payloadSchema;\n    const op = this.validateOperation(name, \"callback\");\n\n    if (this.wireVersion >= 1) {\n      return this.createCallbackV1<T>({\n        name,\n        timeoutSeconds,\n        payloadSchema,\n        op,\n      });\n    }\n    return this.createCallbackV0<T>({\n      name,\n      timeoutSeconds,\n      payloadSchema,\n      op,\n    });\n  }\n\n  /**\n   * The wire v0 callback path. v0 has no server-side expiry, so a callback\n   * here can only ever be delivered: with timeoutSeconds it resolves a\n   * delivered CallbackResult (never an expired one) to honour the overload's\n   * type; without it, the bare payload, byte-identical to legacy.\n   */\n  private async createCallbackV0<T>({\n    name,\n    timeoutSeconds,\n    payloadSchema,\n    op: existing,\n  }: {\n    name: string;\n    timeoutSeconds: number | undefined;\n    payloadSchema: z.ZodSchema<T> | undefined;\n    op: Operation | undefined;\n  }): Promise<[TrackedPromise<T> | TrackedPromise<CallbackResult<T>>, string]> {\n    let op = existing;\n    const hasDeadline = timeoutSeconds !== undefined;\n\n    // Entire createCallback body in ALLOWED (no user code here, just SDK internals)\n    return this.guardAllowed(async () => {\n      // First time: checkpoint (server generates token, updates local cache)\n      if (!op) {\n        if (timeoutSeconds !== undefined) {\n          // v0 honours the CallbackResult shape but has no server expiry, so\n          // the callback can only ever resolve { status: \"delivered\" }. We\n          // accept it (in-flight v0 executions pass timeoutSeconds); warn once\n          // that the deadline isn't enforced until the account is on v1.\n          console.warn(\n            `[zapier-durable] execution ${this.executionId}: callback ` +\n              `\"${name}\" was created with timeoutSeconds, but this execution ` +\n              `replays under wire v0 — it resolves a delivered CallbackResult ` +\n              `and never expires. The deadline is not enforced until the ` +\n              `account is on durable_wire_version v1.`,\n          );\n        }\n        const expiresMs = validateCallbackSeconds(timeoutSeconds) * 1000;\n        this.tracker.registerWait(name);\n        // Compute expires_at client-side (SDK owns timeout duration)\n        op = await this.checkpoint({\n          name,\n          type: \"callback\",\n          status: \"pending\",\n          expires_at: new Date(this.clock.now() + expiresMs).toISOString(),\n          payload_schema: payloadSchema\n            ? stripSchemaUri(payloadSchema.toJSONSchema())\n            : undefined,\n        });\n      }\n\n      // op now has server-generated callback_token\n      if (!op.callback_token) {\n        throw new Error(\n          `Callback \"${name}\" missing callback_token - data corruption`,\n        );\n      }\n      const url = this.callbackUrl(op.callback_token);\n\n      // An expired row can't exist in a legitimate v0 journal (the\n      // timeout_seconds column only rides the wire on v1). Fail loudly rather than fall\n      // through to suspend and hang forever.\n      if (op.status === \"expired\") {\n        throw new Error(\n          `Callback \"${name}\" is expired in the journal but this execution ` +\n            `replays under wire v0, which cannot produce expired ` +\n            `callbacks. The journal and the execution's wire version ` +\n            `disagree - data corruption.`,\n        );\n      }\n\n      // Completed: replay the delivered outcome, ordered by completed_at.\n      if (op.status === \"completed\") {\n        this.tracker.registerWait(name);\n        const readyAt = new Date(op.completed_at ?? op.created_at).getTime();\n\n        if (hasDeadline) {\n          // v0 has no server expiry, so a settled callback is always delivered.\n          const outcome: CallbackResult<T> = {\n            status: \"delivered\",\n            value: op.payload as T,\n            at: op.completed_at ?? op.created_at,\n          };\n          return [this.replaySettled(name, readyAt, outcome), url];\n        }\n        return [this.replaySettled<T>(name, readyAt, op.payload as T), url];\n      }\n\n      // Pending: suspend until delivery (v0 never expires).\n      this.tracker.registerWait(name);\n\n      if (hasDeadline) {\n        const tracked = this.suspendPending<CallbackResult<T>>(\n          name,\n          (payload) => ({\n            status: \"delivered\",\n            value: payload as T,\n            at: new Date(this.clock.now()).toISOString(),\n          }),\n        );\n        return [tracked, url];\n      }\n      return [this.suspendPending<T>(name, (payload) => payload as T), url];\n    });\n  }\n\n  /**\n   * Wire v1 callback path. The deadline rides the wire as timeout_seconds\n   * for the server to stamp from its own clock. A call site that passed\n   * timeoutSeconds awaits a CallbackResult; one that didn't resolves the\n   * bare payload and cannot expire.\n   */\n  private async createCallbackV1<T>({\n    name,\n    timeoutSeconds,\n    payloadSchema,\n    op: existing,\n  }: {\n    name: string;\n    timeoutSeconds: number | undefined;\n    payloadSchema: z.ZodSchema<T> | undefined;\n    op: Operation | undefined;\n  }): Promise<[TrackedPromise<T> | TrackedPromise<CallbackResult<T>>, string]> {\n    let op = existing;\n    const hasDeadline = timeoutSeconds !== undefined;\n\n    // Entire createCallback body in ALLOWED (no user code here, just SDK internals)\n    return this.guardAllowed(async () => {\n      // Server generates the callback_token and updates the local cache.\n      if (!op) {\n        const checkpointTimeout = hasDeadline\n          ? validateCallbackSeconds(timeoutSeconds)\n          : undefined;\n        this.tracker.registerWait(name);\n        op = await this.checkpoint({\n          name,\n          type: \"callback\",\n          status: \"pending\",\n          timeout_seconds: checkpointTimeout,\n          payload_schema: payloadSchema\n            ? stripSchemaUri(payloadSchema.toJSONSchema())\n            : undefined,\n        });\n      } else {\n        // Journal wins on values; a mismatch means the durable code changed\n        // between ticks. An absent key (vs explicit null = no-timeout) means the\n        // server didn't echo the column — no opinion, no warning.\n        const journaled = op.timeout_seconds;\n        if (journaled !== undefined && journaled !== (timeoutSeconds ?? null)) {\n          console.warn(\n            `[zapier-durable] execution ${this.executionId}: ` +\n              `Callback \"${name}\": code requests ` +\n              `timeoutSeconds=${timeoutSeconds ?? \"none\"} but the journal ` +\n              `recorded timeout_seconds=${journaled ?? \"none\"}. ` +\n              `The journaled deadline wins.`,\n          );\n        }\n      }\n      const journaledOp = op;\n\n      // Replay shape is journal-derived: an existing row's wrapper-ness is\n      // fixed by its journaled timeout_seconds, so changing the code's\n      // timeoutSeconds between ticks can't flip a settled callback's shape.\n      // An un-echoed column (undefined) means no opinion — use the call site.\n      const wrap =\n        journaledOp.timeout_seconds === undefined\n          ? hasDeadline\n          : journaledOp.timeout_seconds !== null;\n\n      if (!journaledOp.callback_token) {\n        throw new Error(\n          `Callback \"${name}\" missing callback_token - data corruption`,\n        );\n      }\n      const url = this.callbackUrl(journaledOp.callback_token);\n\n      // Settled (completed or expired): replay the journaled outcome.\n      if (\n        journaledOp.status === \"completed\" ||\n        journaledOp.status === \"expired\"\n      ) {\n        this.tracker.registerWait(name);\n\n        // Sort by when the outcome happened: delivery at completed_at,\n        // expiry at expires_at; created_at as fallback for legacy rows.\n        const readyAt = new Date(\n          (journaledOp.status === \"completed\"\n            ? journaledOp.completed_at\n            : journaledOp.expires_at) ?? journaledOp.created_at,\n        ).getTime();\n\n        if (wrap) {\n          // Build the wrapper from journaled fields. Key on status, not\n          // field presence — a delivered JSON null payload is legal.\n          const outcome: CallbackResult<T> =\n            journaledOp.status === \"completed\"\n              ? {\n                  status: \"delivered\",\n                  value: journaledOp.payload as T,\n                  at: journaledOp.completed_at ?? journaledOp.created_at,\n                }\n              : {\n                  status: \"expired\",\n                  at: journaledOp.expires_at ?? journaledOp.created_at,\n                };\n\n          return [this.replaySettled(name, readyAt, outcome), url];\n        }\n\n        if (journaledOp.status === \"expired\") {\n          // Reached only when the journal didn't echo timeout_seconds (so\n          // `wrap` fell back to the call site) and the code now passes none:\n          // an expired callback has no payload to resolve. Fail loudly.\n          throw new Error(\n            `Callback \"${name}\" expired in the journal but neither the ` +\n              `journal nor the current code carries a timeoutSeconds; an ` +\n              `expired callback has no payload to resolve.`,\n          );\n        }\n\n        return [\n          this.replaySettled<T>(name, readyAt, journaledOp.payload as T),\n          url,\n        ];\n      }\n\n      this.tracker.registerWait(name);\n\n      if (wrap) {\n        // The test-helper resolver can only mean a delivery, so a\n        // clock-stamped `at` is acceptable here (see suspendPending).\n        const tracked = this.suspendPending<CallbackResult<T>>(\n          name,\n          (payload) => ({\n            status: \"delivered\",\n            value: payload as T,\n            at: new Date(this.clock.now()).toISOString(),\n          }),\n        );\n        return [tracked, url];\n      }\n\n      return [this.suspendPending<T>(name, (payload) => payload as T), url];\n    });\n  }\n\n  // Test helper: deliver a callback payload in-process. The stored resolver\n  // wraps it to match what the call site awaits (bare payload or\n  // CallbackResult).\n  resolveCallback(name: string, payload: unknown): void {\n    this.guardAllowed(() => {\n      const resolver = this.callbackResolvers.get(name);\n      if (resolver) {\n        resolver(payload);\n        this.tracker.complete(name);\n      }\n    });\n  }\n}\n","import type { HeldReason } from \"./types\";\n\nexport interface ErrorClassification {\n  /** Server cause vocabulary; \"unknown\" when no rule matched. */\n  cause: string;\n  /** HTTP status when the error carries one. */\n  statusCode?: number;\n  /** What the held run points at (a connection id, app key, or action key,\n   * per cause); becomes the hold's detail. */\n  detail?: string;\n}\n\nconst CAUSE_BY_ERROR_CODE = new Map<string, string>([\n  [\"authentication_error\", \"stale_authentication\"],\n  [\"authentication_access_error\", \"authentication_revoked\"],\n  [\"insufficient_tasks\", \"over_task_limit\"],\n  [\"restricted_app\", \"access_restricted_app\"],\n  [\"banned_app_action\", \"banned_app_action\"],\n  [\"REFRESH_AUTH_FAILED\", \"stale_authentication\"], // Relay\n  [\"AUTH_TEMPLATE_NOT_FOUND\", \"authentication_revoked\"], // Relay\n  [\"ACCOUNT_TASKS_EXHAUSTED\", \"over_task_limit\"], // Relay\n]);\n// Hold policy, separate from classification. A cause appears here only when\n// the failure is fixable by user action, so the server should park the run\n// rather than let it burn retries; a cause absent from this map reports on the\n// checkpoint without ever holding.\nconst HELD_REASON_BY_CAUSE = new Map<string, HeldReason>([\n  [\"stale_authentication\", \"stale_authentication\"],\n  [\"authentication_revoked\", \"authentication_revoked\"],\n  [\"over_task_limit\", \"over_task_limit\"],\n  [\"access_restricted_app\", \"app_restriction\"],\n  [\"banned_app_action\", \"banned_app_action\"],\n]);\n\n/** Returns the held reason for a classified cause, iff it is hold-eligible. */\nexport function heldReasonFor(cause: string): HeldReason | undefined {\n  return HELD_REASON_BY_CAUSE.get(cause);\n}\n\nfunction readStatusCode(error: object): number | undefined {\n  const statusCode = (error as { statusCode?: unknown }).statusCode;\n  return typeof statusCode === \"number\" ? statusCode : undefined;\n}\n\nfunction readErrorCodes(error: object): string[] {\n  const errors = (error as { errors?: unknown }).errors;\n  if (!Array.isArray(errors)) return [];\n  return errors\n    .map((entry) => (entry as { code?: unknown } | null)?.code)\n    .filter((code): code is string => typeof code === \"string\");\n}\n\n// Which error field the held run should point at, per cause: the connection\n// to fix for auth failures, the app or action for restrictions. A cause\n// without an entry (over_task_limit — an account quota, no target object)\n// holds with no detail. The SDK stamps these fields on the error at the\n// throw site, so wrapped causes carry them too.\nconst DETAIL_FIELD_BY_CAUSE = new Map<string, string>([\n  [\"stale_authentication\", \"connectionId\"],\n  [\"authentication_revoked\", \"connectionId\"],\n  [\"access_restricted_app\", \"appKey\"],\n  [\"banned_app_action\", \"actionKey\"],\n]);\n\n// `field` comes from DETAIL_FIELD_BY_CAUSE (never from the error), so a plain\n// property read is safe from prototype keys.\nfunction readDetail(error: object, field: string): string | undefined {\n  const value = (error as Record<string, unknown>)[field];\n  if (typeof value === \"string\") return value;\n  if (typeof value === \"number\") return String(value);\n  return undefined;\n}\n\nfunction detailFor({\n  cause,\n  error,\n}: {\n  cause: string;\n  error: object;\n}): string | undefined {\n  const field = DETAIL_FIELD_BY_CAUSE.get(cause);\n  return field === undefined ? undefined : readDetail(error, field);\n}\n\nexport function classifyError({\n  error,\n}: {\n  error: unknown;\n}): ErrorClassification {\n  if (typeof error !== \"object\" || error === null) return { cause: \"unknown\" };\n\n  // Step bodies idiomatically wrap failures (new Error(\"...\", { cause })), so\n  // walk the cause chain. Bounded — a cyclic cause must not hang the tick.\n  let current: unknown = error;\n  for (\n    let depth = 0;\n    depth < 5 && typeof current === \"object\" && current !== null;\n    depth++\n  ) {\n    const statusCode = readStatusCode(current);\n    for (const code of readErrorCodes(current)) {\n      const cause = CAUSE_BY_ERROR_CODE.get(code);\n      if (cause) {\n        return {\n          cause,\n          statusCode,\n          detail: detailFor({ cause, error: current }),\n        };\n      }\n    }\n    current = (current as { cause?: unknown }).cause;\n  }\n  return { cause: \"unknown\", statusCode: readStatusCode(error) };\n}\n","/**\n * SDK-side mirror of the server's wire-protocol constants for externalized\n * step results — header name, capability label, sentinel prefix, and the\n * list of operation fields the server may externalize. Drift between\n * client and server here silently breaks the contract.\n */\n\nexport const SENTINEL_PREFIX = \"zd-ext:v1:\";\n\nexport const CAPABILITY_HEADER = \"x-zapier-durable-capabilities\";\n// Repo lint disallows digits in ALL_CAPS const names; PascalCase keeps the\n// version in the identifier so the server's `CAPABILITY_PRESIGNED_V1` and\n// the SDK constant grep for the same wire value.\nexport const CapabilityPresignedV1 = \"presigned-result-v1\";\n\n/**\n * Operation fields the server may externalize. The SDK scans each of these\n * on every checkout-response operation for sentinel-prefixed strings. Mirror\n * any additions on the server side (`DEFERRABLE_FIELDS`) here.\n */\nexport const DEFERRABLE_FIELDS = [\"result\"] as const;\nexport type DeferrableField = (typeof DEFERRABLE_FIELDS)[number];\n\n/** Cheap shape check; does not verify the HMAC (the SDK has no key for that). */\nexport function isSentinelPrefix(value: unknown): value is string {\n  return typeof value === \"string\" && value.startsWith(SENTINEL_PREFIX);\n}\n","/**\n * Durable Execution Limits\n *\n * Sanity bounds for user-controllable fields. These limits must stay in\n * sync with the server-side schema; changes here require a coordinated\n * server change.\n */\n\nimport { DurableValidationError } from \"./errors\";\n\n/** Duration limits in seconds */\nexport const DURATION_LIMITS = {\n  /** Minimum duration for any timed operation */\n  MIN_SECONDS: 1,\n  /** Maximum duration: 1 year (365 days) */\n  MAX_SECONDS: 365 * 24 * 60 * 60, // 31536000\n} as const;\n\n/** Retry attempt limits */\nexport const RETRY_LIMITS = {\n  /** Minimum retry attempts (must try at least once) */\n  MIN_ATTEMPTS: 1,\n  /** Maximum retry attempts */\n  MAX_ATTEMPTS: 100,\n  /** Default retry attempts */\n  DEFAULT_ATTEMPTS: 5,\n} as const;\n\n/** Wait operation limits (ctx.wait) */\nexport const WAIT_LIMITS = {\n  /** Minimum wait duration in seconds */\n  MIN_SECONDS: DURATION_LIMITS.MIN_SECONDS,\n  /** Maximum wait duration in seconds (1 year) */\n  MAX_SECONDS: DURATION_LIMITS.MAX_SECONDS,\n} as const;\n\n/** Callback operation limits (ctx.createCallback) */\nexport const CALLBACK_LIMITS = {\n  /** Minimum callback TTL in seconds (1 minute) */\n  MIN_SECONDS: 60,\n  /** Maximum callback TTL in seconds (1 year) */\n  MAX_SECONDS: DURATION_LIMITS.MAX_SECONDS,\n  /** Default callback TTL in seconds (30 days) */\n  DEFAULT_SECONDS: 30 * 24 * 60 * 60, // 2592000\n} as const;\n\n/** Retry delay limits (exponential backoff) */\nexport const RETRY_DELAY_LIMITS = {\n  /** Minimum retry delay in milliseconds */\n  MIN_MS: 1000,\n  /** Maximum retry delay in milliseconds (5 minutes) */\n  MAX_MS: 5 * 60 * 1000, // 300000\n  /** Default base retry delay in milliseconds */\n  DEFAULT_BASE_MS: 5000,\n} as const;\n\n/**\n * Clamp a numeric value to within bounds (silent, no errors).\n * Use for computed values like retry delays.\n */\nexport function clamp(value: number, min: number, max: number): number {\n  return Math.max(min, Math.min(max, value));\n}\n\n/**\n * Validate and return wait duration in seconds.\n * @param seconds - User-provided wait duration\n * @throws Error if out of bounds\n *\n * Test mode: Set ZAPIER_DURABLE_TEST_MAX_WAIT_SECONDS to cap wait durations.\n * This allows integration tests to run quickly without waiting for real timers.\n */\nexport function validateWaitSeconds(seconds: number): number {\n  if (!Number.isSafeInteger(seconds)) {\n    throw new DurableValidationError(\n      seconds,\n      `Wait duration must be a whole number of seconds, got ${seconds}`,\n    );\n  }\n  if (seconds < WAIT_LIMITS.MIN_SECONDS || seconds > WAIT_LIMITS.MAX_SECONDS) {\n    throw new DurableValidationError(\n      seconds,\n      `Wait duration must be between ${WAIT_LIMITS.MIN_SECONDS} and ${WAIT_LIMITS.MAX_SECONDS} seconds, got ${seconds}`,\n    );\n  }\n\n  // Test mode: cap wait durations for faster integration tests\n  const testMaxWait = process.env.ZAPIER_DURABLE_TEST_MAX_WAIT_SECONDS;\n  if (testMaxWait) {\n    const maxWait = parseInt(testMaxWait, 10);\n    if (!isNaN(maxWait) && maxWait > 0 && seconds > maxWait) {\n      return maxWait;\n    }\n  }\n\n  return seconds;\n}\n\n/**\n * Validate and return callback timeout in seconds.\n * @param seconds - User-provided callback TTL (undefined = use default)\n * @throws Error if explicitly provided value is out of bounds\n *\n * The undefined → DEFAULT_SECONDS fallback is only reached on the legacy\n * (wire_version 0) callback path; v1 calls this only for explicit values.\n */\nexport function validateCallbackSeconds(seconds: number | undefined): number {\n  if (seconds === undefined) {\n    return CALLBACK_LIMITS.DEFAULT_SECONDS;\n  }\n  if (seconds < CALLBACK_LIMITS.MIN_SECONDS) {\n    throw new Error(\n      `Callback timeout ${seconds}s is below minimum (${CALLBACK_LIMITS.MIN_SECONDS}s = 1 minute)`,\n    );\n  }\n  if (seconds > CALLBACK_LIMITS.MAX_SECONDS) {\n    throw new Error(\n      `Callback timeout ${seconds}s exceeds maximum (${CALLBACK_LIMITS.MAX_SECONDS}s = 1 year)`,\n    );\n  }\n  return seconds;\n}\n\n/** Absolute expires_at from a timeout offset (storage clock, mirroring the server). */\nexport function computeExpiresAt(\n  nowMs: number,\n  timeoutSeconds: number,\n): string {\n  return new Date(nowMs + timeoutSeconds * 1000).toISOString();\n}\n\n/** Absolute resume_at from a wait duration (storage clock, mirroring the server). */\nexport function computeResumeAt(\n  nowMs: number,\n  durationSeconds: number,\n): string {\n  return new Date(nowMs + durationSeconds * 1000).toISOString();\n}\n\n/**\n * Validate and return max retry attempts.\n * @param attempts - User-provided max attempts (undefined = use default)\n * @throws Error if explicitly provided value is out of bounds\n */\nexport function validateMaxAttempts(attempts: number | undefined): number {\n  if (attempts === undefined) {\n    return RETRY_LIMITS.DEFAULT_ATTEMPTS;\n  }\n  if (attempts < RETRY_LIMITS.MIN_ATTEMPTS) {\n    throw new Error(\n      `Max attempts ${attempts} is below minimum (${RETRY_LIMITS.MIN_ATTEMPTS})`,\n    );\n  }\n  if (attempts > RETRY_LIMITS.MAX_ATTEMPTS) {\n    throw new Error(\n      `Max attempts ${attempts} exceeds maximum (${RETRY_LIMITS.MAX_ATTEMPTS})`,\n    );\n  }\n  return attempts;\n}\n\n/**\n * Clamp retry delay in milliseconds (for exponential backoff).\n * Silent clamping - this is computed internally, not user-provided.\n * @param ms - Computed retry delay\n * @returns Clamped delay between 1 second and 5 minutes\n *\n * Test mode: Set ZAPIER_DURABLE_TEST_MAX_RETRY_DELAY_MS to cap retry delays.\n * This allows integration tests to run quickly without waiting for retries.\n */\nexport function clampRetryDelayMs(ms: number): number {\n  let maxMs = RETRY_DELAY_LIMITS.MAX_MS;\n\n  // Test mode: cap retry delays for faster integration tests.\n  // `..._MS` is the deprecated abbreviated env var, read as a fallback.\n  const testMaxDelay =\n    process.env.ZAPIER_DURABLE_TEST_MAX_RETRY_DELAY_MILLISECONDS ??\n    process.env.ZAPIER_DURABLE_TEST_MAX_RETRY_DELAY_MS;\n  if (testMaxDelay) {\n    const parsed = parseInt(testMaxDelay, 10);\n    if (!isNaN(parsed) && parsed > 0) {\n      maxMs = parsed;\n    }\n  }\n\n  return clamp(ms, RETRY_DELAY_LIMITS.MIN_MS, maxMs);\n}\n","/**\n * Configuration management for the Durable SDK.\n *\n * Environment variables:\n * - ZAPIER_DURABLE_ADAPTER: \"filesystem\" (default) or \"zapier\"\n * - ZAPIER_DURABLE_FS_DIR: Directory for filesystem adapter (default: ~/.config/zapier-sdk/durable)\n * - ZAPIER_DURABLE_DETERMINISM_GUARD: \"on\" (default) or \"off\"\n * - ZAPIER_DURABLE_API_URL: Base URL for the API (default: https://sdkapi.zapier.com/api/v0/sdk/code-substrate-runner)\n * - ZAPIER_DURABLE_API_JWT: JWT token for API authentication (auto-generated for localhost)\n * - ZAPIER_DURABLE_WAIT_INPROCESS_THRESHOLD_SECONDS: a ctx.wait whose time\n *   remaining at first await is at or below this sleeps in-process instead\n *   of suspending the tick (default: 0, disabled)\n * - ZAPIER_DURABLE_WAIT_INPROCESS_BUDGET_SECONDS: per-tick cap on total\n *   seconds absorbed by in-process waits (default: 120)\n */\n\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport type { Clock } from \"./context\";\nimport type { DurableClient } from \"./types\";\nimport { MemoryClient } from \"./clients/memory\";\nimport { FilesystemClient } from \"./clients/filesystem\";\nimport { RestClient } from \"./clients/rest\";\n\n/**\n * Get the default durable state directory.\n * Uses ~/.config/zapier-sdk/durable on all platforms.\n */\nfunction getDefaultFsDir(): string {\n  return path.join(os.homedir(), \".config\", \"zapier-sdk\", \"durable\");\n}\n\nexport type AdapterType = \"filesystem\" | \"zapier\" | \"memory\";\n\nexport interface DurableConfig {\n  /** Adapter type: \"filesystem\", \"zapier\", or \"memory\" */\n  adapter: AdapterType;\n  /** Directory for filesystem adapter */\n  fsDir: string;\n  /** Enable determinism guard */\n  guardEnabled: boolean;\n  /** Base URL for Zapier API */\n  apiUrl: string;\n  /** JWT token for Zapier API */\n  apiToken?: string;\n  /** Enable debug logging */\n  logging: boolean;\n  /**\n   * A wait is always journaled pending at the call. If the time remaining\n   * until resume_at is at or below this threshold when the wait is first\n   * awaited, it sleeps out the remainder in-process and journals completed\n   * instead of suspending. 0 disables in-process waits (the default).\n   */\n  waitInProcessThresholdSeconds: number;\n  /**\n   * Per-tick cap on total seconds absorbed by in-process waits. Once a\n   * tick's cumulative in-process sleep would exceed this, further waits\n   * fall back to the checkpoint-and-suspend path even if under threshold.\n   */\n  waitInProcessBudgetSeconds: number;\n}\n\n// Global config singleton\nlet globalConfig: DurableConfig | null = null;\n\n/**\n * Get configuration from environment variables.\n */\nfunction getConfigFromEnv(): DurableConfig {\n  const adapter = (process.env.ZAPIER_DURABLE_ADAPTER ??\n    \"filesystem\") as AdapterType;\n  const fsDir = process.env.ZAPIER_DURABLE_FS_DIR ?? getDefaultFsDir();\n  const guardEnabled = process.env.ZAPIER_DURABLE_DETERMINISM_GUARD !== \"off\";\n  const apiUrl =\n    process.env.ZAPIER_DURABLE_API_URL ??\n    \"https://sdkapi.zapier.com/api/v0/sdk/code-substrate-runner\";\n  // New name: ZAPIER_DURABLE_API_JWT, old name kept for backwards compat\n  const apiToken =\n    process.env.ZAPIER_DURABLE_API_JWT ?? process.env.ZAPIER_DURABLE_API_TOKEN;\n  const logging = process.env.ZAPIER_DURABLE_DEBUG === \"true\";\n\n  const parsedThreshold = parseInt(\n    process.env.ZAPIER_DURABLE_WAIT_INPROCESS_THRESHOLD_SECONDS ?? \"\",\n    10,\n  );\n  const waitInProcessThresholdSeconds =\n    Number.isFinite(parsedThreshold) && parsedThreshold >= 1\n      ? parsedThreshold\n      : 0;\n\n  const parsedBudget = parseInt(\n    process.env.ZAPIER_DURABLE_WAIT_INPROCESS_BUDGET_SECONDS ?? \"\",\n    10,\n  );\n  const waitInProcessBudgetSeconds =\n    Number.isFinite(parsedBudget) && parsedBudget >= 1 ? parsedBudget : 120;\n\n  return {\n    adapter,\n    fsDir,\n    guardEnabled,\n    apiUrl,\n    apiToken,\n    logging,\n    waitInProcessThresholdSeconds,\n    waitInProcessBudgetSeconds,\n  };\n}\n\n/**\n * Get current configuration. If not explicitly set, reads from environment.\n */\nexport function getConfig(): DurableConfig {\n  if (!globalConfig) {\n    globalConfig = getConfigFromEnv();\n  }\n  return globalConfig;\n}\n\n/**\n * Set global configuration. Call this at startup if you need custom config.\n */\nexport function configureDurable(\n  config: Partial<DurableConfig>,\n): DurableConfig {\n  const defaults = getConfigFromEnv();\n  globalConfig = {\n    ...defaults,\n    ...config,\n  };\n  return globalConfig;\n}\n\n/**\n * Reset configuration to defaults (mainly for testing).\n */\nexport function resetConfig(): void {\n  globalConfig = null;\n}\n\n/**\n * Create a DurableClient based on current configuration.\n */\nexport function createClient(\n  configOverrides?: Partial<DurableConfig>,\n  clientOptions?: {\n    /** Client-side clock injection is intended for local adapters (memory,\n     *  filesystem) and tests; pass the same instance to runTick /\n     *  DurableCallOptions for deterministic timing. The zapier adapter does\n     *  not receive it. */\n    clock?: Clock;\n  },\n): DurableClient {\n  const config = configOverrides\n    ? { ...getConfig(), ...configOverrides }\n    : getConfig();\n\n  switch (config.adapter) {\n    case \"memory\":\n      const memClient = new MemoryClient({ clock: clientOptions?.clock });\n      memClient.setLogging(config.logging);\n      return memClient;\n\n    case \"filesystem\":\n      const fsClient = new FilesystemClient({\n        baseDir: config.fsDir,\n        logging: config.logging,\n        clock: clientOptions?.clock,\n      });\n      return fsClient;\n\n    case \"zapier\":\n      return new RestClient({\n        baseUrl: config.apiUrl,\n        token: config.apiToken,\n        logging: config.logging,\n      });\n\n    default:\n      throw new Error(`Unknown adapter type: ${config.adapter}`);\n  }\n}\n","/**\n * In-memory DurableClient implementation for testing.\n */\n\nimport Ajv from \"ajv\";\nimport { type Clock, defaultClock } from \"../context\";\nimport { SDK_WIRE_VERSION_MAX } from \"../wire-version\";\nimport { CallbackConflictError, CallbackExpiredError } from \"../errors\";\nimport {\n  applyCheckpointUpdate,\n  classifyDelivery,\n  resolveDeadlineFields,\n  resolveResumeAt,\n  settleElapsedDeadlines,\n} from \"./shared\";\nimport type {\n  DurableClient,\n  CreateExecutionRequest,\n  CreateExecutionResponse,\n  CheckoutRequest,\n  CheckoutResponse,\n  CheckpointRequest,\n  CheckpointResponse,\n  ReleaseRequest,\n  ReleaseResponse,\n  CallbackRequest,\n  CallbackResponse,\n  Execution,\n  Operation,\n} from \"../types\";\n\n// Ajv instance for JSON Schema validation\nconst AjvClass = (Ajv as unknown as { default?: typeof Ajv }).default || Ajv;\nconst ajv = new AjvClass({ allErrors: true });\n\nfunction generateUuidV7(): string {\n  const timestamp = Date.now();\n  const timestampHex = timestamp.toString(16).padStart(12, \"0\");\n  const randomPart = Math.random().toString(16).slice(2, 14).padStart(12, \"0\");\n  const randomPart2 = Math.random().toString(16).slice(2, 6).padStart(4, \"0\");\n  return `${timestampHex.slice(0, 8)}-${timestampHex.slice(8, 12)}-7${randomPart.slice(0, 3)}-${randomPart2}-${randomPart.slice(3, 15)}`;\n}\n\nexport class MemoryClient implements DurableClient {\n  readonly callbackBaseUrl = \"memory://callbacks\";\n\n  private executions = new Map<string, Execution>();\n  private operations = new Map<string, Operation[]>();\n  /** `inbox\\0idempotency_key` -> execution id, for ensure-by-key creates. */\n  private ensured = new Map<string, string>();\n  private callbackIndex = new Map<\n    string,\n    { executionId: string; name: string }\n  >();\n  private logging = false;\n  private clock: Clock;\n  private wireVersion: number;\n\n  constructor(options?: {\n    /** Clock used for wait auto-completion at checkout and for callback\n     *  expiry / completed_at. When using a mock clock in tests, pass the\n     *  same instance to runTick(). */\n    clock?: Clock;\n    wireVersion?: number;\n  }) {\n    this.clock = options?.clock ?? defaultClock;\n    this.wireVersion = options?.wireVersion ?? SDK_WIRE_VERSION_MAX;\n  }\n\n  setLogging(enabled: boolean): void {\n    this.logging = enabled;\n  }\n\n  private log(msg: string): void {\n    if (this.logging) {\n      console.log(`  [memory-client] ${msg}`);\n    }\n  }\n\n  async create(req: CreateExecutionRequest): Promise<CreateExecutionResponse> {\n    // An inbox plus an idempotency key makes create an ensure: the pair maps to\n    // at most one execution, so a replayed event resumes the original instead of\n    // forking a second one. Either half alone does not dedupe.\n    const ensureKey =\n      req.inbox && req.idempotency_key\n        ? `${req.inbox}\\u0000${req.idempotency_key}`\n        : null;\n    const ensured = ensureKey ? this.ensured.get(ensureKey) : undefined;\n    if (ensured) {\n      const existing = this.executions.get(ensured)!;\n      this.log(`create: ${ensured} (ensure matched)`);\n      return {\n        id: existing.id,\n        name: existing.name,\n        status: existing.status,\n        inbox: req.inbox,\n        idempotency_key: req.idempotency_key,\n        created_at: existing.created_at,\n      };\n    }\n\n    const id = generateUuidV7();\n    const execution: Execution = {\n      id,\n      name: req.name,\n      status: \"running\",\n      input: req.input,\n      metadata: req.metadata,\n      wire_version: this.wireVersion,\n      created_at: new Date().toISOString(),\n    };\n    this.executions.set(id, execution);\n    this.operations.set(id, []);\n    if (ensureKey) this.ensured.set(ensureKey, id);\n    this.log(`create: ${id}`);\n    return {\n      id,\n      name: req.name,\n      status: \"running\",\n      inbox: req.inbox,\n      idempotency_key: req.idempotency_key,\n      created_at: execution.created_at,\n    };\n  }\n\n  async checkout(\n    executionId: string,\n    req?: CheckoutRequest,\n  ): Promise<CheckoutResponse> {\n    const execution = this.executions.get(executionId);\n    if (!execution) {\n      return { leased: false };\n    }\n\n    // Simple lease - always grant in memory mode\n    const leaseToken = generateUuidV7();\n    execution.lease_token = leaseToken;\n    execution.lease_expires_at = new Date(\n      Date.now() + 15 * 60 * 1000,\n    ).toISOString();\n\n    if (req?.resume_url) {\n      execution.resume_url = req.resume_url;\n    }\n    if (req?.resume_url_delivery_state) {\n      execution.resume_url_delivery_state = req.resume_url_delivery_state;\n    }\n\n    const ops = this.operations.get(executionId) ?? [];\n\n    // Auto-complete elapsed pending waits (mirrors server behaviour).\n    const now = this.clock.now();\n    for (const op of ops) {\n      if (\n        op.type === \"wait\" &&\n        op.status === \"pending\" &&\n        op.resume_at &&\n        new Date(op.resume_at).getTime() <= now\n      ) {\n        op.status = \"completed\";\n        op.completed_at = op.resume_at;\n      }\n    }\n\n    // Mirrors server behaviour.\n    settleElapsedDeadlines(ops, now);\n\n    this.log(`checkout: ${executionId}, ${ops.length} operations`);\n\n    return {\n      leased: true,\n      lease_token: leaseToken,\n      execution,\n      operations: ops,\n    };\n  }\n\n  async checkpoint(\n    executionId: string,\n    req: CheckpointRequest,\n  ): Promise<CheckpointResponse> {\n    const ops = this.operations.get(executionId) ?? [];\n    const existing = ops.find((op) => op.name === req.operation.name);\n\n    let op: Operation;\n\n    if (existing) {\n      // Update existing (see shared.ts applyCheckpointUpdate).\n      applyCheckpointUpdate(existing, req.operation);\n      op = existing;\n      this.log(\n        `checkpoint (update): ${req.operation.name} -> ${existing.status}`,\n      );\n    } else {\n      // Insert new - generate callback_token server-side for callback ops\n      // Local adapters use simple hex tokens (no version byte)\n      const callbackToken =\n        req.operation.type === \"callback\"\n          ? generateUuidV7().replace(/-/g, \"\").slice(0, 22)\n          : undefined;\n\n      const nowMs = this.clock.now();\n      const deadline = resolveDeadlineFields(req.operation, nowMs);\n\n      op = {\n        id: generateUuidV7(),\n        execution_id: executionId,\n        name: req.operation.name,\n        type: req.operation.type,\n        status: req.operation.status,\n        result: req.operation.result,\n        error: req.operation.error,\n        retry_count: req.operation.retry_count ?? 0,\n        max_attempts: req.operation.max_attempts,\n        next_retry_at: req.operation.next_retry_at,\n        resume_at: resolveResumeAt(req.operation, nowMs),\n        callback_token: callbackToken,\n        payload_schema: req.operation.payload_schema,\n        expires_at: deadline.expires_at,\n        timeout_seconds: deadline.timeout_seconds,\n        created_at: new Date().toISOString(),\n      };\n      ops.push(op);\n      this.operations.set(executionId, ops);\n      this.log(\n        `checkpoint (insert): ${req.operation.name} -> ${req.operation.status}`,\n      );\n\n      // Index callback token\n      if (op.callback_token) {\n        this.callbackIndex.set(op.callback_token, {\n          executionId,\n          name: op.name,\n        });\n      }\n    }\n\n    return { ok: true, operation: op };\n  }\n\n  async release(\n    executionId: string,\n    req: ReleaseRequest,\n  ): Promise<ReleaseResponse> {\n    const execution = this.executions.get(executionId);\n    if (execution) {\n      execution.status = req.status;\n      execution.output = req.output;\n      execution.error = req.error;\n      execution.lease_token = undefined;\n      execution.lease_expires_at = undefined;\n    }\n\n    const done = req.status === \"completed\" || req.status === \"failed\";\n    this.log(`release: ${executionId} -> ${req.status}, done=${done}`);\n    return { ok: true, done };\n  }\n\n  async callback(\n    token: string,\n    req: CallbackRequest,\n  ): Promise<CallbackResponse> {\n    const index = this.callbackIndex.get(token);\n    if (!index) {\n      return { error: \"not_found\" };\n    }\n\n    const ops = this.operations.get(index.executionId) ?? [];\n    const op = ops.find((o) => o.name === index.name);\n    if (!op) {\n      return { error: \"not_found\" };\n    }\n\n    // Deadline classification happens before payload validation (mirrors\n    // the server: expiry is decided from ingress time, and dead-callback\n    // paths never compile attacker-controllable schemas).\n    const verdict = classifyDelivery(op, this.clock.now());\n    if (verdict === \"refuse_settled\") {\n      throw new CallbackConflictError(token);\n    }\n    if (verdict === \"expire_and_refuse\") {\n      // Decided-once: journal the verdict before refusing (see classifyDelivery)\n      op.status = \"expired\";\n      this.log(`callback expired on late delivery: ${token} -> ${index.name}`);\n      throw new CallbackExpiredError(token);\n    }\n    if (verdict === \"refuse_expired\") {\n      throw new CallbackExpiredError(token);\n    }\n\n    // Validate payload against schema (if present) - matches API behavior\n    // req IS the payload (no wrapper) - third-party systems send raw payloads\n    if (op.payload_schema) {\n      const validate = ajv.compile(op.payload_schema as object);\n      if (!validate(req)) {\n        return { error: \"validation_failed\", details: validate.errors ?? [] };\n      }\n    }\n\n    op.status = \"completed\";\n    op.payload = req;\n    op.completed_at = new Date(this.clock.now()).toISOString(); // For race disambiguation\n    this.log(`callback delivered: ${token} -> ${index.name}`);\n\n    return { ok: true };\n  }\n\n  // Test helpers\n  getExecution(id: string): Execution | undefined {\n    return this.executions.get(id);\n  }\n\n  getOperations(executionId: string): Operation[] {\n    return this.operations.get(executionId) ?? [];\n  }\n\n  // Simulate callback delivery for testing (payload IS the body, no wrapper)\n  async deliverCallback(token: string, payload: unknown): Promise<boolean> {\n    try {\n      const result = await this.callback(token, payload);\n      return \"ok\" in result;\n    } catch (err) {\n      if (\n        err instanceof CallbackExpiredError ||\n        err instanceof CallbackConflictError\n      ) {\n        return false;\n      }\n      throw err;\n    }\n  }\n}\n","/**\n * Execution wire versioning.\n *\n * `executions.wire_version` is stamped once by the server as\n * min(server_current, sdk_declared_max) at the execution's first checkout\n * (before any operations exist) and echoed on every checkout thereafter.\n * The SDK dispatches callback-resolution behavior on it: v0 replays the\n * legacy behavior byte-identically; v1 resolves callbacks created with\n * `timeoutSeconds` to a CallbackResult.\n *\n * The server rejects a checkout with 426 wire-version-mismatch when an\n * SDK declares a lower max than the execution's stamped version — that\n * direction is unrecoverable (the SDK cannot know how to replay a newer\n * wire version). The opposite direction is safe: a newer SDK replays older\n * executions under their stamped version.\n *\n * Bump criterion: bump only when an execution created yesterday would\n * observe a different value at the same await under the new code.\n * Wire-protocol additions and new columns don't bump; the CallbackResult\n * wrapper does.\n */\n\n/** Highest execution wire version this SDK understands. */\nexport const SDK_WIRE_VERSION_MAX = 1;\n\n/**\n * Dedicated header the SDK uses to advertise its max wire version.\n * It rides every request, but the server reads it only at an execution's\n * first checkout, where it negotiates min(server_max, advertised) and\n * stamps `executions.wire_version` once. A later checkout by an SDK whose\n * max is below the stamped version gets a 426 wire-version-mismatch.\n */\nexport const WIRE_VERSION_HEADER = \"x-zapier-durable-wire-version\";\n","// Deadline state machine shared by the in-process clients; mirrors the server.\n\nimport type { CheckpointRequest, Operation } from \"../types\";\nimport { computeExpiresAt, computeResumeAt } from \"../limits\";\n\nfunction hasCallbackDeadline(op: Operation): boolean {\n  return op.type === \"callback\" && op.timeout_seconds != null;\n}\n\nfunction deadlinePassed(op: Operation, nowMs: number): boolean {\n  return (\n    op.expires_at !== undefined && new Date(op.expires_at).getTime() <= nowMs\n  );\n}\n\nexport function settleElapsedDeadlines(\n  ops: Operation[],\n  nowMs: number,\n): boolean {\n  let changed = false;\n  for (const op of ops) {\n    if (\n      hasCallbackDeadline(op) &&\n      op.status === \"pending\" &&\n      deadlinePassed(op, nowMs)\n    ) {\n      op.status = \"expired\";\n      changed = true;\n    }\n  }\n  return changed;\n}\n\nexport type DeliveryVerdict =\n  | \"accept\"\n  | \"expire_and_refuse\"\n  | \"refuse_expired\"\n  | \"refuse_settled\";\n\nexport function classifyDelivery(\n  op: Operation,\n  nowMs: number,\n): DeliveryVerdict {\n  if (op.status === \"expired\") {\n    return \"refuse_expired\";\n  }\n  if (op.status !== \"pending\") {\n    return \"refuse_settled\";\n  }\n  if (deadlinePassed(op, nowMs)) {\n    return hasCallbackDeadline(op) ? \"expire_and_refuse\" : \"refuse_expired\";\n  }\n  return \"accept\";\n}\n\nexport function resolveResumeAt(\n  op: CheckpointRequest[\"operation\"],\n  nowMs: number,\n): string | undefined {\n  if (op.type === \"wait\" && op.duration_seconds !== undefined) {\n    return computeResumeAt(nowMs, op.duration_seconds);\n  }\n  return op.resume_at;\n}\n\nexport function resolveDeadlineFields(\n  op: CheckpointRequest[\"operation\"],\n  nowMs: number,\n): Pick<Operation, \"expires_at\" | \"timeout_seconds\"> {\n  if (op.type !== \"callback\") {\n    return { expires_at: op.expires_at, timeout_seconds: undefined };\n  }\n  if (op.timeout_seconds !== undefined) {\n    return {\n      expires_at: computeExpiresAt(nowMs, op.timeout_seconds),\n      timeout_seconds: op.timeout_seconds,\n    };\n  }\n  // No-timeout callback: never synthesize a deadline — it must stay pending\n  // indefinitely. The expires_at passthrough is load-bearing: it preserves a\n  // real legacy v0 expires_at (client-stamped on the v0 path) so v0 journals\n  // replay byte-identically.\n  return {\n    expires_at: op.expires_at,\n    timeout_seconds: null,\n  };\n}\n\nexport function applyCheckpointUpdate(\n  existing: Operation,\n  update: CheckpointRequest[\"operation\"],\n): void {\n  const settledCallback =\n    existing.type === \"callback\" &&\n    (existing.status === \"completed\" || existing.status === \"expired\");\n\n  // Assign deadline fields unconditionally — null ?? x would flip a no-timeout callback into one with a deadline.\n  Object.assign(existing, update, {\n    callback_token: existing.callback_token,\n    status: settledCallback ? existing.status : update.status,\n    expires_at: existing.expires_at,\n    timeout_seconds: existing.timeout_seconds,\n  });\n}\n","/**\n * Filesystem-based DurableClient implementation for local development and CLI.\n *\n * Storage structure:\n * .zapier-durable/\n *   executions/\n *     {execution_id}/\n *       execution.json\n *       operations.json\n *   callbacks/\n *     {callback_token}.json\n */\n\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport Ajv from \"ajv\";\nimport { type Clock, defaultClock } from \"../context\";\nimport { SDK_WIRE_VERSION_MAX } from \"../wire-version\";\nimport { CallbackConflictError, CallbackExpiredError } from \"../errors\";\nimport {\n  applyCheckpointUpdate,\n  classifyDelivery,\n  resolveDeadlineFields,\n  resolveResumeAt,\n  settleElapsedDeadlines,\n} from \"./shared\";\nimport type {\n  DurableClient,\n  CreateExecutionRequest,\n  CreateExecutionResponse,\n  CheckoutRequest,\n  CheckoutResponse,\n  CheckpointRequest,\n  CheckpointResponse,\n  ReleaseRequest,\n  ReleaseResponse,\n  CallbackRequest,\n  CallbackResponse,\n  Execution,\n  Operation,\n} from \"../types\";\n\n// Ajv instance for JSON Schema validation\nconst AjvClass = (Ajv as unknown as { default?: typeof Ajv }).default || Ajv;\nconst ajv = new AjvClass({ allErrors: true });\n\nfunction generateUuidV7(): string {\n  const timestamp = Date.now();\n  const timestampHex = timestamp.toString(16).padStart(12, \"0\");\n  const randomPart = Math.random().toString(16).slice(2, 14).padStart(12, \"0\");\n  const randomPart2 = Math.random().toString(16).slice(2, 6).padStart(4, \"0\");\n  return `${timestampHex.slice(0, 8)}-${timestampHex.slice(8, 12)}-7${randomPart.slice(0, 3)}-${randomPart2}-${randomPart.slice(3, 15)}`;\n}\n\nexport interface FilesystemClientOptions {\n  /** Base directory for storage (default: .zapier-durable) */\n  baseDir?: string;\n  /** Enable debug logging */\n  logging?: boolean;\n  /** Clock used for wait auto-completion at checkout and for callback\n   *  expiry / completed_at. When using a mock clock in tests, pass the\n   *  same instance to runTick(). */\n  clock?: Clock;\n  wireVersion?: number;\n}\n\ninterface StoredExecution extends Execution {\n  inbox?: string;\n  idempotency_key?: string;\n}\n\nexport class FilesystemClient implements DurableClient {\n  private baseDir: string;\n  private logging: boolean;\n  private clock: Clock;\n  private wireVersion: number;\n\n  /**\n   * Base URL for constructing callback URLs.\n   * For filesystem client, uses file:// protocol.\n   */\n  get callbackBaseUrl(): string {\n    return `file://${path.resolve(this.baseDir, \"callbacks\")}`;\n  }\n\n  constructor(options: FilesystemClientOptions = {}) {\n    this.baseDir = options.baseDir ?? \".zapier-durable\";\n    this.logging = options.logging ?? false;\n    this.clock = options.clock ?? defaultClock;\n    this.wireVersion = options.wireVersion ?? SDK_WIRE_VERSION_MAX;\n    this.ensureDirectories();\n  }\n\n  setLogging(enabled: boolean): void {\n    this.logging = enabled;\n  }\n\n  private log(msg: string): void {\n    if (this.logging) {\n      console.log(`  [fs-client] ${msg}`);\n    }\n  }\n\n  private ensureDirectories(): void {\n    const dirs = [\n      this.baseDir,\n      path.join(this.baseDir, \"executions\"),\n      path.join(this.baseDir, \"callbacks\"),\n    ];\n    for (const dir of dirs) {\n      if (!fs.existsSync(dir)) {\n        fs.mkdirSync(dir, { recursive: true });\n      }\n    }\n  }\n\n  private executionDir(executionId: string): string {\n    return path.join(this.baseDir, \"executions\", executionId);\n  }\n\n  private executionFile(executionId: string): string {\n    return path.join(this.executionDir(executionId), \"execution.json\");\n  }\n\n  private operationsFile(executionId: string): string {\n    return path.join(this.executionDir(executionId), \"operations.json\");\n  }\n\n  private callbackFile(token: string): string {\n    return path.join(this.baseDir, \"callbacks\", `${token}.json`);\n  }\n\n  private readExecution(executionId: string): StoredExecution | null {\n    const file = this.executionFile(executionId);\n    if (!fs.existsSync(file)) {\n      return null;\n    }\n    return JSON.parse(fs.readFileSync(file, \"utf-8\"));\n  }\n\n  private writeExecution(execution: StoredExecution): void {\n    const dir = this.executionDir(execution.id);\n    if (!fs.existsSync(dir)) {\n      fs.mkdirSync(dir, { recursive: true });\n    }\n    fs.writeFileSync(\n      this.executionFile(execution.id),\n      JSON.stringify(execution, null, 2),\n    );\n  }\n\n  private readOperations(executionId: string): Operation[] {\n    const file = this.operationsFile(executionId);\n    if (!fs.existsSync(file)) {\n      return [];\n    }\n    return JSON.parse(fs.readFileSync(file, \"utf-8\"));\n  }\n\n  private writeOperations(executionId: string, operations: Operation[]): void {\n    const dir = this.executionDir(executionId);\n    if (!fs.existsSync(dir)) {\n      fs.mkdirSync(dir, { recursive: true });\n    }\n    fs.writeFileSync(\n      this.operationsFile(executionId),\n      JSON.stringify(operations, null, 2),\n    );\n  }\n\n  private readCallback(\n    token: string,\n  ): { executionId: string; name: string } | null {\n    const file = this.callbackFile(token);\n    if (!fs.existsSync(file)) {\n      return null;\n    }\n    return JSON.parse(fs.readFileSync(file, \"utf-8\"));\n  }\n\n  private writeCallback(\n    token: string,\n    data: { executionId: string; name: string },\n  ): void {\n    fs.writeFileSync(this.callbackFile(token), JSON.stringify(data, null, 2));\n  }\n\n  async create(req: CreateExecutionRequest): Promise<CreateExecutionResponse> {\n    if (req.inbox && req.idempotency_key) {\n      for (const executionId of this.listExecutions()) {\n        const existing = this.readExecution(executionId);\n        if (\n          existing?.inbox === req.inbox &&\n          existing.idempotency_key === req.idempotency_key\n        ) {\n          this.log(`create: ${executionId} (ensure matched)`);\n          return {\n            id: existing.id,\n            name: existing.name,\n            status: existing.status,\n            inbox: existing.inbox,\n            idempotency_key: existing.idempotency_key,\n            created_at: existing.created_at,\n          };\n        }\n      }\n    }\n\n    const id = generateUuidV7();\n    const execution: StoredExecution = {\n      id,\n      name: req.name,\n      status: \"running\",\n      input: req.input,\n      metadata: req.metadata,\n      inbox: req.inbox,\n      idempotency_key: req.idempotency_key,\n      wire_version: this.wireVersion,\n      created_at: new Date().toISOString(),\n    };\n\n    this.writeExecution(execution);\n    this.writeOperations(id, []);\n    this.log(`create: ${id}`);\n\n    return {\n      id,\n      name: req.name,\n      status: \"running\",\n      inbox: req.inbox,\n      idempotency_key: req.idempotency_key,\n      created_at: execution.created_at,\n    };\n  }\n\n  async checkout(\n    executionId: string,\n    req?: CheckoutRequest,\n  ): Promise<CheckoutResponse> {\n    const execution = this.readExecution(executionId);\n    if (!execution) {\n      return { leased: false };\n    }\n\n    // Simple lease - always grant in filesystem mode\n    const leaseToken = generateUuidV7();\n    execution.lease_token = leaseToken;\n    execution.lease_expires_at = new Date(\n      Date.now() + 15 * 60 * 1000,\n    ).toISOString();\n\n    if (req?.resume_url) {\n      execution.resume_url = req.resume_url;\n    }\n    if (req?.resume_url_delivery_state) {\n      execution.resume_url_delivery_state = req.resume_url_delivery_state;\n    }\n\n    this.writeExecution(execution);\n\n    const ops = this.readOperations(executionId);\n\n    // Auto-complete elapsed pending waits (mirrors server behaviour).\n    const now = this.clock.now();\n    let opsChanged = false;\n    for (const op of ops) {\n      if (\n        op.type === \"wait\" &&\n        op.status === \"pending\" &&\n        op.resume_at &&\n        new Date(op.resume_at).getTime() <= now\n      ) {\n        op.status = \"completed\";\n        op.completed_at = op.resume_at;\n        opsChanged = true;\n      }\n    }\n\n    // Mirrors server behaviour.\n    if (settleElapsedDeadlines(ops, now)) {\n      opsChanged = true;\n    }\n\n    if (opsChanged) {\n      this.writeOperations(executionId, ops);\n    }\n\n    this.log(`checkout: ${executionId}, ${ops.length} operations`);\n\n    return {\n      leased: true,\n      lease_token: leaseToken,\n      execution,\n      operations: ops,\n    };\n  }\n\n  async checkpoint(\n    executionId: string,\n    req: CheckpointRequest,\n  ): Promise<CheckpointResponse> {\n    const ops = this.readOperations(executionId);\n    const existingIndex = ops.findIndex((op) => op.name === req.operation.name);\n\n    let op: Operation;\n\n    if (existingIndex >= 0) {\n      // Update existing (see shared.ts applyCheckpointUpdate).\n      const existing = ops[existingIndex];\n      applyCheckpointUpdate(existing, req.operation);\n      op = existing;\n      this.log(\n        `checkpoint (update): ${req.operation.name} -> ${existing.status}`,\n      );\n    } else {\n      // Insert new - generate callback_token server-side for callback ops\n      // Local adapters use simple hex tokens (no version byte)\n      const callbackToken =\n        req.operation.type === \"callback\"\n          ? generateUuidV7().replace(/-/g, \"\").slice(0, 22)\n          : undefined;\n\n      const nowMs = this.clock.now();\n      const deadline = resolveDeadlineFields(req.operation, nowMs);\n\n      op = {\n        id: generateUuidV7(),\n        execution_id: executionId,\n        name: req.operation.name,\n        type: req.operation.type,\n        status: req.operation.status,\n        result: req.operation.result,\n        error: req.operation.error,\n        retry_count: req.operation.retry_count ?? 0,\n        max_attempts: req.operation.max_attempts,\n        next_retry_at: req.operation.next_retry_at,\n        resume_at: resolveResumeAt(req.operation, nowMs),\n        callback_token: callbackToken,\n        payload_schema: req.operation.payload_schema,\n        expires_at: deadline.expires_at,\n        timeout_seconds: deadline.timeout_seconds,\n        created_at: new Date().toISOString(),\n      };\n      ops.push(op);\n      this.log(\n        `checkpoint (insert): ${req.operation.name} -> ${req.operation.status}`,\n      );\n\n      // Index callback token\n      if (op.callback_token) {\n        this.writeCallback(op.callback_token, { executionId, name: op.name });\n      }\n    }\n\n    this.writeOperations(executionId, ops);\n    return { ok: true, operation: op };\n  }\n\n  async release(\n    executionId: string,\n    req: ReleaseRequest,\n  ): Promise<ReleaseResponse> {\n    const execution = this.readExecution(executionId);\n    if (execution) {\n      execution.status = req.status;\n      execution.output = req.output;\n      execution.error = req.error;\n      execution.lease_token = undefined;\n      execution.lease_expires_at = undefined;\n      this.writeExecution(execution);\n    }\n\n    const done = req.status === \"completed\" || req.status === \"failed\";\n    this.log(`release: ${executionId} -> ${req.status}, done=${done}`);\n    return { ok: true, done };\n  }\n\n  async callback(\n    token: string,\n    req: CallbackRequest,\n  ): Promise<CallbackResponse> {\n    const index = this.readCallback(token);\n    if (!index) {\n      return { error: \"not_found\" };\n    }\n\n    const ops = this.readOperations(index.executionId);\n    const op = ops.find((o) => o.name === index.name);\n    if (!op) {\n      return { error: \"not_found\" };\n    }\n\n    // Deadline classification happens before payload validation (mirrors\n    // the server: expiry is decided from ingress time, and dead-callback\n    // paths never compile attacker-controllable schemas).\n    const verdict = classifyDelivery(op, this.clock.now());\n    if (verdict === \"refuse_settled\") {\n      throw new CallbackConflictError(token);\n    }\n    if (verdict === \"expire_and_refuse\") {\n      // Decided-once: journal the verdict before refusing (see classifyDelivery)\n      op.status = \"expired\";\n      this.writeOperations(index.executionId, ops);\n      this.log(`callback expired on late delivery: ${token} -> ${index.name}`);\n      throw new CallbackExpiredError(token);\n    }\n    if (verdict === \"refuse_expired\") {\n      throw new CallbackExpiredError(token);\n    }\n\n    // Validate payload against schema (if present) - matches API behavior\n    // req IS the payload (no wrapper) - third-party systems send raw payloads\n    if (op.payload_schema) {\n      const validate = ajv.compile(op.payload_schema as object);\n      if (!validate(req)) {\n        return { error: \"validation_failed\", details: validate.errors ?? [] };\n      }\n    }\n\n    op.status = \"completed\";\n    op.payload = req;\n    op.completed_at = new Date(this.clock.now()).toISOString(); // For race disambiguation\n    this.writeOperations(index.executionId, ops);\n    this.log(`callback delivered: ${token} -> ${index.name}`);\n\n    return { ok: true };\n  }\n\n  // Helper methods for CLI\n\n  /**\n   * Get an execution by ID. Returns null if not found.\n   */\n  getExecution(executionId: string): Execution | null {\n    return this.readExecution(executionId);\n  }\n\n  /**\n   * Get all operations for an execution.\n   */\n  getOperations(executionId: string): Operation[] {\n    return this.readOperations(executionId);\n  }\n\n  /**\n   * List all execution IDs in the store.\n   */\n  listExecutions(): string[] {\n    const dir = path.join(this.baseDir, \"executions\");\n    if (!fs.existsSync(dir)) {\n      return [];\n    }\n    return fs.readdirSync(dir).filter((name) => {\n      const stat = fs.statSync(path.join(dir, name));\n      return stat.isDirectory();\n    });\n  }\n\n  /**\n   * Delete an execution and its operations.\n   */\n  deleteExecution(executionId: string): boolean {\n    const dir = this.executionDir(executionId);\n    if (!fs.existsSync(dir)) {\n      return false;\n    }\n    fs.rmSync(dir, { recursive: true });\n    return true;\n  }\n\n  /**\n   * Clean up all data (useful for tests).\n   */\n  clear(): void {\n    if (fs.existsSync(this.baseDir)) {\n      fs.rmSync(this.baseDir, { recursive: true });\n    }\n    this.ensureDirectories();\n  }\n}\n","/**\n * REST API DurableClient implementation for production use.\n *\n * Communicates with the Zapier-hosted durable execution backend.\n * Uses openapi-fetch for type-safe API requests.\n */\n\nimport createClientModule from \"openapi-fetch\";\nimport type {\n  DurableClient,\n  CreateExecutionRequest,\n  CreateExecutionResponse,\n  CheckoutRequest,\n  CheckoutResponse,\n  CheckpointRequest,\n  CheckpointResponse,\n  DeferredFieldsResponse,\n  ReleaseRequest,\n  ReleaseResponse,\n  CallbackRequest,\n  CallbackResponse,\n} from \"../types\";\nimport {\n  CAPABILITY_HEADER,\n  CapabilityPresignedV1,\n} from \"../externalization/constants\";\nimport { SDK_WIRE_VERSION_MAX, WIRE_VERSION_HEADER } from \"../wire-version\";\nimport {\n  CallbackConflictError,\n  CallbackExpiredError,\n  ExecutionTerminalError,\n  IdempotencyConflictError,\n  LeaseConflictError,\n  RequestOutcomeUnknownError,\n  ResultNotFoundError,\n  WireVersionMismatchError,\n} from \"../errors\";\n\n// openapi-fetch is external in the tsup build, and its CJS entry exposes the\n// client factory on `exports.default`. esbuild's node-mode interop therefore\n// hands the CJS build the whole exports object instead of the factory, so\n// unwrap `.default` when present. The ESM build binds the real default\n// export, making the fallback a no-op there.\nconst createClient =\n  (createClientModule as unknown as { default?: typeof createClientModule })\n    .default ?? createClientModule;\n\ninterface ApiPaths {\n  \"/api/v0/executions\": {\n    post: {\n      requestBody: { content: { \"application/json\": CreateExecutionRequest } };\n      responses: {\n        201: { content: { \"application/json\": CreateExecutionResponse } };\n      };\n    };\n  };\n  \"/api/v0/executions/{id}/checkout\": {\n    post: {\n      parameters: { path: { id: string } };\n      requestBody?: { content: { \"application/json\": CheckoutRequest } };\n      responses: {\n        200: { content: { \"application/json\": CheckoutResponse } };\n      };\n    };\n  };\n  \"/api/v0/executions/{id}/checkpoint\": {\n    post: {\n      parameters: { path: { id: string } };\n      requestBody: { content: { \"application/json\": CheckpointRequest } };\n      responses: {\n        200: { content: { \"application/json\": CheckpointResponse } };\n      };\n    };\n  };\n  \"/api/v0/executions/{id}/release\": {\n    post: {\n      parameters: { path: { id: string } };\n      requestBody: { content: { \"application/json\": ReleaseRequest } };\n      responses: {\n        200: { content: { \"application/json\": ReleaseResponse } };\n      };\n    };\n  };\n  \"/api/v0/callbacks/{token}\": {\n    post: {\n      parameters: { path: { token: string } };\n      requestBody: { content: { \"application/json\": CallbackRequest } };\n      responses: {\n        200: { content: { \"application/json\": CallbackResponse } };\n      };\n    };\n  };\n  \"/api/v0/executions/{id}/fetch_deferred\": {\n    post: {\n      parameters: { path: { id: string } };\n      requestBody: {\n        content: {\n          \"application/json\": { lease_token: string; operation_id: string };\n        };\n      };\n      responses: {\n        200: { content: { \"application/json\": DeferredFieldsResponse } };\n      };\n    };\n  };\n}\n\n// --- HTTP Retry Utilities ---\n// These handle transport-level retry (5xx, network errors).\n// Distinct from step retry (business logic retry when user code throws).\n\nexport interface HttpRetryConfig {\n  /** Maximum number of attempts (default: 3) */\n  maxAttempts: number;\n  /** Base delay in milliseconds (default: 500) */\n  baseDelayMs: number;\n  /** Maximum delay cap in milliseconds (default: 5000) */\n  maxDelayMs: number;\n  /** Jitter factor 0-1 (default: 0.5) */\n  jitterFactor: number;\n}\n\nexport const DEFAULT_HTTP_RETRY_CONFIG: HttpRetryConfig = {\n  maxAttempts: 3,\n  baseDelayMs: 500,\n  maxDelayMs: 5000,\n  jitterFactor: 0.5,\n};\n\n/**\n * Check if an HTTP status code is retriable.\n * Retriable: 5xx server errors, 408 timeout, 429 rate limit, network errors.\n */\nexport function isHttpRetriable(status: number | undefined): boolean {\n  if (status === undefined) return true; // Network error (no response)\n  if (status >= 500) return true; // Server errors\n  if (status === 408) return true; // Request timeout\n  if (status === 429) return true; // Rate limited\n  return false;\n}\n\n/**\n * Calculate delay for a given retry attempt using exponential backoff with jitter.\n */\nexport function calculateHttpDelay(\n  attempt: number,\n  config: HttpRetryConfig,\n): number {\n  const exponential = config.baseDelayMs * Math.pow(2, attempt - 1);\n  const capped = Math.min(exponential, config.maxDelayMs);\n  const jitter = Math.random() * config.jitterFactor * capped;\n  return Math.floor(capped + jitter);\n}\n\nfunction sleep(ms: number): Promise<void> {\n  return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/** Per-attempt request timeout for every RestClient network call. */\nconst HTTP_REQUEST_TIMEOUT_SECONDS = 30;\n\ninterface HttpResult<T> {\n  data?: T;\n  error?: unknown;\n  response?: Response;\n}\n\n/**\n * Marks fetch's own rejections (connection reset, refused connection, DNS\n * failure, a connection dropped mid-body) other than our timeout abort. The\n * request may or may not have reached the server, so a durable write that\n * fails this way has an unknown outcome. The original error is rethrown\n * unchanged; only the mark is added.\n */\nconst TRANSPORT_FAILURE = Symbol(\"durable.transportFailure\");\n\nfunction markTransportFailures(fetchImpl: typeof fetch): typeof fetch {\n  return async (input, init) => {\n    try {\n      const response = await fetchImpl(input, init);\n      // openapi-fetch reads the body after fetch returns, outside this catch.\n      // Draining a clone here buffers the whole body into the original, so a\n      // connection dropped mid-body is marked like one dropped before the\n      // headers, and openapi-fetch's later read cannot touch the socket.\n      await drainBody(response.clone());\n      return response;\n    } catch (error) {\n      if (\n        error instanceof Error &&\n        error.name !== \"AbortError\" &&\n        !(TRANSPORT_FAILURE in error)\n      ) {\n        Object.defineProperty(error, TRANSPORT_FAILURE, { value: true });\n      }\n      throw error;\n    }\n  };\n}\n\n/**\n * Read a body to its end, discarding each chunk as it arrives, so no second\n * full copy of the body is held (`fetchDeferred` can return several\n * megabytes).\n */\nasync function drainBody(response: Response): Promise<void> {\n  const reader = response.body?.getReader();\n  if (!reader) return;\n  while (!(await reader.read()).done) {\n    // Keep reading until the stream ends or rejects.\n  }\n}\n\nfunction isTransportFailure(error: unknown): error is Error {\n  return error instanceof Error && TRANSPORT_FAILURE in error;\n}\n\n/**\n * undici reports every transport failure as a bare \"fetch failed\" or\n * \"terminated\" and puts what happened (`read ECONNRESET`, `other side closed`)\n * on the cause.\n */\nfunction describeTransportFailure(error: Error): string {\n  return error.cause instanceof Error\n    ? `${error.message}: ${error.cause.message}`\n    : error.message;\n}\n\n/**\n * Run one request attempt under a bounded timeout.\n *\n * A timeout or transport failure is reported as a response-less failure, so\n * `isHttpRetriable` routes it into the caller's retry path instead of ending\n * the call.\n */\nasync function sendWithTimeout<T>(\n  operation: string,\n  send: (signal: AbortSignal) => Promise<HttpResult<T>>,\n): Promise<HttpResult<T> & { timedOut?: boolean }> {\n  const controller = new AbortController();\n  let timedOut = false;\n\n  const timer = setTimeout(() => {\n    timedOut = true;\n    controller.abort();\n  }, HTTP_REQUEST_TIMEOUT_SECONDS * 1000);\n\n  try {\n    return await send(controller.signal);\n  } catch (error) {\n    if (isTransportFailure(error)) {\n      return {\n        error: {\n          error: \"transport_failure\",\n          message: `${operation} transport failure: ${describeTransportFailure(error)}`,\n        },\n      };\n    }\n    // Aborting with no reason causes the platform to supply its default — a\n    // DOMException named \"AbortError\", which propagates up verbatim.\n    const isTimeoutAbort =\n      timedOut && error instanceof Error && error.name === \"AbortError\";\n    if (!isTimeoutAbort) throw error;\n    return {\n      timedOut: true,\n      error: {\n        error: \"request_timeout\",\n        message: `${operation} request timed out after ${HTTP_REQUEST_TIMEOUT_SECONDS}s`,\n      },\n    };\n  } finally {\n    clearTimeout(timer);\n  }\n}\n\nfunction isWireVersionMismatchBody(error: unknown): boolean {\n  return (\n    typeof error === \"object\" &&\n    error !== null &&\n    ((\"code\" in error && error.code === \"wire-version-mismatch\") ||\n      (\"error\" in error && error.error === \"wire-version-mismatch\"))\n  );\n}\n\n// --- Localhost Test JWT ---\n\n/**\n * Check if a URL is localhost (for auto-generating test JWT).\n */\nfunction isLocalhostUrl(url: string): boolean {\n  try {\n    const parsed = new URL(url);\n    return (\n      parsed.hostname === \"localhost\" ||\n      parsed.hostname === \"127.0.0.1\" || // pii:allow\n      parsed.hostname.startsWith(\"127.\")\n    );\n  } catch {\n    return false;\n  }\n}\n\n/**\n * Generate a test JWT compatible with the durable API in dev mode.\n *\n * When the API is running with JWT signature verification disabled,\n * it skips signature verification but still validates the token structure.\n * This generates a properly-structured JWT for local development.\n */\nexport function generateLocalhostTestJwt(\n  opts: { userId?: string; accountId?: string } = {},\n): string {\n  const { userId = \"test-user-1\", accountId = \"test-account-1\" } = opts;\n\n  const header = { alg: \"RS256\", typ: \"JWT\", kid: \"localhost-dev-key\" };\n  const payload = {\n    // Standard JWT claims\n    sub: `customuser:${userId}`,\n    sub_type: \"customuser\",\n    iss: \"id.zapier.com\",\n    aud: \"zapier.com\",\n    exp: Math.floor(Date.now() / 1000) + 86400, // 24 hours\n    nbf: Math.floor(Date.now() / 1000),\n    iat: Math.floor(Date.now() / 1000),\n    jti: `localhost-${Date.now()}`,\n    scp: [\"user\"],\n    // Zapier-specific claims\n    \"zap:acc\": accountId,\n    \"zap:uid\": userId,\n    \"zap:rle\": \"admin\",\n    \"zap:rlm\": \"zapier.com\",\n    \"zap:tms\": [1],\n    \"zap:tmsown\": [1],\n  };\n\n  const encode = (obj: object) =>\n    Buffer.from(JSON.stringify(obj)).toString(\"base64url\");\n  return `${encode(header)}.${encode(payload)}.localhost-dev-signature`;\n}\n\n// --- RestClient ---\n\nexport interface RestClientOptions {\n  /** Base URL for the API (default: https://sdkapi.zapier.com/api/v0/sdk/code-substrate-runner) */\n  baseUrl?: string;\n  /** Base URL for callback URLs shown to users (may differ from API baseUrl) */\n  callbackBaseUrl?: string;\n  /** Authorization token (JWT). Auto-generated for localhost if not provided. */\n  token?: string;\n  /** Enable debug logging */\n  logging?: boolean;\n  /** HTTP retry configuration for transient failures (false to disable) */\n  httpRetry?: Partial<HttpRetryConfig> | false;\n  /**\n   * Opt out of advertising the `presigned-result-v1` capability. With the\n   * header absent, the server omits `presigned` blocks on externalized\n   * operations and the SDK falls back to `fetchDeferred` for every read.\n   * Use for restricted-egress environments that cannot reach S3 directly.\n   *\n   * Note: this does *not* disable the read-side hydration pass — the SDK\n   * still scans checkout responses for sentinel-prefixed fields and\n   * resolves them via `fetchDeferred`. Sentinels in user data would\n   * otherwise leak through as raw strings.\n   */\n  disablePresignedCapability?: boolean;\n}\n\nexport class RestClient implements DurableClient {\n  private client: ReturnType<typeof createClient<ApiPaths>>;\n  private _callbackBaseUrl: string;\n  private logging: boolean;\n  private httpRetryConfig: HttpRetryConfig | false;\n\n  get callbackBaseUrl(): string {\n    return this._callbackBaseUrl;\n  }\n\n  constructor(options: RestClientOptions = {}) {\n    const baseUrl =\n      options.baseUrl ??\n      \"https://sdkapi.zapier.com/api/v0/sdk/code-substrate-runner\";\n    this._callbackBaseUrl =\n      options.callbackBaseUrl ?? `${baseUrl}/api/v0/callbacks`;\n    this.logging = options.logging ?? false;\n\n    // Configure HTTP retry\n    if (options.httpRetry === false) {\n      this.httpRetryConfig = false;\n    } else {\n      this.httpRetryConfig = {\n        ...DEFAULT_HTTP_RETRY_CONFIG,\n        ...options.httpRetry,\n      };\n    }\n\n    // Determine token: use provided, or auto-generate for localhost\n    let token = options.token;\n    if (!token && isLocalhostUrl(baseUrl)) {\n      token = generateLocalhostTestJwt();\n      if (this.logging) {\n        console.log(\n          `  [rest-client] Auto-generated test JWT for localhost (requires the backend to be running in development mode)`,\n        );\n      }\n    }\n\n    const headers: Record<string, string> = {\n      \"Content-Type\": \"application/json\",\n    };\n\n    if (token) {\n      headers[\"Authorization\"] = `Bearer ${token}`;\n    }\n\n    if (!options.disablePresignedCapability) {\n      headers[CAPABILITY_HEADER] = CapabilityPresignedV1;\n    }\n\n    headers[WIRE_VERSION_HEADER] = String(SDK_WIRE_VERSION_MAX);\n\n    this.client = createClient<ApiPaths>({\n      baseUrl,\n      headers,\n      fetch: markTransportFailures(globalThis.fetch),\n    });\n  }\n\n  setLogging(enabled: boolean): void {\n    this.logging = enabled;\n  }\n\n  private log(msg: string): void {\n    if (this.logging) {\n      console.log(`  [rest-client] ${msg}`);\n    }\n  }\n\n  /**\n   * Execute an operation with HTTP retry logic for transient failures.\n   * Retries on 5xx, 408, 429, timeouts, and network errors.\n   */\n  private async withHttpRetry<T>(\n    operation: string,\n    fn: (signal: AbortSignal) => Promise<HttpResult<T>>,\n    options?: {\n      /** Handle a 409 identically regardless of retry history. */\n      onAny409?: () => T;\n    },\n  ): Promise<T> {\n    const config = this.httpRetryConfig;\n    const maxAttempts = config === false ? 1 : config.maxAttempts;\n\n    for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n      const { data, error, response, timedOut } = await sendWithTimeout(\n        operation,\n        fn,\n      );\n\n      if (data !== undefined) {\n        return data;\n      }\n\n      const status = response?.status;\n\n      if (status === 409 && options?.onAny409) {\n        return options.onAny409();\n      }\n\n      if (!isHttpRetriable(status)) {\n        throw new Error(`${operation} failed: ${JSON.stringify(error)}`);\n      }\n      // A retriable failure can follow a committed write, so the last one\n      // leaves the outcome unknown rather than failed.\n      if (config === false || attempt === maxAttempts) {\n        throw new RequestOutcomeUnknownError(\n          operation,\n          attempt,\n          JSON.stringify(error),\n        );\n      }\n\n      const delay = calculateHttpDelay(attempt, config);\n      this.log(\n        `${operation}: ${status ?? (timedOut ? \"timeout\" : \"network error\")}, retry ${attempt}/${maxAttempts} in ${delay}ms`,\n      );\n      await sleep(delay);\n    }\n\n    // Should never reach here, but TypeScript needs it\n    throw new Error(`${operation} failed after ${maxAttempts} attempts`);\n  }\n\n  async create(req: CreateExecutionRequest): Promise<CreateExecutionResponse> {\n    this.log(`create: ${req.name}`);\n\n    const data = await this.withHttpRetry(\n      \"create\",\n      (signal) => this.client.POST(\"/api/v0/executions\", { body: req, signal }),\n      {\n        onAny409: () => {\n          throw new IdempotencyConflictError(\n            req.inbox ?? \"\",\n            req.idempotency_key ?? \"\",\n          );\n        },\n      },\n    );\n\n    this.log(`created: ${data.id}`);\n    return data;\n  }\n\n  async checkout(\n    executionId: string,\n    req?: CheckoutRequest,\n  ): Promise<CheckoutResponse> {\n    this.log(`checkout: ${executionId}`);\n\n    const data = await this.withHttpRetry(\n      \"checkout\",\n      async (signal) => {\n        const res = await this.client.POST(\"/api/v0/executions/{id}/checkout\", {\n          params: { path: { id: executionId } },\n          body: req ?? {},\n          signal,\n        });\n        if (\n          res.response?.status === 426 ||\n          isWireVersionMismatchBody(res.error)\n        ) {\n          throw new WireVersionMismatchError(executionId);\n        }\n        return res;\n      },\n      {\n        onAny409: () => {\n          throw new ExecutionTerminalError(executionId);\n        },\n      },\n    );\n\n    if (data.leased) {\n      this.log(\n        `checkout: ${executionId}, ${data.operations.length} operations`,\n      );\n    } else {\n      this.log(`checkout: ${executionId}, not leased`);\n    }\n\n    return data;\n  }\n\n  async checkpoint(\n    executionId: string,\n    req: CheckpointRequest,\n  ): Promise<CheckpointResponse> {\n    this.log(`checkpoint: ${req.operation.name} -> ${req.operation.status}`);\n\n    const data = await this.withHttpRetry(\n      \"checkpoint\",\n      (signal) =>\n        this.client.POST(\"/api/v0/executions/{id}/checkpoint\", {\n          params: { path: { id: executionId } },\n          body: req,\n          signal,\n        }),\n      {\n        onAny409: () => {\n          throw new LeaseConflictError(executionId);\n        },\n      },\n    );\n\n    return data;\n  }\n\n  async release(\n    executionId: string,\n    req: ReleaseRequest,\n  ): Promise<ReleaseResponse> {\n    this.log(`release: ${executionId} -> ${req.status}`);\n\n    const data = await this.withHttpRetry(\n      \"release\",\n      (signal) =>\n        this.client.POST(\"/api/v0/executions/{id}/release\", {\n          params: { path: { id: executionId } },\n          body: req,\n          signal,\n        }),\n      {\n        onAny409: () => {\n          throw new LeaseConflictError(executionId);\n        },\n      },\n    );\n\n    this.log(`release: done=${data.done}`);\n    return data;\n  }\n\n  async callback(\n    token: string,\n    req: CallbackRequest,\n  ): Promise<CallbackResponse> {\n    this.log(`callback: ${token}`);\n\n    // Callback has special error handling - don't use withHttpRetry directly\n    const config = this.httpRetryConfig;\n    const maxAttempts = config === false ? 1 : config.maxAttempts;\n\n    for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n      const { data, error, response, timedOut } = await sendWithTimeout(\n        \"callback\",\n        (signal) =>\n          this.client.POST(\"/api/v0/callbacks/{token}\", {\n            params: { path: { token } },\n            body: req,\n            signal,\n          }),\n      );\n\n      if (data) {\n        this.log(`callback delivered: ${token}`);\n        return data;\n      }\n\n      // Handle specific error cases (these are not retry-able)\n      const errObj = error as { error?: string };\n      const status = response?.status;\n\n      // 410/409 are terminal delivery outcomes the server distinguishes by\n      // status code: 410 = the callback expired and can no longer be\n      // delivered; 409 = it already completed with a structurally different\n      // payload (an idempotent identical re-delivery returns 200). Surface them\n      // as typed errors so a delivering caller can tell these apart from a\n      // transient failure. Keyed on status, not the response body, so an\n      // unexpected body can't degrade a terminal outcome to a generic failure.\n      if (status === 410) {\n        throw new CallbackExpiredError(token);\n      }\n      if (status === 409) {\n        throw new CallbackConflictError(token);\n      }\n\n      if (errObj.error === \"not_found\") {\n        return { error: \"not_found\" };\n      }\n      if (errObj.error === \"validation_failed\") {\n        // Pass through AJV validation error details from API\n        const details = (error as { details?: unknown[] }).details ?? [];\n        return { error: \"validation_failed\", details };\n      }\n\n      // Check if we should retry\n      if (\n        config === false ||\n        !isHttpRetriable(status) ||\n        attempt === maxAttempts\n      ) {\n        throw new Error(`Failed to deliver callback: ${JSON.stringify(error)}`);\n      }\n\n      const delay = calculateHttpDelay(attempt, config);\n      this.log(\n        `callback: ${status ?? (timedOut ? \"timeout\" : \"network error\")}, retry ${attempt}/${maxAttempts} in ${delay}ms`,\n      );\n      await sleep(delay);\n    }\n\n    throw new Error(`Failed to deliver callback after ${maxAttempts} attempts`);\n  }\n\n  /**\n   * Universal fallback for externalized results: the server fetches and\n   * decompresses the S3 bundle and returns the full field bag inline.\n   * Used when the SDK has no capability header, when the presigned URL\n   * has expired/403'd, or when verification of the presigned path failed.\n   */\n  async fetchDeferred(\n    executionId: string,\n    operationId: string,\n    leaseToken: string,\n  ): Promise<DeferredFieldsResponse> {\n    this.log(`fetchDeferred: ${executionId}/${operationId}`);\n\n    const config = this.httpRetryConfig;\n    const maxAttempts = config === false ? 1 : config.maxAttempts;\n\n    for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n      const { data, error, response, timedOut } = await sendWithTimeout(\n        \"fetchDeferred\",\n        (signal) =>\n          this.client.POST(\"/api/v0/executions/{id}/fetch_deferred\", {\n            params: { path: { id: executionId } },\n            body: { lease_token: leaseToken, operation_id: operationId },\n            signal,\n          }),\n      );\n\n      if (data !== undefined) {\n        return data;\n      }\n\n      const status = response?.status;\n\n      // 404 = operation or its S3 object is gone; terminal, no retry.\n      if (status === 404) {\n        throw new ResultNotFoundError(\n          `fetchDeferred returned 404 for operation ${operationId}`,\n          { executionId, operationId },\n        );\n      }\n\n      if (\n        config === false ||\n        !isHttpRetriable(status) ||\n        attempt === maxAttempts\n      ) {\n        throw new Error(`fetchDeferred failed: ${JSON.stringify(error)}`);\n      }\n\n      const delay = calculateHttpDelay(attempt, config);\n      this.log(\n        `fetchDeferred: ${status ?? (timedOut ? \"timeout\" : \"network error\")}, retry ${attempt}/${maxAttempts} in ${delay}ms`,\n      );\n      await sleep(delay);\n    }\n\n    throw new Error(`fetchDeferred failed after ${maxAttempts} attempts`);\n  }\n}\n","const nodeZstdDecompress =\n  typeof process === \"undefined\"\n    ? undefined\n    : process.getBuiltinModule?.(\"node:zlib\")?.zstdDecompress;\n\ntype ZstdCapableDecompressionStreamCtor = new (\n  format: \"zstd\",\n) => GenericTransformStream;\n\n/**\n * `DecompressionStream` itself isn't universal — Cloudflare Workers,\n * Deno without `--unstable-byonm`, React Native, and older Node lack\n * the global entirely. Dereferencing it at module scope (outside a\n * guard) would throw `ReferenceError` on import, breaking the whole\n * `zapier-durable` package, not just the native path. Check via\n * `typeof` before the constructor probe.\n */\nconst hasNativeZstd: boolean = (() => {\n  if (typeof DecompressionStream === \"undefined\") return false;\n  try {\n    new (DecompressionStream as unknown as ZstdCapableDecompressionStreamCtor)(\n      \"zstd\",\n    );\n    return true;\n  } catch {\n    return false;\n  }\n})();\n\nexport interface DecompressOptions {\n  /**\n   * Hard cap on the decompressed output. The caller is expected to\n   * derive this from the server-signed `uncompressed_size` (plus a\n   * small slack for length-encoding variance), so a malicious or\n   * buggy upstream cannot blow past the server's own write cap.\n   */\n  maxUncompressedBytes: number;\n}\n\nfunction capExceededError(maxUncompressedBytes: number): Error {\n  return new Error(\n    `Decompressed output exceeded cap of ${maxUncompressedBytes} bytes`,\n  );\n}\n\nexport async function decompressZstd(\n  compressed: Uint8Array,\n  opts: DecompressOptions,\n): Promise<Uint8Array> {\n  if (nodeZstdDecompress) {\n    return new Promise((resolve, reject) => {\n      nodeZstdDecompress(\n        compressed,\n        { maxOutputLength: opts.maxUncompressedBytes },\n        (error, result) => {\n          if (!error) resolve(result);\n          else if (\n            (error as { code?: unknown }).code === \"ERR_BUFFER_TOO_LARGE\"\n          ) {\n            // Match the Web Streams and fzstd paths so callers see one\n            // consistent failure regardless of which decoder ran.\n            reject(capExceededError(opts.maxUncompressedBytes));\n          } else reject(error);\n        },\n      );\n    });\n  }\n  if (hasNativeZstd) {\n    return decompressNative(compressed, opts.maxUncompressedBytes);\n  }\n  return decompressFallback(compressed, opts.maxUncompressedBytes);\n}\n\nasync function decompressNative(\n  compressed: Uint8Array,\n  maxUncompressedBytes: number,\n): Promise<Uint8Array> {\n  const source = new ReadableStream<Uint8Array>({\n    start(controller) {\n      controller.enqueue(compressed);\n      controller.close();\n    },\n  });\n\n  const reader = source\n    .pipeThrough(\n      new (DecompressionStream as unknown as ZstdCapableDecompressionStreamCtor)(\n        \"zstd\",\n      ) as TransformStream<Uint8Array, Uint8Array>,\n    )\n    .getReader();\n\n  const chunks: Uint8Array[] = [];\n  let total = 0;\n\n  while (true) {\n    const { done, value } = await reader.read();\n    if (done) break;\n    total += value.byteLength;\n    if (total > maxUncompressedBytes) {\n      // Cancel propagates upstream and tears down the decompressor\n      // mid-flight, so we don't keep decoding bytes we'll never use.\n      await reader.cancel();\n      throw capExceededError(maxUncompressedBytes);\n    }\n    chunks.push(value);\n  }\n\n  if (chunks.length === 1) return chunks[0];\n  const out = new Uint8Array(total);\n  let offset = 0;\n  for (const chunk of chunks) {\n    out.set(chunk, offset);\n    offset += chunk.byteLength;\n  }\n  return out;\n}\n\nasync function decompressFallback(\n  compressed: Uint8Array,\n  maxUncompressedBytes: number,\n): Promise<Uint8Array> {\n  const { decompress } = await import(\"fzstd\");\n  const out = decompress(compressed);\n  if (out.length > maxUncompressedBytes) {\n    throw capExceededError(maxUncompressedBytes);\n  }\n  return out;\n}\n","/**\n * Fetch + verify + decompress an externalized result bundle from S3.\n *\n * Verification order matters: SHA-256 over the raw compressed bytes runs\n * BEFORE decompression begins, so mismatched bytes never reach the\n * decompressor.\n *\n * `block.envelope_sig` is currently unverified — the SDK has no copy of\n * the server-side signing key. Integrity rests on the SHA-256 binding\n * plus TLS and S3 SigV4 on the presigned URL.\n */\nimport type { PresignedBlock } from \"../types\";\nimport { ResultCorruptError, ResultNotFoundError } from \"../errors\";\nimport { decompressZstd } from \"./decompress\";\n\n/** S3 GET timeout. Well below the 15-min lease TTL; generous for a few-MB bundle. */\nconst s3FetchTimeoutMs = 15_000;\n\n/**\n * Slack added to the server-signed `uncompressed_size` when capping the\n * decompressor. Covers small length-encoding variance and gives the\n * native streaming path enough room to read the final chunk before\n * hitting the cap.\n */\nconst UNCOMPRESSED_SLACK_BYTES = 64;\n\n/**\n * Absolute ceiling on the decompressed bundle, independent of the\n * server-supplied `uncompressed_size`. Mirrors the backend's 10 MB\n * write cap. Until `envelope_sig` is verified end-to-end, treat the\n * `uncompressed_size` value as untrusted (a TLS-MITM or buggy upstream\n * could supply NaN, a negative number, or MAX_SAFE_INTEGER, all of\n * which would silently disable the cap). Clamp to this ceiling.\n */\nconst MAX_ALLOWED_BUNDLE_BYTES = 10 * 1024 * 1024;\n\n/**\n * Internal control-flow signal: the presigned path is unusable (URL\n * returned 403/expired, network error, or the bytes failed integrity\n * verification before they were inspected enough to call them corrupt).\n * The resolver catches this and falls back to `fetchDeferred`.\n *\n * Shape mirrors `ZapierSignal` (name, code) per Rule 12; the abstract\n * base will follow when the whole `zapier-durable/errors.ts` module\n * migrates to `ZapierError`/`ZapierSignal`.\n */\nexport class ZapierPresignedUnavailableSignal extends Error {\n  readonly name = \"ZapierPresignedUnavailableSignal\";\n  readonly code = \"ZAPIER_PRESIGNED_UNAVAILABLE\" as const;\n  readonly status: number | \"network\" | \"expired\";\n  constructor(status: number | \"network\" | \"expired\", message: string) {\n    super(message);\n    this.status = status;\n    Object.setPrototypeOf(this, new.target.prototype);\n  }\n}\n\nexport interface BundleFetchScope {\n  executionId: string;\n  operationId: string;\n  correlationId?: string;\n}\n\n/** Materialized bag of deferrable fields for one operation, post-decode. */\nexport type FetchedBundleFields = Record<string, unknown>;\n\n/**\n * Resolve a presigned block to its materialized field bag.\n *\n * Throws:\n *   - `ZapierPresignedUnavailableSignal` — URL returned 403, expired before we\n *     could request, or the network call failed. Caller should fall back\n *     to `fetchDeferred`.\n *   - `ResultNotFoundError` — URL returned 404. S3 object missing\n *     (lifecycle expiration, GDPR purge, writer/reader inconsistency).\n *     Terminal.\n *   - `ResultCorruptError` — checksum mismatch or decompression failure.\n *     Terminal.\n *\n * The `fetch` parameter is injectable for tests; defaults to global fetch.\n */\nexport async function fetchAndDecodeBundle(\n  block: PresignedBlock,\n  scope: BundleFetchScope,\n  fetchImpl: typeof fetch = fetch,\n): Promise<FetchedBundleFields> {\n  const expiresMs = Date.parse(block.expires_at);\n  if (!Number.isFinite(expiresMs) || expiresMs <= Date.now()) {\n    throw new ZapierPresignedUnavailableSignal(\n      \"expired\",\n      \"Presigned URL expires_at is missing, invalid, or in the past\",\n    );\n  }\n\n  // Bound the S3 GET so a single stalled connection can't hold the\n  // checkout (and the lease) hostage. 15s is well under the 15-min lease\n  // TTL and generous for any reasonable bundle size + S3 latency budget.\n  let response: Response;\n  try {\n    response = await fetchImpl(block.url, {\n      signal: AbortSignal.timeout(s3FetchTimeoutMs),\n    });\n  } catch (cause) {\n    throw new ZapierPresignedUnavailableSignal(\n      \"network\",\n      `S3 GET failed: ${(cause as Error)?.message ?? \"network error\"}`,\n    );\n  }\n\n  if (response.status === 403) {\n    throw new ZapierPresignedUnavailableSignal(\n      403,\n      \"S3 returned 403 (likely expired or revoked presigned URL)\",\n    );\n  }\n  if (response.status === 404) {\n    throw new ResultNotFoundError(\n      \"Externalized result object missing from S3\",\n      {\n        executionId: scope.executionId,\n        operationId: scope.operationId,\n        correlationId: scope.correlationId,\n      },\n    );\n  }\n  if (!response.ok) {\n    throw new ZapierPresignedUnavailableSignal(\n      response.status,\n      `Unexpected S3 status ${response.status}`,\n    );\n  }\n\n  const compressed = new Uint8Array(await response.arrayBuffer());\n\n  // Wire format is `sha256:<base64-of-32-byte-digest>`. Compare base64\n  // strings directly — constant-time isn't load-bearing here (no HMAC),\n  // so a length-equal byte compare adds no security.\n  const expectedSig = parseSha256Checksum(block.compressed_checksum);\n  if (expectedSig === null) {\n    throw new ResultCorruptError(\n      `Malformed compressed_checksum: ${block.compressed_checksum}`,\n      {\n        kind: \"checksum_mismatch\",\n        executionId: scope.executionId,\n        operationId: scope.operationId,\n        correlationId: scope.correlationId,\n      },\n    );\n  }\n  const actualSig = await sha256Base64(compressed);\n  if (actualSig !== expectedSig) {\n    throw new ResultCorruptError(\"Bundle SHA-256 mismatch\", {\n      kind: \"checksum_mismatch\",\n      executionId: scope.executionId,\n      operationId: scope.operationId,\n      correlationId: scope.correlationId,\n    });\n  }\n\n  // Validate `uncompressed_size` before deriving the cap. The wire\n  // value is typed `number` but is untrusted until `envelope_sig` is\n  // verified, so a non-finite / negative / absurdly-large value would\n  // disable the cap entirely. Clamp to MAX_ALLOWED_BUNDLE_BYTES so the\n  // ceiling is enforced even if the server contract drifts.\n  const declaredSize = block.uncompressed_size;\n  if (\n    !Number.isInteger(declaredSize) ||\n    declaredSize < 0 ||\n    declaredSize > MAX_ALLOWED_BUNDLE_BYTES\n  ) {\n    throw new ResultCorruptError(\n      `Invalid uncompressed_size: ${String(declaredSize)}`,\n      {\n        kind: \"decompress_error\",\n        executionId: scope.executionId,\n        operationId: scope.operationId,\n        correlationId: scope.correlationId,\n      },\n    );\n  }\n\n  let uncompressed: Uint8Array;\n  try {\n    uncompressed = await decompressZstd(compressed, {\n      maxUncompressedBytes: declaredSize + UNCOMPRESSED_SLACK_BYTES,\n    });\n  } catch (cause) {\n    throw new ResultCorruptError(\n      `zstd decompression failed: ${(cause as Error)?.message ?? \"unknown\"}`,\n      {\n        kind: \"decompress_error\",\n        executionId: scope.executionId,\n        operationId: scope.operationId,\n        correlationId: scope.correlationId,\n      },\n    );\n  }\n\n  try {\n    const text = new TextDecoder(\"utf-8\", { fatal: true }).decode(uncompressed);\n    const parsed = JSON.parse(text);\n    if (\n      typeof parsed !== \"object\" ||\n      parsed === null ||\n      Array.isArray(parsed)\n    ) {\n      throw new Error(\"Bundle root is not a JSON object\");\n    }\n    return parsed as FetchedBundleFields;\n  } catch (cause) {\n    throw new ResultCorruptError(\n      `Bundle JSON decode failed: ${(cause as Error)?.message ?? \"unknown\"}`,\n      {\n        kind: \"decompress_error\",\n        executionId: scope.executionId,\n        operationId: scope.operationId,\n        correlationId: scope.correlationId,\n      },\n    );\n  }\n}\n\n/**\n * SHA-256 over `bytes` returning standard base64. The server emits the\n * digest as `sha256:<base64>` on the wire (see `mintPresignedBlock`),\n * so we encode our local digest the same way for a direct string compare.\n */\nasync function sha256Base64(bytes: Uint8Array): Promise<string> {\n  const digest = await crypto.subtle.digest(\"SHA-256\", bytes);\n  return uint8ToBase64(new Uint8Array(digest));\n}\n\n/**\n * Validate and unwrap a `sha256:<base64>` checksum. Returns the base64\n * portion on success, `null` on any structural problem. Strict — the\n * server contract is exact.\n */\nfunction parseSha256Checksum(value: string): string | null {\n  const prefix = \"sha256:\";\n  if (!value.startsWith(prefix)) return null;\n  const sig = value.slice(prefix.length);\n  // SHA-256 is 32 bytes; base64 of 32 bytes is 44 chars including one `=`.\n  if (sig.length !== 44) return null;\n  return sig;\n}\n\n/**\n * Base64-encode bytes without depending on Node's `Buffer` (browser-safe).\n * `btoa` accepts only Latin-1 strings, so we build the string byte-by-byte.\n */\nfunction uint8ToBase64(bytes: Uint8Array): string {\n  let binary = \"\";\n  for (let i = 0; i < bytes.length; i++) {\n    binary += String.fromCharCode(bytes[i]);\n  }\n  return btoa(binary);\n}\n","/**\n * Lazy resolver for externalized operation bundles, scoped to one tick.\n *\n * The cache (`Map<operation_id, Promise<bag>>`) collapses multiple field\n * reads on the same operation into one fetch, and skips operations whose\n * results are never read on this tick.\n *\n * Resolution per operation:\n *   - If `presigned` is present, try the direct S3 GET.\n *   - On `ZapierPresignedUnavailableSignal` (403, expired, network) or\n *     `ResultCorruptError(checksum_mismatch)`, fall back to\n *     `fetchDeferred` — these are the only failures the server might\n *     succeed where the SDK didn't.\n *   - Other `ResultCorruptError` kinds and `ResultNotFoundError`\n *     propagate terminally; re-fetching server-side would just surface\n *     the same failure.\n *   - If `presigned` is absent, go straight to `fetchDeferred`.\n *\n * Rejected fetches are evicted from the cache so a later call (e.g. in\n * a subsequent tick with a refreshed lease) can retry.\n */\nimport type {\n  Operation,\n  PresignedBlock,\n  DeferredFieldsResponse,\n} from \"../types\";\nimport {\n  ZapierPresignedUnavailableSignal,\n  type FetchedBundleFields,\n} from \"./bundle\";\nimport { ResultCorruptError } from \"../errors\";\n\nexport interface ResolverDeps {\n  presignedFetcher: (\n    block: PresignedBlock,\n    scope: { executionId: string; operationId: string },\n  ) => Promise<FetchedBundleFields>;\n  deferredFetcher: (\n    executionId: string,\n    operationId: string,\n    leaseToken: string,\n  ) => Promise<DeferredFieldsResponse>;\n}\n\nexport class OperationBundleResolver {\n  private readonly cache = new Map<string, Promise<FetchedBundleFields>>();\n\n  constructor(\n    private readonly executionId: string,\n    private readonly leaseToken: string,\n    private readonly deps: ResolverDeps,\n  ) {}\n\n  /**\n   * Resolve the field bag for `operation`. Subsequent calls with the same\n   * `operation.id` share the in-flight promise (or its resolved value).\n   * A rejected fetch is evicted so a later call can retry.\n   */\n  resolve(operation: Operation): Promise<FetchedBundleFields> {\n    const cached = this.cache.get(operation.id);\n    if (cached) return cached;\n\n    const pending = this.fetchBag(operation).catch((err) => {\n      this.cache.delete(operation.id);\n      throw err;\n    });\n    this.cache.set(operation.id, pending);\n    return pending;\n  }\n\n  private async fetchBag(op: Operation): Promise<FetchedBundleFields> {\n    if (op.presigned) {\n      try {\n        return await this.deps.presignedFetcher(op.presigned, {\n          executionId: this.executionId,\n          operationId: op.id,\n        });\n      } catch (err) {\n        if (!shouldFallback(err)) throw err;\n        // fall through to deferredFetcher\n      }\n    }\n\n    const fallback = await this.deps.deferredFetcher(\n      this.executionId,\n      op.id,\n      this.leaseToken,\n    );\n    return fallback.fields;\n  }\n}\n\nfunction shouldFallback(err: unknown): boolean {\n  // Safe to use `instanceof` here (unlike SDK-2195's cross-bundle case): these\n  // errors are constructed and caught within this bundle during operation\n  // resolution, so a single class identity exists at the throw/catch site.\n  if (err instanceof ZapierPresignedUnavailableSignal) return true;\n  if (err instanceof ResultCorruptError && err.kind === \"checksum_mismatch\") {\n    return true;\n  }\n  return false;\n}\n","/**\n * Runner - Executes a tick of a durable execution.\n */\n\nimport type { DurableClient, Operation } from \"./types\";\nimport { LeaseConflictError, RequestOutcomeUnknownError } from \"./errors\";\nimport { serializeError } from \"./errorCause\";\nimport { DeterminismGuard } from \"./guard\";\nimport { DormancyTracker } from \"./dormancy\";\nimport { DurableContext, type Clock, type RetryingStep } from \"./context\";\nimport { OperationBundleResolver } from \"./externalization/resolver\";\nimport { fetchAndDecodeBundle } from \"./externalization/bundle\";\n\nexport interface DurableResult<T> {\n  done: boolean;\n  result?: T;\n  error?: Error;\n  executionId?: string;\n  /**\n   * Steps that failed on this tick with attempts remaining, so the execution\n   * suspended to retry. Present (non-empty) only on a suspended (`waiting`)\n   * tick where at least one step burned an attempt; absent on completed and\n   * failed returns and on suspends with no step failure (e.g. a `ctx.wait`).\n   * Lets a host observe the error that occurred without waiting for the step\n   * to exhaust.\n   *\n   * Entries record events, not state: each corresponds 1:1 with an attempt\n   * burned during this tick, so a failure is reported exactly once, on the\n   * tick it happened. A step still in retry backoff on a later tick is not\n   * re-reported; the journal remains the authoritative view of which steps\n   * are currently scheduled to retry.\n   */\n  retrying?: RetryingStep[];\n}\n\nexport interface DurableDefinition<TInput, TOutput> {\n  name: string;\n  description?: string;\n  run: (ctx: DurableContext, input: TInput) => Promise<TOutput>;\n}\n\nexport interface RunTickOptions {\n  client: DurableClient;\n  executionId?: string;\n  input?: unknown;\n  inbox?: string;\n  idempotencyKey?: string;\n  leaseToken?: string;\n  settleDelayMs?: number;\n  logging?: boolean;\n  guardEnabled?: boolean;\n  /**\n   * Clock for time operations. Defaults to Date.now(). Inject a mock for\n   * testing. When using a mock clock, pass the same instance to the client\n   * (e.g., MemoryClient) so wait auto-completion at checkout uses the same\n   * time source.\n   */\n  clock?: Clock;\n}\n\nexport interface ExecuteTickOptions {\n  client: DurableClient;\n  executionId: string;\n  leaseToken: string;\n  input: unknown;\n  logging?: boolean;\n  guardEnabled?: boolean;\n}\n\n/**\n * Execute the tick lifecycle on a pre-built DurableContext.\n *\n * This is the lower-level primitive that both runTick() and the SDK's\n * defineDurable use. The caller is responsible for:\n * - Creating/checking out the execution\n * - Constructing the DurableContext (possibly with extra fields via Object.assign)\n *\n * executeTick handles:\n * - Guard setup (logging, global guards, violation detection)\n * - Racing user code against dormancy and violations\n * - Releasing the execution with the correct status\n *\n * The ctx parameter accepts DurableContext or any subtype (e.g. with extra\n * fields Object.assigned by the SDK's define layer).\n */\nexport async function executeTick<TContext extends DurableContext, TOutput>(\n  run: (ctx: TContext, input: unknown) => Promise<TOutput>,\n  ctx: TContext,\n  options: ExecuteTickOptions,\n): Promise<DurableResult<TOutput>> {\n  const {\n    client,\n    executionId,\n    leaseToken,\n    input,\n    logging = false,\n    guardEnabled = true,\n  } = options;\n\n  const guard = DeterminismGuard.instance;\n  guard.initGlobal();\n  guard.setLogging(logging);\n\n  if (guardEnabled) {\n    guard.installGlobalGuards();\n  }\n\n  let rejectViolation: (error: Error) => void;\n  const violationPromise = new Promise<never>((_, reject) => {\n    rejectViolation = reject;\n  });\n  guard.setViolationCallback((error) => rejectViolation(error));\n\n  try {\n    const [winner, value] = await Promise.race([\n      guard\n        .runGuarded(() => run(ctx, input))\n        .then((r) => [\"completed\", r] as const),\n      ctx.termination.then((r) => [\"suspended\", r] as const),\n      violationPromise,\n    ]);\n\n    // A write whose outcome is unknown, or that lost the lease, ends the\n    // tick with no release; the next tick replays what the server saved.\n    const writeError = ctx.getWriteError();\n    if (writeError) throw writeError;\n\n    if (winner === \"completed\") {\n      ctx.markReleased();\n      const { done } = await client.release(executionId, {\n        lease_token: leaseToken,\n        status: \"completed\",\n        output: value,\n      });\n      return { done, result: value, executionId };\n    } else {\n      const checkpointError = ctx.getCheckpointError();\n      if (checkpointError) throw checkpointError;\n      const pendingHold = ctx.getPendingHold();\n      ctx.markReleased();\n      const { done } = await client.release(executionId, {\n        lease_token: leaseToken,\n        status: \"waiting\",\n        ...(pendingHold ? { run_state: pendingHold } : {}),\n      });\n      const retrying = ctx.getRetryingSteps();\n      return retrying.length > 0\n        ? { done, executionId, retrying }\n        : { done, executionId };\n    }\n  } catch (error) {\n    // The sticky writeError covers user code that caught the SDK error and\n    // threw its own: the tick still must not release over an unknown write.\n    const writeError = ctx.getWriteError();\n    if (\n      writeError ||\n      error instanceof RequestOutcomeUnknownError ||\n      error instanceof LeaseConflictError\n    ) {\n      throw writeError ?? error;\n    }\n    ctx.markReleased();\n    const { done } = await client.release(executionId, {\n      lease_token: leaseToken,\n      status: \"failed\",\n      // The workflow has unwound out of GUARDED mode, so a StepExhaustedError's\n      // guarded cause is transparent here: serialize the full chain (wrapper +\n      // underlying error, stack, and props) for the host to report.\n      error: serializeError(error),\n    });\n    return { done, error: error as Error, executionId };\n  } finally {\n    guard.setViolationCallback(undefined);\n  }\n}\n\n/**\n * Execute a single tick of a durable execution.\n *\n * A tick runs user code until it either completes or goes dormant (all work done,\n * waiting on external events). Multiple ticks may be needed to complete an\n * execution - each tick resumes from where the previous left off.\n *\n * @param durable - The durable definition to execute\n * @param options - Execution options\n * @returns Result containing done status, result/error, and executionId\n */\nexport async function runTick<TInput, TOutput>(\n  durable: DurableDefinition<TInput, TOutput>,\n  options: RunTickOptions,\n): Promise<DurableResult<TOutput>> {\n  const {\n    client,\n    settleDelayMs = 50,\n    logging = false,\n    guardEnabled = true,\n    clock,\n  } = options;\n\n  // 1. Create execution if needed\n  let executionId = options.executionId;\n  if (!executionId) {\n    const { id } = await client.create({\n      name: durable.name,\n      input: options.input,\n      ...(options.inbox ? { inbox: options.inbox } : {}),\n      ...(options.idempotencyKey\n        ? { idempotency_key: options.idempotencyKey }\n        : {}),\n    });\n    executionId = id;\n  }\n\n  // 2. Checkout (lease + state)\n  const checkout = await client.checkout(\n    executionId,\n    options.leaseToken ? { lease_token: options.leaseToken } : undefined,\n  );\n  if (!checkout.leased) {\n    throw new LeaseConflictError(executionId);\n  }\n\n  // 3. Build context\n  const tracker = new DormancyTracker(settleDelayMs);\n  tracker.setLogging(logging);\n\n  const guard = DeterminismGuard.instance;\n  const bundleResolver = new OperationBundleResolver(\n    executionId,\n    checkout.lease_token,\n    {\n      presignedFetcher: (block, scope) => fetchAndDecodeBundle(block, scope),\n      deferredFetcher: (execId, opId, leaseToken) => {\n        if (!client.fetchDeferred) {\n          throw new Error(\n            `Client does not implement fetchDeferred; cannot resolve externalized result for operation ${opId}`,\n          );\n        }\n        return client.fetchDeferred(execId, opId, leaseToken);\n      },\n    },\n  );\n  const ctx = new DurableContext({\n    client,\n    tracker,\n    guard,\n    executionId,\n    leaseToken: checkout.lease_token,\n    operations: new Map(\n      checkout.operations.map((op: Operation) => [op.name, op]),\n    ),\n    bundleResolver,\n    clock,\n    // Servers predating wire versioning don't echo the field; absent\n    // means legacy behavior, which is safe in both directions.\n    wireVersion: checkout.execution.wire_version ?? 0,\n  });\n\n  // 4. Delegate to executeTick\n  return executeTick((c, input) => durable.run(c, input as TInput), ctx, {\n    client,\n    executionId,\n    leaseToken: checkout.lease_token,\n    input: checkout.execution.input,\n    logging,\n    guardEnabled,\n  });\n}\n","/**\n * Entry point for defining durable executions.\n */\n\nimport type { z } from \"zod\";\nimport type { DurableContext, Clock } from \"./context\";\nimport type {\n  DurableResult,\n  DurableDefinition,\n  RunTickOptions,\n} from \"./runner\";\nimport type { DurableClient } from \"./types\";\nimport { runTick } from \"./runner\";\nimport { getConfig, createClient } from \"./config\";\n\n// Re-export DurableDefinition for external use\nexport type { DurableDefinition, DurableResult };\n\n/**\n * Options for defining a durable execution.\n */\nexport interface DefineDurableOptions<\n  TInput extends Record<string, unknown>,\n  TOutput,\n> {\n  /** Unique name for this durable type */\n  name: string;\n  /** Optional description */\n  description?: string;\n  /** Optional Zod schema for input validation */\n  inputSchema?: z.ZodSchema<TInput>;\n  /** Optional Zod schema for output validation */\n  outputSchema?: z.ZodSchema<TOutput>;\n  /** The execution function */\n  run: (ctx: DurableContext, input: TInput) => Promise<TOutput>;\n}\n\n/**\n * Options for calling a durable (second argument). All fields are optional;\n * client defaults to createClient().\n */\nexport interface DurableCallOptions {\n  client?: DurableClient;\n  logging?: boolean;\n  guardEnabled?: boolean;\n  settleDelayMs?: number;\n  /** Clock used by runTick. If `client` is omitted, this clock is also\n   *  forwarded to the default local client so wait/callback expiry stay\n   *  in sync. If you pass an explicit `client`, construct it with the same\n   *  clock instance. */\n  clock?: Clock;\n  inbox?: string;\n  idempotencyKey?: string;\n  leaseToken?: string;\n}\n\n/**\n * A callable durable that can be invoked directly.\n *\n * Pass an object as the first argument to start a new execution.\n * Pass a string (execution ID) to resume an existing one.\n */\nexport interface CallableDurable<\n  TInput extends Record<string, unknown>,\n  TOutput,\n> extends DurableDefinition<TInput, TOutput> {\n  (\n    input: TInput,\n    options?: DurableCallOptions,\n  ): Promise<DurableResult<TOutput>>;\n  (\n    executionId: string,\n    options?: DurableCallOptions,\n  ): Promise<DurableResult<TOutput>>;\n}\n\n/**\n * Define a durable execution.\n *\n * Supports two call signatures:\n * - defineDurable(name, run) - Simple form\n * - defineDurable({ name, run, inputSchema?, outputSchema?, description? }) - Full options\n *\n * Returns a callable that can be invoked directly:\n *   const myDurable = defineDurable(\"my-durable\", async (ctx, input) => {...});\n *   const result = await myDurable({ userId: \"123\" });\n *\n * @example\n * // Simple form\n * const myDurable = defineDurable(\"my-durable\", async (ctx, input) => {\n *   const data = await ctx.step(\"fetch\", async () => {...});\n *   return data;\n * });\n * const result = await myDurable({ userId: \"123\" });\n *\n * @example\n * // Resume an existing execution\n * const result = await myDurable(\"exec-abc\");\n *\n * @example\n * // Full options with schemas\n * const myDurable = defineDurable({\n *   name: \"my-durable\",\n *   inputSchema: z.object({ userId: z.string() }),\n *   run: async (ctx, input) => {\n *     const data = await ctx.step(\"fetch\", async () => {...});\n *     return data;\n *   },\n * });\n */\nexport function defineDurable<\n  TInput extends Record<string, unknown> = Record<string, unknown>,\n  TOutput = unknown,\n>(\n  name: string,\n  run: (ctx: DurableContext, input: TInput) => Promise<TOutput>,\n): CallableDurable<TInput, TOutput>;\nexport function defineDurable<\n  TInput extends Record<string, unknown> = Record<string, unknown>,\n  TOutput = unknown,\n>(\n  options: DefineDurableOptions<TInput, TOutput>,\n): CallableDurable<TInput, TOutput>;\nexport function defineDurable<\n  TInput extends Record<string, unknown> = Record<string, unknown>,\n  TOutput = unknown,\n>(\n  nameOrOptions: string | DefineDurableOptions<TInput, TOutput>,\n  runFn?: (ctx: DurableContext, input: TInput) => Promise<TOutput>,\n): CallableDurable<TInput, TOutput> {\n  // Normalize arguments\n  let definition: DurableDefinition<TInput, TOutput>;\n  let inputSchema: z.ZodSchema<TInput> | undefined;\n  let outputSchema: z.ZodSchema<TOutput> | undefined;\n\n  if (typeof nameOrOptions === \"string\") {\n    definition = {\n      name: nameOrOptions,\n      run: runFn!,\n    };\n  } else {\n    definition = {\n      name: nameOrOptions.name,\n      description: nameOrOptions.description,\n      run: nameOrOptions.run,\n    };\n    inputSchema = nameOrOptions.inputSchema;\n    outputSchema = nameOrOptions.outputSchema;\n  }\n\n  // Create the callable function\n  const callable = async (\n    inputOrExecutionId: TInput | string,\n    options?: DurableCallOptions,\n  ): Promise<DurableResult<TOutput>> => {\n    const opts = options ?? {};\n    const config = getConfig();\n    const client =\n      opts.client ?? createClient(undefined, { clock: opts.clock });\n\n    const tickOptions: RunTickOptions = {\n      client,\n      logging: opts.logging ?? config.logging,\n      guardEnabled: opts.guardEnabled ?? config.guardEnabled,\n      settleDelayMs: opts.settleDelayMs,\n      clock: opts.clock,\n      inbox: opts.inbox,\n      idempotencyKey: opts.idempotencyKey,\n      leaseToken: opts.leaseToken,\n    };\n\n    if (typeof inputOrExecutionId === \"string\") {\n      tickOptions.executionId = inputOrExecutionId;\n    } else {\n      if (inputSchema) {\n        inputSchema.parse(inputOrExecutionId);\n      }\n      tickOptions.input = inputOrExecutionId;\n    }\n\n    const result = await runTick(definition, tickOptions);\n\n    // Validate output if schema provided and execution completed\n    if (outputSchema && result.done && result.result !== undefined) {\n      outputSchema.parse(result.result);\n    }\n\n    return result;\n  };\n\n  // Attach definition properties to the callable\n  // Note: 'name' is read-only on functions, so we use defineProperty\n  Object.defineProperty(callable, \"name\", {\n    value: definition.name,\n    writable: false,\n    configurable: true,\n  });\n  if (definition.description) {\n    Object.defineProperty(callable, \"description\", {\n      value: definition.description,\n      writable: true,\n      configurable: true,\n    });\n  }\n  Object.defineProperty(callable, \"run\", {\n    value: definition.run,\n    writable: true,\n    configurable: true,\n  });\n\n  return callable as CallableDurable<TInput, TOutput>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,qBAAN,cAAiC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,YAAY,WAAW;AAGpD,QAAI,gBAAgB,OAAO,QAAQ,OAAO,WAAW,QAAW;AAC9D,mBAAa,MAAM,OAAO,MAAM;AAAA,IAClC;AAEA,WAAO;AAAA,EACT;AAIA,SAAO,eAAe,UAAU,QAAQ;AAAA,IACtC,OAAO,WAAW;AAAA,IAClB,UAAU;AAAA,IACV,cAAc;AAAA,EAChB,CAAC;AACD,MAAI,WAAW,aAAa;AAC1B,WAAO,eAAe,UAAU,eAAe;AAAA,MAC7C,OAAO,WAAW;AAAA,MAClB,UAAU;AAAA,MACV,cAAc;AAAA,IAChB,CAAC;AAAA,EACH;AACA,SAAO,eAAe,UAAU,OAAO;AAAA,IACrC,OAAO,WAAW;AAAA,IAClB,UAAU;AAAA,IACV,cAAc;AAAA,EAChB,CAAC;AAED,SAAO;AACT;","names":["createClient","out","resolve","import_node_async_hooks","path","Ajv","op","path","import_ajv","AjvClass","Ajv","ajv","generateUuidV7","op","createClientModule","resolve","createClient","sleep","resolve","inner","resolve","createClient"]}