@workflow/world-testing 5.0.0-beta.38 → 5.0.0-beta.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -380,7 +380,9 @@ function appendFramedDetails(title, details) {
380
380
  const head = isLast ? "\u2570\u25B6 " : "\u251C\u25B6 ";
381
381
  const cont = isLast ? " " : "\u2502 ";
382
382
  const text = `${detail.label}: ${detail.value}`;
383
- text.split("\n").forEach((line, i) => lines.push(`${i === 0 ? head : cont}${line}`));
383
+ text.split("\n").forEach((line, i) => {
384
+ lines.push(`${i === 0 ? head : cont}${line}`);
385
+ });
384
386
  });
385
387
  return lines.join("\n");
386
388
  }
@@ -12063,10 +12065,10 @@ function _property(property, schema, params) {
12063
12065
  });
12064
12066
  }
12065
12067
  // @__NO_SIDE_EFFECTS__
12066
- function _mime(types2, params) {
12068
+ function _mime(types3, params) {
12067
12069
  return new $ZodCheckMimeType({
12068
12070
  check: "mime_type",
12069
- mime: types2,
12071
+ mime: types3,
12070
12072
  ...normalizeParams(params)
12071
12073
  });
12072
12074
  }
@@ -15387,8 +15389,8 @@ var init_schemas2 = __esm({
15387
15389
  inst._zod.processJSONSchema = (ctx, json2, params) => fileProcessor(inst, ctx, json2, params);
15388
15390
  inst.min = (size, params) => inst.check(_minSize(size, params));
15389
15391
  inst.max = (size, params) => inst.check(_maxSize(size, params));
15390
- inst.mime = (types2, params) => inst.check(_mime(Array.isArray(types2) ? types2 : [
15391
- types2
15392
+ inst.mime = (types3, params) => inst.check(_mime(Array.isArray(types3) ? types3 : [
15393
+ types3
15392
15394
  ], params));
15393
15395
  });
15394
15396
  __name(file, "file");
@@ -16905,7 +16907,15 @@ var init_events = __esm({
16905
16907
  eventId: external_exports.string(),
16906
16908
  createdAt: external_exports.coerce.date(),
16907
16909
  occurredAt: external_exports.coerce.date().optional(),
16908
- specVersion: external_exports.number().optional()
16910
+ specVersion: external_exports.number().optional(),
16911
+ /**
16912
+ * Lazy hook resume idempotency key, persisted on `hook_received` events so
16913
+ * the queue consumer can detect that the producer's concurrent direct write
16914
+ * already landed in the run_started preload and skip its own re-ensure.
16915
+ * Mirrors {@link CreateEventParams.resumeId}; absent on all other events and
16916
+ * on legacy (non-lazy) resumes.
16917
+ */
16918
+ resumeId: external_exports.string().optional()
16909
16919
  }));
16910
16920
  }
16911
16921
  });
@@ -17203,7 +17213,9 @@ var init_analytics = __esm({
17203
17213
  retryAfter: NullableDateSchema,
17204
17214
  errorCode: NullableStringSchema,
17205
17215
  workflowCoreVersion: NullableStringSchema,
17206
- workflowEncryptionEnabled: NullableBooleanSchema
17216
+ workflowEncryptionEnabled: NullableBooleanSchema,
17217
+ /** Compute instance of the latest attempt's `step_started`. */
17218
+ computeInstanceId: NullableStringSchema
17207
17219
  });
17208
17220
  AnalyticsEventSchema = external_exports.object({
17209
17221
  runId: external_exports.string(),
@@ -17220,6 +17232,8 @@ var init_analytics = __esm({
17220
17232
  region: NullableStringSchema,
17221
17233
  vercelId: NullableStringSchema,
17222
17234
  requestId: NullableStringSchema,
17235
+ /** Compute instance that wrote the event. See CreateEventParams. */
17236
+ computeInstanceId: NullableStringSchema,
17223
17237
  resumeAt: NullableDateSchema,
17224
17238
  retryAfter: NullableDateSchema,
17225
17239
  errorCode: NullableStringSchema,
@@ -17333,7 +17347,7 @@ function getQueueTopicPrefix(kind, namespace) {
17333
17347
  }
17334
17348
  return "__wkf_workflow_";
17335
17349
  }
17336
- var QueuePrefix, ValidQueueName, QueueNamespace, MessageId, TraceCarrierSchema, RunInputSchema, WorkflowInvokePayloadSchema, HealthCheckPayloadSchema, QueuePayloadSchema;
17350
+ var QueuePrefix, ValidQueueName, QueueNamespace, MessageId, TraceCarrierSchema, RunInputSchema, HookResumeInputSchema, WorkflowInvokePayloadSchema, HealthCheckPayloadSchema, QueuePayloadSchema;
17337
17351
  var init_queue = __esm({
17338
17352
  "../world/dist/queue.js"() {
17339
17353
  "use strict";
@@ -17358,7 +17372,50 @@ var init_queue = __esm({
17358
17372
  * `start()` option so resilient run creation validates the same way as
17359
17373
  * the original `run_created` attempt.
17360
17374
  */
17361
- allowReservedAttributes: external_exports.literal(true).optional()
17375
+ allowReservedAttributes: external_exports.literal(true).optional(),
17376
+ /**
17377
+ * The environment the creating client's writes are attributed to, as
17378
+ * reported by {@link World.getEnvironment} at `start()` time (on Vercel:
17379
+ * `'production' | 'preview' | 'development'`).
17380
+ *
17381
+ * This exists so the resilient-start path can be checked for a tenant
17382
+ * mismatch. `start()` writes `run_created` under the caller's own
17383
+ * credentials while pinning the queue message to a deployment, and those
17384
+ * two can disagree: if the message is consumed by a deployment in a
17385
+ * DIFFERENT environment, that consumer's `run_started` re-creates the run
17386
+ * under ITS tenant, so the same client-minted `wrun_` id ends up existing
17387
+ * in two environments — one stuck pending forever, the other executing.
17388
+ * Carrying the creator's environment lets the consumer compare it against
17389
+ * its own and refuse the delivery instead of forking the run.
17390
+ *
17391
+ * Absent for worlds with no environment dimension (local, Postgres), and
17392
+ * for older SDKs — consumers must treat it as advisory and skip the check
17393
+ * when it is missing.
17394
+ */
17395
+ environment: external_exports.string().optional()
17396
+ });
17397
+ HookResumeInputSchema = external_exports.object({
17398
+ /** Stable idempotency key minted once per `resumeHook()` call. */
17399
+ resumeId: external_exports.string(),
17400
+ /** The hook being resumed. */
17401
+ hookId: external_exports.string(),
17402
+ /**
17403
+ * The hook's token, written into the `hook_received` event's `eventData` so
17404
+ * the consumer's re-ensured event carries the same token the producer would
17405
+ * — replay validates `eventData.token` against the `createHook` token.
17406
+ */
17407
+ token: external_exports.string(),
17408
+ /** The serialized resume payload, reused verbatim from the direct write. */
17409
+ payload: external_exports.unknown(),
17410
+ /**
17411
+ * Content digest of `payload`, computed once by the producer over the
17412
+ * serialized bytes and forwarded verbatim on both the direct `events.create`
17413
+ * and this queue message. The consumer forwards it back to the server so both
17414
+ * writers of the same `resumeId` record an identical digest on the
17415
+ * `(runId, resumeId)` constraint — required because the v4 payload ref is not
17416
+ * content-stable server-side.
17417
+ */
17418
+ payloadDigest: external_exports.string()
17362
17419
  });
17363
17420
  WorkflowInvokePayloadSchema = external_exports.object({
17364
17421
  runId: external_exports.string(),
@@ -17369,6 +17426,14 @@ var init_queue = __esm({
17369
17426
  eventId: external_exports.string(),
17370
17427
  count: external_exports.number().int().positive()
17371
17428
  }).optional(),
17429
+ /**
17430
+ * Re-invocations so far in this chain of stale-snapshot (precondition)
17431
+ * rejections. Counted on the message because the in-process restart budget
17432
+ * lives in the invocation closure and the queue's delivery count resets on
17433
+ * every fresh enqueue, so without this a permanently fenced run would cycle
17434
+ * forever instead of failing.
17435
+ */
17436
+ preconditionReinvocations: external_exports.number().int().positive().optional(),
17372
17437
  /** Number of times this message has been re-enqueued due to server errors (5xx) */
17373
17438
  serverErrorRetryCount: external_exports.number().int().optional(),
17374
17439
  /** Step ID for inline step execution in combined handler. If provided, the flow execution
@@ -17377,7 +17442,13 @@ var init_queue = __esm({
17377
17442
  /** Step name, sent alongside stepId to avoid loading the event log just to resolve the name. */
17378
17443
  stepName: external_exports.string().optional(),
17379
17444
  /** Run creation data, only present on the first queue delivery from start() */
17380
- runInput: RunInputSchema.optional()
17445
+ runInput: RunInputSchema.optional(),
17446
+ /**
17447
+ * Lazy hook resume data, only present when `resumeHook()` takes the parallel
17448
+ * fast path. A consumer that understands this field idempotently ensures the
17449
+ * `hook_received` event exists (keyed by `resumeId`) before replaying.
17450
+ */
17451
+ hookInput: HookResumeInputSchema.optional()
17381
17452
  });
17382
17453
  HealthCheckPayloadSchema = external_exports.object({
17383
17454
  __healthCheck: external_exports.literal(true),
@@ -17402,7 +17473,7 @@ var init_queue = __esm({
17402
17473
  });
17403
17474
 
17404
17475
  // ../world/dist/hooks.js
17405
- var HookResumeContextSchema, HookSchema;
17476
+ var HookResumeContextSchema, HOOK_RESUME_INPUT_VERSION, HOOK_RESUME_DEDUP_VERSION, HookResumeCapabilitiesSchema, HookSchema;
17406
17477
  var init_hooks = __esm({
17407
17478
  "../world/dist/hooks.js"() {
17408
17479
  "use strict";
@@ -17421,7 +17492,25 @@ var init_hooks = __esm({
17421
17492
  // the run or fetching its symmetric key. Absent on runs created before
17422
17493
  // sealed envelopes and on projects with encryption disabled, where the
17423
17494
  // resume falls back to the symmetric per-run key.
17424
- encryptionPublicKey: external_exports.string().optional()
17495
+ encryptionPublicKey: external_exports.string().optional(),
17496
+ // Feature marker: the version of the lazy-hook-resume consumer protocol the
17497
+ // run's creating deployment supports. Present (>= 1) means that deployment's
17498
+ // `@workflow/core` re-ensures the `hook_received` event from the queue
17499
+ // message's `hookInput` on replay, so `resumeHook()`'s parallel fast path is
17500
+ // safe to use. Because a run is pinned to its creating deployment, this
17501
+ // marker is a reliable per-run attestation — unlike inferring support from a
17502
+ // version compare against a predicted release cutoff. Absent on runs created
17503
+ // before the marker existed (fall back to the sequential path).
17504
+ hookResumeInputVersion: external_exports.number().optional()
17505
+ });
17506
+ HOOK_RESUME_INPUT_VERSION = 1;
17507
+ HOOK_RESUME_DEDUP_VERSION = 1;
17508
+ HookResumeCapabilitiesSchema = external_exports.object({
17509
+ // Present (>= HOOK_RESUME_DEDUP_VERSION) when the live backend enforces the
17510
+ // `(runId, resumeId)` dedup constraint AND no server-side kill switch is
17511
+ // active. Absent against an older/rolled-back server or when the kill switch
17512
+ // is engaged.
17513
+ hookResumeDedupVersion: external_exports.number()
17425
17514
  });
17426
17515
  HookSchema = external_exports.object({
17427
17516
  runId: external_exports.string(),
@@ -17439,7 +17528,15 @@ var init_hooks = __esm({
17439
17528
  // Present when the server stored it (new hooks) or synthesized it from the
17440
17529
  // run (old hooks). Absent only against an old server, where the resume path
17441
17530
  // falls back to `runs.get`.
17442
- resumeContext: HookResumeContextSchema.optional()
17531
+ resumeContext: HookResumeContextSchema.optional(),
17532
+ // Backend dedup capability, computed FRESH by the server on every by-token
17533
+ // lookup — RESPONSE-ONLY and TRANSIENT. Never persisted on the hook entity
17534
+ // and never part of `resumeContext`, so a server rollback or kill switch
17535
+ // takes effect on the very next lookup (the field simply stops appearing).
17536
+ // `resumeHook()` gates its parallel fast path on this being present and
17537
+ // current. Absent against an older/rolled-back server or when the kill switch
17538
+ // is active.
17539
+ resumeCapabilities: HookResumeCapabilitiesSchema.optional()
17443
17540
  });
17444
17541
  }
17445
17542
  });
@@ -17501,7 +17598,7 @@ var init_spec_version = __esm({
17501
17598
  });
17502
17599
 
17503
17600
  // ../../node_modules/.pnpm/ulid@3.0.1/node_modules/ulid/dist/node/index.js
17504
- import crypto from "node:crypto";
17601
+ import crypto2 from "node:crypto";
17505
17602
  function randomChar(prng) {
17506
17603
  const randomPosition = Math.floor(prng() * ENCODING_LEN) % ENCODING_LEN;
17507
17604
  return ENCODING.charAt(randomPosition);
@@ -17534,7 +17631,7 @@ function incrementBase32(str) {
17534
17631
  }
17535
17632
  function detectPRNG(root) {
17536
17633
  const rootLookup = detectRoot();
17537
- const globalCrypto = rootLookup && (rootLookup.crypto || rootLookup.msCrypto) || (typeof crypto !== "undefined" ? crypto : null);
17634
+ const globalCrypto = rootLookup && (rootLookup.crypto || rootLookup.msCrypto) || (typeof crypto2 !== "undefined" ? crypto2 : null);
17538
17635
  if (typeof globalCrypto?.getRandomValues === "function") {
17539
17636
  return () => {
17540
17637
  const buffer2 = new Uint8Array(1);
@@ -17543,8 +17640,8 @@ function detectPRNG(root) {
17543
17640
  };
17544
17641
  } else if (typeof globalCrypto?.randomBytes === "function") {
17545
17642
  return () => globalCrypto.randomBytes(1).readUInt8() / 255;
17546
- } else if (crypto?.randomBytes) {
17547
- return () => crypto.randomBytes(1).readUInt8() / 255;
17643
+ } else if (crypto2?.randomBytes) {
17644
+ return () => crypto2.randomBytes(1).readUInt8() / 255;
17548
17645
  }
17549
17646
  throw new ULIDError(ULIDErrorCode.PRNGDetectFailure, "Failed to find a reliable PRNG");
17550
17647
  }
@@ -18345,10 +18442,10 @@ var init_encryption2 = __esm({
18345
18442
  }
18346
18443
  });
18347
18444
 
18348
- // ../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/constants.js
18445
+ // ../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/constants.js
18349
18446
  var UNDEFINED, HOLE, NAN, POSITIVE_INFINITY, NEGATIVE_INFINITY, NEGATIVE_ZERO, SPARSE, MAX_ARRAY_LEN, MAX_ARRAY_INDEX;
18350
18447
  var init_constants = __esm({
18351
- "../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/constants.js"() {
18448
+ "../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/constants.js"() {
18352
18449
  "use strict";
18353
18450
  UNDEFINED = -1;
18354
18451
  HOLE = -2;
@@ -18362,10 +18459,7 @@ var init_constants = __esm({
18362
18459
  }
18363
18460
  });
18364
18461
 
18365
- // ../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/utils.js
18366
- function is_primitive(thing) {
18367
- return thing === null || typeof thing !== "object" && typeof thing !== "function";
18368
- }
18462
+ // ../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/utils.js
18369
18463
  function is_plain_object(thing) {
18370
18464
  const proto = Object.getPrototypeOf(thing);
18371
18465
  return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names;
@@ -18440,19 +18534,22 @@ function is_valid_array_index_string(s) {
18440
18534
  }
18441
18535
  return is_valid_array_index(+s);
18442
18536
  }
18443
- function valid_array_indices(array2) {
18444
- const keys = Object.keys(array2);
18537
+ function array_index_cut(keys) {
18445
18538
  for (var i = keys.length - 1; i >= 0; i--) {
18446
18539
  if (is_valid_array_index_string(keys[i])) {
18447
18540
  break;
18448
18541
  }
18449
18542
  }
18450
- keys.length = i + 1;
18543
+ return i + 1;
18544
+ }
18545
+ function valid_array_indices(array2) {
18546
+ const keys = Object.keys(array2);
18547
+ keys.length = array_index_cut(keys);
18451
18548
  return keys;
18452
18549
  }
18453
18550
  var DevalueError, object_proto_names, is_identifier;
18454
18551
  var init_utils = __esm({
18455
- "../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/utils.js"() {
18552
+ "../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/utils.js"() {
18456
18553
  "use strict";
18457
18554
  init_constants();
18458
18555
  DevalueError = class extends Error {
@@ -18473,7 +18570,6 @@ var init_utils = __esm({
18473
18570
  this.root = root;
18474
18571
  }
18475
18572
  };
18476
- __name(is_primitive, "is_primitive");
18477
18573
  object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
18478
18574
  __name(is_plain_object, "is_plain_object");
18479
18575
  __name(get_type, "get_type");
@@ -18485,11 +18581,12 @@ var init_utils = __esm({
18485
18581
  __name(is_valid_array_index, "is_valid_array_index");
18486
18582
  __name(is_valid_array_len, "is_valid_array_len");
18487
18583
  __name(is_valid_array_index_string, "is_valid_array_index_string");
18584
+ __name(array_index_cut, "array_index_cut");
18488
18585
  __name(valid_array_indices, "valid_array_indices");
18489
18586
  }
18490
18587
  });
18491
18588
 
18492
- // ../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/base64.js
18589
+ // ../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/base64.js
18493
18590
  function encode_native(array_buffer) {
18494
18591
  return new Uint8Array(array_buffer).toBase64();
18495
18592
  }
@@ -18523,7 +18620,7 @@ function decode_legacy(base643) {
18523
18620
  }
18524
18621
  var native, buffer, encode64, decode64;
18525
18622
  var init_base64 = __esm({
18526
- "../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/base64.js"() {
18623
+ "../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/base64.js"() {
18527
18624
  "use strict";
18528
18625
  __name(encode_native, "encode_native");
18529
18626
  __name(decode_native, "decode_native");
@@ -18538,11 +18635,119 @@ var init_base64 = __esm({
18538
18635
  }
18539
18636
  });
18540
18637
 
18541
- // ../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/parse.js
18542
- function parse3(serialized, revivers) {
18543
- return unflatten(JSON.parse(serialized), revivers);
18638
+ // ../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/operations.js
18639
+ function merge_operations(defaults, overrides) {
18640
+ if (!overrides) return defaults;
18641
+ const merged = (
18642
+ /** @type {T} */
18643
+ {}
18644
+ );
18645
+ for (const key of Object.keys(defaults)) {
18646
+ merged[key] = overrides[key] ?? defaults[key];
18647
+ }
18648
+ return merged;
18544
18649
  }
18545
- function unflatten(parsed, revivers) {
18650
+ var NOT_PLAIN, SYMBOL_KEYS, stringify_operations, default_stringify_operations, parse_operations, default_parse_operations;
18651
+ var init_operations = __esm({
18652
+ "../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/operations.js"() {
18653
+ "use strict";
18654
+ init_constants();
18655
+ init_utils();
18656
+ __name(merge_operations, "merge_operations");
18657
+ NOT_PLAIN = Object.freeze({
18658
+ kind: "not-plain"
18659
+ });
18660
+ SYMBOL_KEYS = Object.freeze({
18661
+ kind: "symbol-keys"
18662
+ });
18663
+ stringify_operations = {
18664
+ identify: /* @__PURE__ */ __name((value) => value, "identify"),
18665
+ typeOf: /* @__PURE__ */ __name((value) => value === null ? "null" : typeof value, "typeOf"),
18666
+ toPrimitive: /* @__PURE__ */ __name((value) => value, "toPrimitive"),
18667
+ tagOf: /* @__PURE__ */ __name((value) => get_type(value), "tagOf"),
18668
+ isThenable: /* @__PURE__ */ __name((value) => typeof value.then === "function", "isThenable"),
18669
+ toPromise: /* @__PURE__ */ __name((thenable) => Promise.resolve(thenable), "toPromise"),
18670
+ unbox: /* @__PURE__ */ __name((boxed) => boxed.valueOf(), "unbox"),
18671
+ toISOString: /* @__PURE__ */ __name((date5) => isNaN(date5.getDate()) ? "" : date5.toISOString(), "toISOString"),
18672
+ toStringValue: /* @__PURE__ */ __name((value) => value.toString(), "toStringValue"),
18673
+ regExpInfo: /* @__PURE__ */ __name((regexp) => ({
18674
+ source: regexp.source,
18675
+ flags: regexp.flags
18676
+ }), "regExpInfo"),
18677
+ valuesOf: /* @__PURE__ */ __name((set2) => set2, "valuesOf"),
18678
+ entriesOf: /* @__PURE__ */ __name((map2) => map2, "entriesOf"),
18679
+ viewInfo: /* @__PURE__ */ __name((view) => ({
18680
+ buffer: view.buffer,
18681
+ byteOffset: view.byteOffset,
18682
+ byteLength: view.byteLength,
18683
+ length: view.length,
18684
+ bufferByteLength: view.buffer.byteLength
18685
+ }), "viewInfo"),
18686
+ toArrayBuffer: /* @__PURE__ */ __name((buffer2) => buffer2, "toArrayBuffer"),
18687
+ lengthOf: /* @__PURE__ */ __name((array2) => array2.length, "lengthOf"),
18688
+ hasOwn: /* @__PURE__ */ __name((value, key) => Object.hasOwn(value, key), "hasOwn"),
18689
+ indicesOf: /* @__PURE__ */ __name((array2) => valid_array_indices(array2), "indicesOf"),
18690
+ shapeOf: /* @__PURE__ */ __name((value) => {
18691
+ if (!is_plain_object(value)) return NOT_PLAIN;
18692
+ if (enumerable_symbols(value).length > 0) return SYMBOL_KEYS;
18693
+ return {
18694
+ kind: Object.getPrototypeOf(value) === null ? "null-proto" : "plain",
18695
+ keys: Object.keys(value)
18696
+ };
18697
+ }, "shapeOf"),
18698
+ get: /* @__PURE__ */ __name((value, key) => value[key], "get")
18699
+ };
18700
+ default_stringify_operations = Object.freeze(stringify_operations);
18701
+ parse_operations = {
18702
+ fromPrimitive: /* @__PURE__ */ __name((primitive) => primitive, "fromPrimitive"),
18703
+ fromISOString: /* @__PURE__ */ __name((iso) => new Date(iso), "fromISOString"),
18704
+ fromStringValue: /* @__PURE__ */ __name((tag, text) => {
18705
+ if (tag === "URL") return new URL(text);
18706
+ if (tag === "URLSearchParams") return new URLSearchParams(text);
18707
+ return Temporal[tag.slice(9)].from(text);
18708
+ }, "fromStringValue"),
18709
+ fromArrayBuffer: /* @__PURE__ */ __name((buffer2) => buffer2, "fromArrayBuffer"),
18710
+ fromRegExpInfo: /* @__PURE__ */ __name((source, flags) => new RegExp(source, flags), "fromRegExpInfo"),
18711
+ fromViewInfo: /* @__PURE__ */ __name((tag, buffer2, byteOffset, length) => {
18712
+ const Constructor = (
18713
+ /** @type {any} */
18714
+ globalThis[tag]
18715
+ );
18716
+ return byteOffset !== void 0 ? new Constructor(buffer2, byteOffset, length) : new Constructor(buffer2);
18717
+ }, "fromViewInfo"),
18718
+ box: /* @__PURE__ */ __name((value) => Object(value), "box"),
18719
+ createArray: /* @__PURE__ */ __name((length) => new Array(length), "createArray"),
18720
+ createSparseArray: /* @__PURE__ */ __name((length) => {
18721
+ const array2 = [];
18722
+ array2[MAX_ARRAY_INDEX] = void 0;
18723
+ delete array2[MAX_ARRAY_INDEX];
18724
+ array2.length = length;
18725
+ return array2;
18726
+ }, "createSparseArray"),
18727
+ createObject: /* @__PURE__ */ __name(() => ({}), "createObject"),
18728
+ createNullPrototypeObject: /* @__PURE__ */ __name(() => /* @__PURE__ */ Object.create(null), "createNullPrototypeObject"),
18729
+ createSet: /* @__PURE__ */ __name(() => /* @__PURE__ */ new Set(), "createSet"),
18730
+ createMap: /* @__PURE__ */ __name(() => /* @__PURE__ */ new Map(), "createMap"),
18731
+ set: /* @__PURE__ */ __name((target, key, value) => {
18732
+ target[key] = value;
18733
+ }, "set"),
18734
+ addValue: /* @__PURE__ */ __name((set2, value) => {
18735
+ set2.add(value);
18736
+ }, "addValue"),
18737
+ addEntry: /* @__PURE__ */ __name((map2, key, value) => {
18738
+ map2.set(key, value);
18739
+ }, "addEntry")
18740
+ };
18741
+ default_parse_operations = Object.freeze(parse_operations);
18742
+ }
18743
+ });
18744
+
18745
+ // ../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/parse.js
18746
+ function parse3(serialized, revivers, options) {
18747
+ return unflatten(JSON.parse(serialized), revivers, options);
18748
+ }
18749
+ function unflatten(parsed, revivers, options) {
18750
+ const ops = merge_operations(default_parse_operations, options?.operations);
18546
18751
  if (typeof parsed === "number") return hydrate(parsed, true);
18547
18752
  if (!Array.isArray(parsed) || parsed.length === 0) {
18548
18753
  throw new Error("Invalid input");
@@ -18554,18 +18759,18 @@ function unflatten(parsed, revivers) {
18554
18759
  const hydrated = Array(values.length);
18555
18760
  let hydrating = null;
18556
18761
  function hydrate(index, standalone = false) {
18557
- if (index === UNDEFINED) return void 0;
18558
- if (index === NAN) return NaN;
18559
- if (index === POSITIVE_INFINITY) return Infinity;
18560
- if (index === NEGATIVE_INFINITY) return -Infinity;
18561
- if (index === NEGATIVE_ZERO) return -0;
18762
+ if (index === UNDEFINED) return ops.fromPrimitive(void 0);
18763
+ if (index === NAN) return ops.fromPrimitive(NaN);
18764
+ if (index === POSITIVE_INFINITY) return ops.fromPrimitive(Infinity);
18765
+ if (index === NEGATIVE_INFINITY) return ops.fromPrimitive(-Infinity);
18766
+ if (index === NEGATIVE_ZERO) return ops.fromPrimitive(-0);
18562
18767
  if (standalone || typeof index !== "number") {
18563
18768
  throw new Error(`Invalid input`);
18564
18769
  }
18565
18770
  if (index in hydrated) return hydrated[index];
18566
18771
  const value = values[index];
18567
18772
  if (!value || typeof value !== "object") {
18568
- hydrated[index] = value;
18773
+ hydrated[index] = ops.fromPrimitive(value);
18569
18774
  } else if (Array.isArray(value)) {
18570
18775
  if (typeof value[0] === "string") {
18571
18776
  const type = value[0];
@@ -18575,6 +18780,9 @@ function unflatten(parsed, revivers) {
18575
18780
  if (typeof i !== "number") {
18576
18781
  i = values.push(value[1]) - 1;
18577
18782
  }
18783
+ if (Object.hasOwn(hydrated, i)) {
18784
+ return hydrated[index] = reviver(hydrated[i]);
18785
+ }
18578
18786
  hydrating ??= /* @__PURE__ */ new Set();
18579
18787
  if (hydrating.has(i)) {
18580
18788
  throw new Error("Invalid circular reference");
@@ -18586,44 +18794,44 @@ function unflatten(parsed, revivers) {
18586
18794
  }
18587
18795
  switch (type) {
18588
18796
  case "Date":
18589
- hydrated[index] = new Date(value[1]);
18797
+ hydrated[index] = ops.fromISOString(value[1]);
18590
18798
  break;
18591
18799
  case "Set":
18592
- const set2 = /* @__PURE__ */ new Set();
18800
+ const set2 = ops.createSet();
18593
18801
  hydrated[index] = set2;
18594
18802
  for (let i = 1; i < value.length; i += 1) {
18595
- set2.add(hydrate(value[i]));
18803
+ ops.addValue(set2, hydrate(value[i]));
18596
18804
  }
18597
18805
  break;
18598
18806
  case "Map":
18599
- const map2 = /* @__PURE__ */ new Map();
18807
+ const map2 = ops.createMap();
18600
18808
  hydrated[index] = map2;
18601
18809
  for (let i = 1; i < value.length; i += 2) {
18602
- map2.set(hydrate(value[i]), hydrate(value[i + 1]));
18810
+ ops.addEntry(map2, hydrate(value[i]), hydrate(value[i + 1]));
18603
18811
  }
18604
18812
  break;
18605
18813
  case "RegExp":
18606
- hydrated[index] = new RegExp(value[1], value[2]);
18814
+ hydrated[index] = ops.fromRegExpInfo(value[1], value[2]);
18607
18815
  break;
18608
18816
  case "Object": {
18609
18817
  const wrapped_index = value[1];
18610
18818
  if (typeof values[wrapped_index] === "object" && values[wrapped_index][0] !== "BigInt") {
18611
18819
  throw new Error("Invalid input");
18612
18820
  }
18613
- hydrated[index] = Object(hydrate(wrapped_index));
18821
+ hydrated[index] = ops.box(hydrate(wrapped_index));
18614
18822
  break;
18615
18823
  }
18616
18824
  case "BigInt":
18617
- hydrated[index] = BigInt(value[1]);
18825
+ hydrated[index] = ops.fromPrimitive(BigInt(value[1]));
18618
18826
  break;
18619
18827
  case "null":
18620
- const obj = /* @__PURE__ */ Object.create(null);
18828
+ const obj = ops.createNullPrototypeObject();
18621
18829
  hydrated[index] = obj;
18622
18830
  for (let i = 1; i < value.length; i += 2) {
18623
18831
  if (value[i] === "__proto__") {
18624
18832
  throw new Error("Cannot parse an object with a `__proto__` property");
18625
18833
  }
18626
- obj[value[i]] = hydrate(value[i + 1]);
18834
+ ops.set(obj, value[i], hydrate(value[i + 1]));
18627
18835
  }
18628
18836
  break;
18629
18837
  case "Int8Array":
@@ -18642,9 +18850,8 @@ function unflatten(parsed, revivers) {
18642
18850
  if (values[value[1]][0] !== "ArrayBuffer") {
18643
18851
  throw new Error("Invalid data");
18644
18852
  }
18645
- const TypedArrayConstructor = globalThis[type];
18646
18853
  const buffer2 = hydrate(value[1]);
18647
- hydrated[index] = value[2] !== void 0 ? new TypedArrayConstructor(buffer2, value[2], value[3]) : new TypedArrayConstructor(buffer2);
18854
+ hydrated[index] = ops.fromViewInfo(type, buffer2, value[2], value[3]);
18648
18855
  break;
18649
18856
  }
18650
18857
  case "ArrayBuffer": {
@@ -18652,10 +18859,11 @@ function unflatten(parsed, revivers) {
18652
18859
  if (typeof base643 !== "string") {
18653
18860
  throw new Error("Invalid ArrayBuffer encoding");
18654
18861
  }
18655
- const arraybuffer = decode64(base643);
18656
- hydrated[index] = arraybuffer;
18862
+ hydrated[index] = ops.fromArrayBuffer(decode64(base643));
18657
18863
  break;
18658
18864
  }
18865
+ case "URL":
18866
+ case "URLSearchParams":
18659
18867
  case "Temporal.Duration":
18660
18868
  case "Temporal.Instant":
18661
18869
  case "Temporal.PlainDate":
@@ -18664,18 +18872,7 @@ function unflatten(parsed, revivers) {
18664
18872
  case "Temporal.PlainMonthDay":
18665
18873
  case "Temporal.PlainYearMonth":
18666
18874
  case "Temporal.ZonedDateTime": {
18667
- const temporalName = type.slice(9);
18668
- hydrated[index] = Temporal[temporalName].from(value[1]);
18669
- break;
18670
- }
18671
- case "URL": {
18672
- const url2 = new URL(value[1]);
18673
- hydrated[index] = url2;
18674
- break;
18675
- }
18676
- case "URLSearchParams": {
18677
- const url2 = new URLSearchParams(value[1]);
18678
- hydrated[index] = url2;
18875
+ hydrated[index] = ops.fromStringValue(type, value[1]);
18679
18876
  break;
18680
18877
  }
18681
18878
  default:
@@ -18686,36 +18883,32 @@ function unflatten(parsed, revivers) {
18686
18883
  if (!is_valid_array_len(len)) {
18687
18884
  throw new Error("Invalid input");
18688
18885
  }
18689
- const array2 = [];
18886
+ const array2 = ops.createSparseArray(len);
18690
18887
  hydrated[index] = array2;
18691
- array2[MAX_ARRAY_INDEX] = void 0;
18692
- delete array2[MAX_ARRAY_INDEX];
18693
18888
  for (let i = 2; i < value.length; i += 2) {
18694
18889
  const idx = value[i];
18695
18890
  if (!is_valid_array_index(idx) || idx >= len) {
18696
18891
  throw new Error("Invalid input");
18697
18892
  }
18698
- array2[idx] = hydrate(value[i + 1]);
18893
+ ops.set(array2, idx, hydrate(value[i + 1]));
18699
18894
  }
18700
- array2.length = len;
18701
18895
  } else {
18702
- const array2 = new Array(value.length);
18896
+ const array2 = ops.createArray(value.length);
18703
18897
  hydrated[index] = array2;
18704
18898
  for (let i = 0; i < value.length; i += 1) {
18705
18899
  const n = value[i];
18706
18900
  if (n === HOLE) continue;
18707
- array2[i] = hydrate(n);
18901
+ ops.set(array2, i, hydrate(n));
18708
18902
  }
18709
18903
  }
18710
18904
  } else {
18711
- const object2 = {};
18905
+ const object2 = ops.createObject();
18712
18906
  hydrated[index] = object2;
18713
18907
  for (const key of Object.keys(value)) {
18714
18908
  if (key === "__proto__") {
18715
18909
  throw new Error("Cannot parse an object with a `__proto__` property");
18716
18910
  }
18717
- const n = value[key];
18718
- object2[key] = hydrate(n);
18911
+ ops.set(object2, key, hydrate(value[key]));
18719
18912
  }
18720
18913
  }
18721
18914
  return hydrated[index];
@@ -18724,22 +18917,24 @@ function unflatten(parsed, revivers) {
18724
18917
  return hydrate(0);
18725
18918
  }
18726
18919
  var init_parse3 = __esm({
18727
- "../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/parse.js"() {
18920
+ "../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/parse.js"() {
18728
18921
  "use strict";
18729
18922
  init_base64();
18730
18923
  init_constants();
18924
+ init_operations();
18731
18925
  init_utils();
18732
18926
  __name(parse3, "parse");
18733
18927
  __name(unflatten, "unflatten");
18734
18928
  }
18735
18929
  });
18736
18930
 
18737
- // ../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/stringify.js
18738
- function stringify(value, reducers) {
18739
- const stringified = run(false, value, reducers);
18931
+ // ../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/stringify.js
18932
+ function stringify(value, reducers, options) {
18933
+ const stringified = run(false, value, reducers, options);
18740
18934
  return typeof stringified === "string" ? stringified : `[${stringified.join(",")}]`;
18741
18935
  }
18742
- function run(async, value, reducers) {
18936
+ function run(async, value, reducers, options) {
18937
+ const ops = merge_operations(default_stringify_operations, options?.operations);
18743
18938
  const stringified = [];
18744
18939
  const indexes = /* @__PURE__ */ new Map();
18745
18940
  const custom2 = [];
@@ -18754,17 +18949,24 @@ function run(async, value, reducers) {
18754
18949
  const keys = [];
18755
18950
  let p = 0;
18756
18951
  function flatten(thing, index2) {
18757
- if (thing === void 0) return UNDEFINED;
18758
- if (Number.isNaN(thing)) return NAN;
18759
- if (thing === Infinity) return POSITIVE_INFINITY;
18760
- if (thing === -Infinity) return NEGATIVE_INFINITY;
18761
- if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO;
18762
- if (indexes.has(thing)) return (
18952
+ const type = ops.typeOf(thing);
18953
+ if (type === "undefined") return UNDEFINED;
18954
+ let number4;
18955
+ if (type === "number") {
18956
+ number4 = /** @type {number} */
18957
+ ops.toPrimitive(thing);
18958
+ if (Number.isNaN(number4)) return NAN;
18959
+ if (number4 === Infinity) return POSITIVE_INFINITY;
18960
+ if (number4 === -Infinity) return NEGATIVE_INFINITY;
18961
+ if (number4 === 0 && 1 / number4 < 0) return NEGATIVE_ZERO;
18962
+ }
18963
+ const id = ops.identify(thing);
18964
+ if (indexes.has(id)) return (
18763
18965
  /** @type {number} */
18764
- indexes.get(thing)
18966
+ indexes.get(id)
18765
18967
  );
18766
18968
  index2 ??= p++;
18767
- indexes.set(thing, index2);
18969
+ indexes.set(id, index2);
18768
18970
  for (const { key, fn } of custom2) {
18769
18971
  const value2 = fn(thing);
18770
18972
  if (value2) {
@@ -18772,71 +18974,68 @@ function run(async, value, reducers) {
18772
18974
  return index2;
18773
18975
  }
18774
18976
  }
18775
- if (typeof thing === "function") {
18977
+ if (type === "function") {
18776
18978
  throw new DevalueError(`Cannot stringify a function`, keys, thing, value);
18777
- } else if (typeof thing === "symbol") {
18979
+ } else if (type === "symbol") {
18778
18980
  throw new DevalueError(`Cannot stringify a Symbol primitive`, keys, thing, value);
18779
18981
  }
18780
18982
  let str = "";
18781
- if (is_primitive(thing)) {
18782
- str = stringify_primitive(thing);
18783
- } else if (typeof thing.then === "function") {
18983
+ if (type !== "object") {
18984
+ str = stringify_primitive(type === "number" ? number4 : ops.toPrimitive(thing));
18985
+ } else if (ops.isThenable(thing)) {
18784
18986
  if (!async) {
18785
18987
  throw new DevalueError(`Cannot stringify a Promise or thenable \u2014 use stringifyAsync instead`, keys, thing, value);
18786
18988
  }
18787
- str = Promise.resolve(thing).then((value2) => {
18989
+ str = ops.toPromise(thing).then((value2) => {
18788
18990
  const i = flatten(value2, index2);
18789
18991
  if (i < 0) stringified[index2] = i;
18790
18992
  });
18791
18993
  } else {
18792
- const type = get_type(thing);
18793
- switch (type) {
18994
+ const tag = ops.tagOf(thing);
18995
+ switch (tag) {
18794
18996
  case "Number":
18795
18997
  case "String":
18796
18998
  case "Boolean":
18797
18999
  case "BigInt":
18798
- str = `["Object",${flatten(thing.valueOf())}]`;
19000
+ str = `["Object",${flatten(ops.unbox(thing))}]`;
18799
19001
  break;
18800
19002
  case "Date":
18801
- const valid = !isNaN(thing.getDate());
18802
- str = `["Date","${valid ? thing.toISOString() : ""}"]`;
19003
+ str = `["Date","${ops.toISOString(thing)}"]`;
18803
19004
  break;
18804
19005
  case "URL":
18805
- str = `["URL",${stringify_string(thing.toString())}]`;
19006
+ str = `["URL",${stringify_string(ops.toStringValue(thing))}]`;
18806
19007
  break;
18807
19008
  case "URLSearchParams":
18808
- str = `["URLSearchParams",${stringify_string(thing.toString())}]`;
19009
+ str = `["URLSearchParams",${stringify_string(ops.toStringValue(thing))}]`;
18809
19010
  break;
18810
19011
  case "RegExp":
18811
- const { source, flags } = thing;
19012
+ const { source, flags } = ops.regExpInfo(thing);
18812
19013
  str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
18813
19014
  break;
18814
19015
  case "Array": {
18815
19016
  let mostly_dense = false;
19017
+ const length = ops.lengthOf(thing);
18816
19018
  str = "[";
18817
- for (let i = 0; i < thing.length; i += 1) {
19019
+ for (let i = 0; i < length; i += 1) {
18818
19020
  if (i > 0) str += ",";
18819
- if (Object.hasOwn(thing, i)) {
19021
+ if (ops.hasOwn(thing, i)) {
18820
19022
  keys.push(`[${i}]`);
18821
- str += flatten(thing[i]);
19023
+ str += flatten(ops.get(thing, i));
18822
19024
  keys.pop();
18823
19025
  } else if (mostly_dense) {
18824
19026
  str += HOLE;
18825
19027
  } else {
18826
- const populated_keys = valid_array_indices(
18827
- /** @type {any[]} */
18828
- thing
18829
- );
19028
+ const populated_keys = ops.indicesOf(thing);
18830
19029
  const population = populated_keys.length;
18831
- const d = String(thing.length).length;
18832
- const hole_cost = (thing.length - population) * 3;
19030
+ const d = String(length).length;
19031
+ const hole_cost = (length - population) * 3;
18833
19032
  const sparse_cost = 4 + d + population * (d + 1);
18834
19033
  if (hole_cost > sparse_cost) {
18835
- str = "[" + SPARSE + "," + thing.length;
19034
+ str = "[" + SPARSE + "," + length;
18836
19035
  for (let j = 0; j < populated_keys.length; j++) {
18837
19036
  const key = populated_keys[j];
18838
19037
  keys.push(`[${key}]`);
18839
- str += "," + key + "," + flatten(thing[key]);
19038
+ str += "," + key + "," + flatten(ops.get(thing, key));
18840
19039
  keys.pop();
18841
19040
  }
18842
19041
  break;
@@ -18851,15 +19050,17 @@ function run(async, value, reducers) {
18851
19050
  }
18852
19051
  case "Set":
18853
19052
  str = '["Set"';
18854
- for (const value2 of thing) {
19053
+ for (const value2 of ops.valuesOf(thing)) {
18855
19054
  str += `,${flatten(value2)}`;
18856
19055
  }
18857
19056
  str += "]";
18858
19057
  break;
18859
19058
  case "Map":
18860
19059
  str = '["Map"';
18861
- for (const [key, value2] of thing) {
18862
- keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : "..."})`);
19060
+ for (const [key, value2] of ops.entriesOf(thing)) {
19061
+ const key_type = ops.typeOf(key);
19062
+ const key_is_primitive = key_type !== "object" && key_type !== "function" && key_type !== "symbol";
19063
+ keys.push(`.get(${key_is_primitive ? stringify_primitive(ops.toPrimitive(key)) : "..."})`);
18863
19064
  str += `,${flatten(key)},${flatten(value2)}`;
18864
19065
  keys.pop();
18865
19066
  }
@@ -18876,19 +19077,26 @@ function run(async, value, reducers) {
18876
19077
  case "Float32Array":
18877
19078
  case "Float64Array":
18878
19079
  case "BigInt64Array":
18879
- case "BigUint64Array":
19080
+ case "BigUint64Array": {
19081
+ const info = ops.viewInfo(thing);
19082
+ str = '["' + tag + '",' + flatten(info.buffer);
19083
+ if (info.byteLength !== info.bufferByteLength) {
19084
+ str += `,${info.byteOffset},${info.length}`;
19085
+ }
19086
+ str += "]";
19087
+ break;
19088
+ }
18880
19089
  case "DataView": {
18881
- const typedArray = thing;
18882
- str = '["' + type + '",' + flatten(typedArray.buffer);
18883
- if (typedArray.byteLength !== typedArray.buffer.byteLength) {
18884
- str += `,${typedArray.byteOffset},${typedArray.length}`;
19090
+ const info = ops.viewInfo(thing);
19091
+ str = '["' + tag + '",' + flatten(info.buffer);
19092
+ if (info.byteLength !== info.bufferByteLength) {
19093
+ str += `,${info.byteOffset},${info.byteLength}`;
18885
19094
  }
18886
19095
  str += "]";
18887
19096
  break;
18888
19097
  }
18889
19098
  case "ArrayBuffer": {
18890
- const arraybuffer = thing;
18891
- const base643 = encode64(arraybuffer);
19099
+ const base643 = encode64(ops.toArrayBuffer(thing));
18892
19100
  str = `["ArrayBuffer","${base643}"]`;
18893
19101
  break;
18894
19102
  }
@@ -18900,41 +19108,43 @@ function run(async, value, reducers) {
18900
19108
  case "Temporal.PlainMonthDay":
18901
19109
  case "Temporal.PlainYearMonth":
18902
19110
  case "Temporal.ZonedDateTime":
18903
- str = `["${type}",${stringify_string(thing.toString())}]`;
19111
+ str = `["${tag}",${stringify_string(ops.toStringValue(thing))}]`;
18904
19112
  break;
18905
- default:
18906
- if (!is_plain_object(thing)) {
19113
+ default: {
19114
+ const shape = ops.shapeOf(thing);
19115
+ if (shape.kind === "not-plain") {
18907
19116
  throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys, thing, value);
18908
19117
  }
18909
- if (enumerable_symbols(thing).length > 0) {
19118
+ if (shape.kind === "symbol-keys") {
18910
19119
  throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys, thing, value);
18911
19120
  }
18912
- if (Object.getPrototypeOf(thing) === null) {
19121
+ if (shape.kind === "null-proto") {
18913
19122
  str = '["null"';
18914
- for (const key of Object.keys(thing)) {
19123
+ for (const key of shape.keys) {
18915
19124
  if (key === "__proto__") {
18916
19125
  throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
18917
19126
  }
18918
19127
  keys.push(stringify_key(key));
18919
- str += `,${stringify_string(key)},${flatten(thing[key])}`;
19128
+ str += `,${stringify_string(key)},${flatten(ops.get(thing, key))}`;
18920
19129
  keys.pop();
18921
19130
  }
18922
19131
  str += "]";
18923
19132
  } else {
18924
19133
  str = "{";
18925
19134
  let started = false;
18926
- for (const key of Object.keys(thing)) {
19135
+ for (const key of shape.keys) {
18927
19136
  if (key === "__proto__") {
18928
19137
  throw new DevalueError(`Cannot stringify objects with __proto__ keys`, keys, thing, value);
18929
19138
  }
18930
19139
  if (started) str += ",";
18931
19140
  started = true;
18932
19141
  keys.push(stringify_key(key));
18933
- str += `${stringify_string(key)}:${flatten(thing[key])}`;
19142
+ str += `${stringify_string(key)}:${flatten(ops.get(thing, key))}`;
18934
19143
  keys.pop();
18935
19144
  }
18936
19145
  str += "}";
18937
19146
  }
19147
+ }
18938
19148
  }
18939
19149
  }
18940
19150
  stringified[index2] = str;
@@ -18954,23 +19164,25 @@ function stringify_primitive(thing) {
18954
19164
  return String(thing);
18955
19165
  }
18956
19166
  var init_stringify = __esm({
18957
- "../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/src/stringify.js"() {
19167
+ "../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/src/stringify.js"() {
18958
19168
  "use strict";
18959
19169
  init_utils();
18960
19170
  init_constants();
18961
19171
  init_base64();
19172
+ init_operations();
18962
19173
  __name(stringify, "stringify");
18963
19174
  __name(run, "run");
18964
19175
  __name(stringify_primitive, "stringify_primitive");
18965
19176
  }
18966
19177
  });
18967
19178
 
18968
- // ../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/index.js
19179
+ // ../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/index.js
18969
19180
  var init_devalue = __esm({
18970
- "../../node_modules/.pnpm/devalue@5.8.1/node_modules/devalue/index.js"() {
19181
+ "../../node_modules/.pnpm/devalue@5.9.0/node_modules/devalue/index.js"() {
18971
19182
  "use strict";
18972
19183
  init_parse3();
18973
19184
  init_stringify();
19185
+ init_operations();
18974
19186
  init_utils();
18975
19187
  }
18976
19188
  });
@@ -19315,6 +19527,326 @@ var init_get_world_lazy = __esm({
19315
19527
  }
19316
19528
  });
19317
19529
 
19530
+ // ../core/dist/serialization/hardened.js
19531
+ import { types } from "node:util";
19532
+ function withGuestCodeStats(stats, fn) {
19533
+ const previousStats = activeStats;
19534
+ const previousProxies = reportedProxies;
19535
+ activeStats = stats ?? null;
19536
+ reportedProxies = stats ? /* @__PURE__ */ new WeakSet() : null;
19537
+ try {
19538
+ return fn();
19539
+ } finally {
19540
+ activeStats = previousStats;
19541
+ reportedProxies = previousProxies;
19542
+ }
19543
+ }
19544
+ function isUseStepClosureFn(fn) {
19545
+ return typeof fn === "function" && useStepClosureFns.has(fn);
19546
+ }
19547
+ function recordGuestCode(kind, detail) {
19548
+ if (!activeStats) return;
19549
+ const execution = {
19550
+ kind
19551
+ };
19552
+ if (detail !== void 0) execution.detail = detail;
19553
+ activeStats.executions.push(execution);
19554
+ }
19555
+ function recordProxy(value) {
19556
+ if (!activeStats || !reportedProxies) return;
19557
+ if (reportedProxies.has(value)) return;
19558
+ reportedProxies.add(value);
19559
+ recordGuestCode("proxy");
19560
+ }
19561
+ function protoGetter(prototype, key) {
19562
+ const getter = Object.getOwnPropertyDescriptor(prototype, key)?.get;
19563
+ if (!getter) {
19564
+ throw new Error(`Missing intrinsic getter: ${String(key)}`);
19565
+ }
19566
+ return uncurryThis(getter);
19567
+ }
19568
+ function isEngineAccessor(getter) {
19569
+ if (isProxy(getter)) return false;
19570
+ const name = Object.getOwnPropertyDescriptor(getter, "name")?.value;
19571
+ if (typeof name === "string" && name.startsWith("bound ")) return false;
19572
+ return functionToString(getter).endsWith("{ [native code] }") || Reflect.getPrototypeOf(getter) === Function.prototype;
19573
+ }
19574
+ function readProperty(value, key) {
19575
+ if (value === null || typeof value !== "object" && typeof value !== "function") {
19576
+ return void 0;
19577
+ }
19578
+ if (isProxy(value)) {
19579
+ recordProxy(value);
19580
+ return value[key];
19581
+ }
19582
+ let current = value;
19583
+ while (current !== null) {
19584
+ if (isProxy(current)) {
19585
+ recordProxy(current);
19586
+ return value[key];
19587
+ }
19588
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
19589
+ if (descriptor) {
19590
+ if ("value" in descriptor) return descriptor.value;
19591
+ if (descriptor.get) {
19592
+ if (!isEngineAccessor(descriptor.get)) {
19593
+ recordGuestCode("getter", String(key));
19594
+ }
19595
+ return descriptor.get.call(value);
19596
+ }
19597
+ return void 0;
19598
+ }
19599
+ current = Reflect.getPrototypeOf(current);
19600
+ }
19601
+ return void 0;
19602
+ }
19603
+ function hasProperty(value, key) {
19604
+ if (value === null || typeof value !== "object" && typeof value !== "function") {
19605
+ return false;
19606
+ }
19607
+ if (isProxy(value)) {
19608
+ recordProxy(value);
19609
+ return key in value;
19610
+ }
19611
+ let current = value;
19612
+ while (current !== null) {
19613
+ if (isProxy(current)) {
19614
+ recordProxy(current);
19615
+ return key in value;
19616
+ }
19617
+ if (Object.getOwnPropertyDescriptor(current, key)) return true;
19618
+ current = Reflect.getPrototypeOf(current);
19619
+ }
19620
+ return false;
19621
+ }
19622
+ function isInstanceOfPrototype(value, prototype) {
19623
+ if (!prototype) return false;
19624
+ if (value === null || typeof value !== "object") return false;
19625
+ if (isProxy(value)) recordProxy(value);
19626
+ let current = Reflect.getPrototypeOf(value);
19627
+ while (current !== null) {
19628
+ if (current === prototype) return true;
19629
+ if (isProxy(current)) recordProxy(current);
19630
+ current = Reflect.getPrototypeOf(current);
19631
+ }
19632
+ return false;
19633
+ }
19634
+ function urlHref(value) {
19635
+ if (isProxy(value)) {
19636
+ recordProxy(value);
19637
+ return value.href;
19638
+ }
19639
+ return urlHrefGetter(value);
19640
+ }
19641
+ function urlSearchParamsToString(value) {
19642
+ if (isProxy(value)) {
19643
+ recordProxy(value);
19644
+ return String(value);
19645
+ }
19646
+ return urlSearchParamsToStringMethod(value);
19647
+ }
19648
+ function headersToEntries(value) {
19649
+ if (isProxy(value)) {
19650
+ recordProxy(value);
19651
+ return Array.from(value);
19652
+ }
19653
+ return [
19654
+ ...headersIterator(value)
19655
+ ];
19656
+ }
19657
+ function mapToEntries(value) {
19658
+ return [
19659
+ ...mapEntries(value)
19660
+ ];
19661
+ }
19662
+ function setToValues(value) {
19663
+ return [
19664
+ ...setValues(value)
19665
+ ];
19666
+ }
19667
+ function viewInfo(value) {
19668
+ if (types.isDataView(value)) {
19669
+ return {
19670
+ buffer: dataViewBuffer(value),
19671
+ byteOffset: dataViewByteOffset(value),
19672
+ byteLength: dataViewByteLength(value)
19673
+ };
19674
+ }
19675
+ return {
19676
+ buffer: typedArrayBuffer(value),
19677
+ byteOffset: typedArrayByteOffset(value),
19678
+ byteLength: typedArrayByteLength(value)
19679
+ };
19680
+ }
19681
+ function brandOf(value) {
19682
+ if (types.isDate(value)) return "Date";
19683
+ if (types.isRegExp(value)) return "RegExp";
19684
+ if (types.isMap(value)) return "Map";
19685
+ if (types.isSet(value)) return "Set";
19686
+ if (Array.isArray(value)) return "Array";
19687
+ if (types.isTypedArray(value)) {
19688
+ const tag = typedArrayTag(value);
19689
+ return tag !== void 0 && KNOWN_VIEW_TAGS.has(tag) ? tag : void 0;
19690
+ }
19691
+ if (types.isDataView(value)) return "DataView";
19692
+ if (types.isArrayBuffer(value)) return "ArrayBuffer";
19693
+ if (types.isSharedArrayBuffer(value)) return "SharedArrayBuffer";
19694
+ if (types.isNumberObject(value)) return "Number";
19695
+ if (types.isStringObject(value)) return "String";
19696
+ if (types.isBooleanObject(value)) return "Boolean";
19697
+ if (types.isBigIntObject(value)) return "BigInt";
19698
+ if (isInstanceOfPrototype(value, URL.prototype)) return "URL";
19699
+ if (isInstanceOfPrototype(value, URLSearchParams.prototype)) {
19700
+ return "URLSearchParams";
19701
+ }
19702
+ return void 0;
19703
+ }
19704
+ function readToStringTag(value) {
19705
+ const tag = readProperty(value, Symbol.toStringTag);
19706
+ return typeof tag === "string" ? tag : void 0;
19707
+ }
19708
+ var activeStats, reportedProxies, useStepClosureFns, uncurryThis, dateGetDate, dateGetTime, dateToISOString, regExpSource, regExpFlags, arrayBufferByteLength, mapEntries, setValues, numberValueOf, stringValueOf, booleanValueOf, bigIntValueOf, TypedArrayPrototype, typedArrayTag, typedArrayBuffer, typedArrayByteOffset, typedArrayByteLength, typedArrayLength, dataViewBuffer, dataViewByteOffset, dataViewByteLength, sharedArrayBufferByteLength, headersIterator, urlHrefGetter, urlSearchParamsToStringMethod, isProxy, functionToString, KNOWN_VIEW_TAGS, BRAND_DECIDED_TAGS, hardenedStringifyOperations;
19709
+ var init_hardened = __esm({
19710
+ "../core/dist/serialization/hardened.js"() {
19711
+ "use strict";
19712
+ init_devalue();
19713
+ activeStats = null;
19714
+ reportedProxies = null;
19715
+ __name(withGuestCodeStats, "withGuestCodeStats");
19716
+ useStepClosureFns = /* @__PURE__ */ new WeakSet();
19717
+ __name(isUseStepClosureFn, "isUseStepClosureFn");
19718
+ __name(recordGuestCode, "recordGuestCode");
19719
+ __name(recordProxy, "recordProxy");
19720
+ uncurryThis = Function.prototype.bind.bind(Function.prototype.call);
19721
+ __name(protoGetter, "protoGetter");
19722
+ dateGetDate = uncurryThis(Date.prototype.getDate);
19723
+ dateGetTime = uncurryThis(Date.prototype.getTime);
19724
+ dateToISOString = uncurryThis(Date.prototype.toISOString);
19725
+ regExpSource = protoGetter(RegExp.prototype, "source");
19726
+ regExpFlags = protoGetter(RegExp.prototype, "flags");
19727
+ arrayBufferByteLength = protoGetter(ArrayBuffer.prototype, "byteLength");
19728
+ mapEntries = uncurryThis(Map.prototype.entries);
19729
+ setValues = uncurryThis(Set.prototype.values);
19730
+ numberValueOf = uncurryThis(Number.prototype.valueOf);
19731
+ stringValueOf = uncurryThis(String.prototype.valueOf);
19732
+ booleanValueOf = uncurryThis(Boolean.prototype.valueOf);
19733
+ bigIntValueOf = uncurryThis(BigInt.prototype.valueOf);
19734
+ TypedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
19735
+ typedArrayTag = protoGetter(TypedArrayPrototype, Symbol.toStringTag);
19736
+ typedArrayBuffer = protoGetter(TypedArrayPrototype, "buffer");
19737
+ typedArrayByteOffset = protoGetter(TypedArrayPrototype, "byteOffset");
19738
+ typedArrayByteLength = protoGetter(TypedArrayPrototype, "byteLength");
19739
+ typedArrayLength = protoGetter(TypedArrayPrototype, "length");
19740
+ dataViewBuffer = protoGetter(DataView.prototype, "buffer");
19741
+ dataViewByteOffset = protoGetter(DataView.prototype, "byteOffset");
19742
+ dataViewByteLength = protoGetter(DataView.prototype, "byteLength");
19743
+ sharedArrayBufferByteLength = protoGetter(SharedArrayBuffer.prototype, "byteLength");
19744
+ headersIterator = uncurryThis(Headers.prototype[Symbol.iterator]);
19745
+ urlHrefGetter = protoGetter(URL.prototype, "href");
19746
+ urlSearchParamsToStringMethod = uncurryThis(URLSearchParams.prototype.toString);
19747
+ ({ isProxy } = types);
19748
+ functionToString = uncurryThis(Function.prototype.toString);
19749
+ __name(isEngineAccessor, "isEngineAccessor");
19750
+ __name(readProperty, "readProperty");
19751
+ __name(hasProperty, "hasProperty");
19752
+ __name(isInstanceOfPrototype, "isInstanceOfPrototype");
19753
+ __name(urlHref, "urlHref");
19754
+ __name(urlSearchParamsToString, "urlSearchParamsToString");
19755
+ __name(headersToEntries, "headersToEntries");
19756
+ __name(mapToEntries, "mapToEntries");
19757
+ __name(setToValues, "setToValues");
19758
+ __name(viewInfo, "viewInfo");
19759
+ KNOWN_VIEW_TAGS = /* @__PURE__ */ new Set([
19760
+ "Int8Array",
19761
+ "Uint8Array",
19762
+ "Uint8ClampedArray",
19763
+ "Int16Array",
19764
+ "Uint16Array",
19765
+ "Float16Array",
19766
+ "Int32Array",
19767
+ "Uint32Array",
19768
+ "Float32Array",
19769
+ "Float64Array",
19770
+ "BigInt64Array",
19771
+ "BigUint64Array"
19772
+ ]);
19773
+ BRAND_DECIDED_TAGS = /* @__PURE__ */ new Set([
19774
+ "Date",
19775
+ "RegExp",
19776
+ "Map",
19777
+ "Set",
19778
+ "Array",
19779
+ "DataView",
19780
+ "ArrayBuffer",
19781
+ "SharedArrayBuffer",
19782
+ "Number",
19783
+ "String",
19784
+ "Boolean",
19785
+ "BigInt",
19786
+ "URL",
19787
+ "URLSearchParams",
19788
+ ...KNOWN_VIEW_TAGS
19789
+ ]);
19790
+ __name(brandOf, "brandOf");
19791
+ __name(readToStringTag, "readToStringTag");
19792
+ hardenedStringifyOperations = {
19793
+ tagOf: /* @__PURE__ */ __name((value) => {
19794
+ if (isProxy(value)) {
19795
+ recordProxy(value);
19796
+ return default_stringify_operations.tagOf(value);
19797
+ }
19798
+ const brand = brandOf(value);
19799
+ if (brand !== void 0) return brand;
19800
+ const tag = readToStringTag(value);
19801
+ if (tag === void 0 || BRAND_DECIDED_TAGS.has(tag)) return "Object";
19802
+ return tag;
19803
+ }, "tagOf"),
19804
+ isThenable: /* @__PURE__ */ __name((value) => {
19805
+ if (types.isPromise(value)) return true;
19806
+ return typeof readProperty(value, "then") === "function";
19807
+ }, "isThenable"),
19808
+ unbox: /* @__PURE__ */ __name((boxed) => {
19809
+ if (types.isNumberObject(boxed)) return numberValueOf(boxed);
19810
+ if (types.isStringObject(boxed)) return stringValueOf(boxed);
19811
+ if (types.isBooleanObject(boxed)) return booleanValueOf(boxed);
19812
+ return bigIntValueOf(boxed);
19813
+ }, "unbox"),
19814
+ toISOString: /* @__PURE__ */ __name((date5) => Number.isNaN(dateGetDate(date5)) ? "" : dateToISOString(date5), "toISOString"),
19815
+ toStringValue: /* @__PURE__ */ __name((value) => {
19816
+ if (isInstanceOfPrototype(value, URL.prototype)) {
19817
+ return urlHref(value);
19818
+ }
19819
+ if (isInstanceOfPrototype(value, URLSearchParams.prototype)) {
19820
+ return urlSearchParamsToString(value);
19821
+ }
19822
+ recordGuestCode("method", `toString (${readToStringTag(value) ?? "unknown"})`);
19823
+ return value.toString();
19824
+ }, "toStringValue"),
19825
+ regExpInfo: /* @__PURE__ */ __name((regexp) => ({
19826
+ source: regExpSource(regexp),
19827
+ flags: regExpFlags(regexp)
19828
+ }), "regExpInfo"),
19829
+ valuesOf: /* @__PURE__ */ __name((set2) => setToValues(set2), "valuesOf"),
19830
+ entriesOf: /* @__PURE__ */ __name((map2) => mapToEntries(map2), "entriesOf"),
19831
+ viewInfo: /* @__PURE__ */ __name((view) => {
19832
+ const info = viewInfo(view);
19833
+ return {
19834
+ ...info,
19835
+ // devalue only reads `length` for typed-array subviews; DataView
19836
+ // subviews are encoded from `byteLength`.
19837
+ length: types.isDataView(view) ? 0 : typedArrayLength(view),
19838
+ bufferByteLength: types.isSharedArrayBuffer(info.buffer) ? sharedArrayBufferByteLength(info.buffer) : arrayBufferByteLength(info.buffer)
19839
+ };
19840
+ }, "viewInfo"),
19841
+ shapeOf: /* @__PURE__ */ __name((value) => {
19842
+ if (isProxy(value)) recordProxy(value);
19843
+ return default_stringify_operations.shapeOf(value);
19844
+ }, "shapeOf"),
19845
+ get: /* @__PURE__ */ __name((value, key) => readProperty(value, key), "get")
19846
+ };
19847
+ }
19848
+ });
19849
+
19318
19850
  // ../core/dist/class-serialization.js
19319
19851
  function getRegistry(global2 = globalThis) {
19320
19852
  const g = global2;
@@ -19345,7 +19877,7 @@ function getClassReducers() {
19345
19877
  // over the generic Error serialization (devalue uses first-match-wins).
19346
19878
  Class: /* @__PURE__ */ __name((value) => {
19347
19879
  if (typeof value !== "function") return false;
19348
- const classId = value.classId;
19880
+ const classId = readProperty(value, "classId");
19349
19881
  if (typeof classId !== "string") return false;
19350
19882
  return {
19351
19883
  classId
@@ -19353,14 +19885,15 @@ function getClassReducers() {
19353
19885
  }, "Class"),
19354
19886
  Instance: /* @__PURE__ */ __name((value) => {
19355
19887
  if (value === null || typeof value !== "object") return false;
19356
- const cls = value.constructor;
19888
+ const cls = readProperty(value, "constructor");
19357
19889
  if (!cls || typeof cls !== "function") return false;
19358
- const serialize3 = cls[WORKFLOW_SERIALIZE];
19890
+ const serialize3 = readProperty(cls, WORKFLOW_SERIALIZE);
19359
19891
  if (typeof serialize3 !== "function") return false;
19360
- const classId = cls.classId;
19892
+ const classId = readProperty(cls, "classId");
19361
19893
  if (typeof classId !== "string") {
19362
- throw new Error(`Class "${cls.name}" with ${String(WORKFLOW_SERIALIZE)} must have a static "classId" property.`);
19894
+ throw new Error(`Class "${String(readProperty(cls, "name"))}" with ${String(WORKFLOW_SERIALIZE)} must have a static "classId" property.`);
19363
19895
  }
19896
+ recordGuestCode("method", `[WORKFLOW_SERIALIZE] (${classId})`);
19364
19897
  const data = serialize3.call(cls, value);
19365
19898
  return {
19366
19899
  classId,
@@ -19399,20 +19932,22 @@ var init_class = __esm({
19399
19932
  "use strict";
19400
19933
  init_dist3();
19401
19934
  init_class_serialization();
19935
+ init_hardened();
19402
19936
  __name(getClassReducers, "getClassReducers");
19403
19937
  __name(getClassRevivers, "getClassRevivers");
19404
19938
  }
19405
19939
  });
19406
19940
 
19407
19941
  // ../core/dist/serialization/reducers/common.js
19408
- import { types } from "node:util";
19942
+ import { types as types2 } from "node:util";
19409
19943
  function arrayBufferToBase64(value, offset, length) {
19410
19944
  if (length === 0) return ".";
19411
19945
  const uint8 = new Uint8Array(value, offset, length);
19412
19946
  return Buffer.from(uint8).toString("base64");
19413
19947
  }
19414
19948
  function viewToBase64(value) {
19415
- return arrayBufferToBase64(value.buffer, value.byteOffset, value.byteLength);
19949
+ const info = viewInfo(value);
19950
+ return arrayBufferToBase64(info.buffer, info.byteOffset, info.byteLength);
19416
19951
  }
19417
19952
  function reviveArrayBuffer(value, global2) {
19418
19953
  const base643 = value === "." ? "" : value;
@@ -19426,17 +19961,17 @@ function revive(str) {
19426
19961
  return JSON.parse(str);
19427
19962
  }
19428
19963
  function reduceErrorBase(value) {
19429
- if (!types.isNativeError(value)) return false;
19964
+ if (!types2.isNativeError(value)) return false;
19430
19965
  const reduced = {
19431
- message: value.message,
19432
- stack: value.stack
19966
+ message: readProperty(value, "message"),
19967
+ stack: readProperty(value, "stack")
19433
19968
  };
19434
- if ("cause" in value) reduced.cause = value.cause;
19969
+ if (hasProperty(value, "cause")) reduced.cause = readProperty(value, "cause");
19435
19970
  return reduced;
19436
19971
  }
19437
19972
  function reduceNamedErrorSubclassBase(subclassName, value) {
19438
- if (!types.isNativeError(value)) return false;
19439
- if (value.name !== subclassName) return false;
19973
+ if (!types2.isNativeError(value)) return false;
19974
+ if (readProperty(value, "name") !== subclassName) return false;
19440
19975
  return reduceErrorBase(value);
19441
19976
  }
19442
19977
  function makeErrorSubclassReducer(subclassName) {
@@ -19458,16 +19993,20 @@ function makeErrorSubclassReviver(global2, ctorName) {
19458
19993
  return error48;
19459
19994
  };
19460
19995
  }
19461
- function getCommonReducers(global2 = globalThis) {
19996
+ function getCommonReducers(_global = globalThis) {
19462
19997
  return {
19463
- ArrayBuffer: /* @__PURE__ */ __name((value) => value instanceof global2.ArrayBuffer && arrayBufferToBase64(value, 0, value.byteLength), "ArrayBuffer"),
19464
- BigInt: /* @__PURE__ */ __name((value) => typeof value === "bigint" && value.toString(), "BigInt"),
19465
- BigInt64Array: /* @__PURE__ */ __name((value) => value instanceof global2.BigInt64Array && viewToBase64(value), "BigInt64Array"),
19466
- BigUint64Array: /* @__PURE__ */ __name((value) => value instanceof global2.BigUint64Array && viewToBase64(value), "BigUint64Array"),
19998
+ ArrayBuffer: /* @__PURE__ */ __name((value) => types2.isArrayBuffer(value) && arrayBufferToBase64(value, 0, arrayBufferByteLength(value)), "ArrayBuffer"),
19999
+ BigInt: /* @__PURE__ */ __name((value) => (
20000
+ // String(bigint) is a spec-internal numeric conversion — unlike
20001
+ // `value.toString()`, it never consults BigInt.prototype.
20002
+ typeof value === "bigint" && String(value)
20003
+ ), "BigInt"),
20004
+ BigInt64Array: /* @__PURE__ */ __name((value) => types2.isBigInt64Array(value) && viewToBase64(value), "BigInt64Array"),
20005
+ BigUint64Array: /* @__PURE__ */ __name((value) => types2.isBigUint64Array(value) && viewToBase64(value), "BigUint64Array"),
19467
20006
  Date: /* @__PURE__ */ __name((value) => {
19468
- if (!(value instanceof global2.Date)) return false;
19469
- const valid = !Number.isNaN(value.getDate());
19470
- return valid ? value.toISOString() : ".";
20007
+ if (!types2.isDate(value)) return false;
20008
+ const valid = !Number.isNaN(dateGetDate(value));
20009
+ return valid ? dateToISOString(value) : ".";
19471
20010
  }, "Date"),
19472
20011
  // DOMException is a special case: it `instanceof Error` is true in Node,
19473
20012
  // but `types.isNativeError()` returns FALSE for it, so the generic Error
@@ -19477,14 +20016,16 @@ function getCommonReducers(global2 = globalThis) {
19477
20016
  // for instances minted in another context).
19478
20017
  DOMException: /* @__PURE__ */ __name((value) => {
19479
20018
  if (value === null || typeof value !== "object") return false;
19480
- if (value.constructor?.name !== "DOMException") return false;
19481
- const e = value;
20019
+ const ctor = readProperty(value, "constructor");
20020
+ if (!ctor || readProperty(ctor, "name") !== "DOMException") return false;
19482
20021
  const reduced = {
19483
- message: e.message,
19484
- name: e.name,
19485
- stack: e.stack
20022
+ message: readProperty(value, "message"),
20023
+ name: readProperty(value, "name"),
20024
+ stack: readProperty(value, "stack")
19486
20025
  };
19487
- if ("cause" in e) reduced.cause = e.cause;
20026
+ if (hasProperty(value, "cause")) {
20027
+ reduced.cause = readProperty(value, "cause");
20028
+ }
19488
20029
  return reduced;
19489
20030
  }, "DOMException"),
19490
20031
  // Error subclass reducers are intentionally placed before the base Error
@@ -19497,13 +20038,13 @@ function getCommonReducers(global2 = globalThis) {
19497
20038
  HookConflictError: /* @__PURE__ */ __name((value) => {
19498
20039
  const base = reduceNamedErrorSubclassBase("HookConflictError", value);
19499
20040
  if (!base) return false;
19500
- const error48 = value;
19501
20041
  const reduced = {
19502
20042
  ...base,
19503
- token: error48.token
20043
+ token: readProperty(value, "token")
19504
20044
  };
19505
- if (error48.conflictingRunId !== void 0) {
19506
- reduced.conflictingRunId = error48.conflictingRunId;
20045
+ const conflictingRunId = readProperty(value, "conflictingRunId");
20046
+ if (conflictingRunId !== void 0) {
20047
+ reduced.conflictingRunId = conflictingRunId;
19507
20048
  }
19508
20049
  return reduced;
19509
20050
  }, "HookConflictError"),
@@ -19516,11 +20057,20 @@ function getCommonReducers(global2 = globalThis) {
19516
20057
  RetryableError: /* @__PURE__ */ __name((value) => {
19517
20058
  const base = reduceNamedErrorSubclassBase("RetryableError", value);
19518
20059
  if (!base) return false;
19519
- const retryAfterRaw = value.retryAfter;
20060
+ const retryAfterRaw = readProperty(value, "retryAfter");
19520
20061
  let retryAfter;
19521
- if (retryAfterRaw && typeof retryAfterRaw === "object" && typeof retryAfterRaw.getTime === "function") {
19522
- const t = retryAfterRaw.getTime();
20062
+ if (types2.isDate(retryAfterRaw)) {
20063
+ const t = dateGetTime(retryAfterRaw);
19523
20064
  retryAfter = Number.isNaN(t) ? Date.now() + 1e3 : t;
20065
+ } else if (retryAfterRaw && typeof retryAfterRaw === "object") {
20066
+ const getTime = readProperty(retryAfterRaw, "getTime");
20067
+ if (typeof getTime === "function") {
20068
+ recordGuestCode("method", "getTime");
20069
+ const t = getTime.call(retryAfterRaw);
20070
+ retryAfter = Number.isNaN(t) ? Date.now() + 1e3 : t;
20071
+ } else {
20072
+ retryAfter = Date.now() + 1e3;
20073
+ }
19524
20074
  } else if (typeof retryAfterRaw === "string" || typeof retryAfterRaw === "number") {
19525
20075
  const t = new Date(retryAfterRaw).getTime();
19526
20076
  retryAfter = Number.isNaN(t) ? Date.now() + 1e3 : t;
@@ -19541,7 +20091,7 @@ function getCommonReducers(global2 = globalThis) {
19541
20091
  const reduced = {
19542
20092
  ...base
19543
20093
  };
19544
- const context = value.context;
20094
+ const context = readProperty(value, "context");
19545
20095
  if (context !== void 0) {
19546
20096
  reduced.context = context;
19547
20097
  }
@@ -19557,7 +20107,7 @@ function getCommonReducers(global2 = globalThis) {
19557
20107
  if (!base) return false;
19558
20108
  return {
19559
20109
  ...base,
19560
- errors: value.errors
20110
+ errors: readProperty(value, "errors")
19561
20111
  };
19562
20112
  }, "AggregateError"),
19563
20113
  // Base Error reducer — catch-all for any Error instance not matched by a
@@ -19565,49 +20115,58 @@ function getCommonReducers(global2 = globalThis) {
19565
20115
  // WORKFLOW_SERIALIZE). Preserves `name` so the error's identity is retained
19566
20116
  // even though the exact class cannot be reconstructed.
19567
20117
  Error: /* @__PURE__ */ __name((value) => {
19568
- if (!types.isNativeError(value)) return false;
20118
+ if (!types2.isNativeError(value)) return false;
19569
20119
  const reduced = {
19570
- name: value.name,
19571
- message: value.message,
19572
- stack: value.stack
20120
+ name: readProperty(value, "name"),
20121
+ message: readProperty(value, "message"),
20122
+ stack: readProperty(value, "stack")
19573
20123
  };
19574
- if ("cause" in value) reduced.cause = value.cause;
20124
+ if (hasProperty(value, "cause")) {
20125
+ reduced.cause = readProperty(value, "cause");
20126
+ }
19575
20127
  return reduced;
19576
20128
  }, "Error"),
19577
- Float32Array: /* @__PURE__ */ __name((value) => value instanceof global2.Float32Array && viewToBase64(value), "Float32Array"),
19578
- Float64Array: /* @__PURE__ */ __name((value) => value instanceof global2.Float64Array && viewToBase64(value), "Float64Array"),
19579
- Headers: /* @__PURE__ */ __name((value) => value instanceof global2.Headers && Array.from(value), "Headers"),
19580
- Int8Array: /* @__PURE__ */ __name((value) => value instanceof global2.Int8Array && viewToBase64(value), "Int8Array"),
19581
- Int16Array: /* @__PURE__ */ __name((value) => value instanceof global2.Int16Array && viewToBase64(value), "Int16Array"),
19582
- Int32Array: /* @__PURE__ */ __name((value) => value instanceof global2.Int32Array && viewToBase64(value), "Int32Array"),
19583
- Map: /* @__PURE__ */ __name((value) => value instanceof global2.Map && Array.from(value), "Map"),
19584
- RegExp: /* @__PURE__ */ __name((value) => value instanceof global2.RegExp && {
19585
- source: value.source,
19586
- flags: value.flags
20129
+ Float32Array: /* @__PURE__ */ __name((value) => types2.isFloat32Array(value) && viewToBase64(value), "Float32Array"),
20130
+ Float64Array: /* @__PURE__ */ __name((value) => types2.isFloat64Array(value) && viewToBase64(value), "Float64Array"),
20131
+ // Headers is a host class injected into the sandbox, so its (shared)
20132
+ // prototype is reachable from workflow code — iterate through the
20133
+ // boot-captured iterator instead of a live Symbol.iterator lookup.
20134
+ Headers: /* @__PURE__ */ __name((value) => isInstanceOfPrototype(value, Headers.prototype) && headersToEntries(value), "Headers"),
20135
+ Int8Array: /* @__PURE__ */ __name((value) => types2.isInt8Array(value) && viewToBase64(value), "Int8Array"),
20136
+ Int16Array: /* @__PURE__ */ __name((value) => types2.isInt16Array(value) && viewToBase64(value), "Int16Array"),
20137
+ Int32Array: /* @__PURE__ */ __name((value) => types2.isInt32Array(value) && viewToBase64(value), "Int32Array"),
20138
+ // Engine brand check + host-realm iteration: a patched
20139
+ // `Map.prototype[Symbol.iterator]` in the sandbox is never consulted.
20140
+ Map: /* @__PURE__ */ __name((value) => types2.isMap(value) && mapToEntries(value), "Map"),
20141
+ RegExp: /* @__PURE__ */ __name((value) => types2.isRegExp(value) && {
20142
+ source: regExpSource(value),
20143
+ flags: regExpFlags(value)
19587
20144
  }, "RegExp"),
19588
20145
  // Request and Response are intentionally NOT in common reducers.
19589
20146
  // They require mode-specific revivers (stream handling, etc.) and
19590
20147
  // including them here without matching revivers would cause them
19591
20148
  // to deserialize as plain objects.
19592
- Set: /* @__PURE__ */ __name((value) => value instanceof global2.Set && Array.from(value), "Set"),
19593
- URL: /* @__PURE__ */ __name((value) => value instanceof global2.URL && value.href, "URL"),
20149
+ Set: /* @__PURE__ */ __name((value) => types2.isSet(value) && setToValues(value), "Set"),
20150
+ URL: /* @__PURE__ */ __name((value) => isInstanceOfPrototype(value, URL.prototype) && urlHref(value), "URL"),
19594
20151
  WorkflowFunction: /* @__PURE__ */ __name((value) => {
19595
20152
  if (typeof value !== "function") return false;
19596
- const workflowId = value.workflowId;
20153
+ const workflowId = readProperty(value, "workflowId");
19597
20154
  if (typeof workflowId !== "string") return false;
19598
20155
  return {
19599
20156
  workflowId
19600
20157
  };
19601
20158
  }, "WorkflowFunction"),
19602
20159
  URLSearchParams: /* @__PURE__ */ __name((value) => {
19603
- if (!(value instanceof global2.URLSearchParams)) return false;
19604
- if (value.size === 0) return ".";
19605
- return String(value);
20160
+ if (!isInstanceOfPrototype(value, URLSearchParams.prototype)) {
20161
+ return false;
20162
+ }
20163
+ const text = urlSearchParamsToString(value);
20164
+ return text === "" ? "." : text;
19606
20165
  }, "URLSearchParams"),
19607
- Uint8Array: /* @__PURE__ */ __name((value) => value instanceof global2.Uint8Array && viewToBase64(value), "Uint8Array"),
19608
- Uint8ClampedArray: /* @__PURE__ */ __name((value) => value instanceof global2.Uint8ClampedArray && viewToBase64(value), "Uint8ClampedArray"),
19609
- Uint16Array: /* @__PURE__ */ __name((value) => value instanceof global2.Uint16Array && viewToBase64(value), "Uint16Array"),
19610
- Uint32Array: /* @__PURE__ */ __name((value) => value instanceof global2.Uint32Array && viewToBase64(value), "Uint32Array")
20166
+ Uint8Array: /* @__PURE__ */ __name((value) => types2.isUint8Array(value) && viewToBase64(value), "Uint8Array"),
20167
+ Uint8ClampedArray: /* @__PURE__ */ __name((value) => types2.isUint8ClampedArray(value) && viewToBase64(value), "Uint8ClampedArray"),
20168
+ Uint16Array: /* @__PURE__ */ __name((value) => types2.isUint16Array(value) && viewToBase64(value), "Uint16Array"),
20169
+ Uint32Array: /* @__PURE__ */ __name((value) => types2.isUint32Array(value) && viewToBase64(value), "Uint32Array")
19611
20170
  };
19612
20171
  }
19613
20172
  function getCommonRevivers(global2 = globalThis) {
@@ -19719,6 +20278,7 @@ var init_common = __esm({
19719
20278
  "../core/dist/serialization/reducers/common.js"() {
19720
20279
  "use strict";
19721
20280
  init_dist2();
20281
+ init_hardened();
19722
20282
  __name(arrayBufferToBase64, "arrayBufferToBase64");
19723
20283
  __name(viewToBase64, "viewToBase64");
19724
20284
  __name(reviveArrayBuffer, "reviveArrayBuffer");
@@ -19737,13 +20297,19 @@ function getStepFunctionReducer() {
19737
20297
  return {
19738
20298
  StepFunction: /* @__PURE__ */ __name((value) => {
19739
20299
  if (typeof value !== "function") return false;
19740
- const stepId = value.stepId;
20300
+ const stepId = readProperty(value, "stepId");
19741
20301
  if (typeof stepId !== "string") return false;
19742
- const closureVarsFn = value.__closureVarsFn;
19743
- const closureVars = closureVarsFn && typeof closureVarsFn === "function" ? closureVarsFn() : void 0;
19744
- const hasBoundThis = "__boundThis" in value;
19745
- const boundThis = hasBoundThis ? value.__boundThis : void 0;
19746
- const boundArgs = value.__boundArgs;
20302
+ const closureVarsFn = readProperty(value, "__closureVarsFn");
20303
+ let closureVars;
20304
+ if (typeof closureVarsFn === "function") {
20305
+ if (!isUseStepClosureFn(closureVarsFn)) {
20306
+ recordGuestCode("method", "__closureVarsFn");
20307
+ }
20308
+ closureVars = closureVarsFn();
20309
+ }
20310
+ const hasBoundThis = hasProperty(value, "__boundThis");
20311
+ const boundThis = hasBoundThis ? readProperty(value, "__boundThis") : void 0;
20312
+ const boundArgs = readProperty(value, "__boundArgs");
19747
20313
  const payload = {
19748
20314
  stepId
19749
20315
  };
@@ -19777,6 +20343,7 @@ function getStepFunctionReviver(global2 = globalThis) {
19777
20343
  var init_step_function = __esm({
19778
20344
  "../core/dist/serialization/reducers/step-function.js"() {
19779
20345
  "use strict";
20346
+ init_hardened();
19780
20347
  __name(getStepFunctionReducer, "getStepFunctionReducer");
19781
20348
  __name(getStepFunctionReviver, "getStepFunctionReviver");
19782
20349
  }
@@ -19853,6 +20420,7 @@ var init_codec_devalue = __esm({
19853
20420
  "../core/dist/serialization/codec-devalue.js"() {
19854
20421
  "use strict";
19855
20422
  init_devalue();
20423
+ init_hardened();
19856
20424
  init_class();
19857
20425
  init_common();
19858
20426
  init_step_function();
@@ -19865,7 +20433,9 @@ var init_codec_devalue = __esm({
19865
20433
  formatPrefix: SerializationFormat.DEVALUE_V1,
19866
20434
  serialize(value, mode, options) {
19867
20435
  const reducers = getReducersForMode(mode, options?.global, options?.extraReducers);
19868
- const str = stringify(value, reducers);
20436
+ const str = withGuestCodeStats(options?.guestCodeStats, () => stringify(value, reducers, {
20437
+ operations: hardenedStringifyOperations
20438
+ }));
19869
20439
  return encoder.encode(str);
19870
20440
  },
19871
20441
  deserialize(data, mode, options) {
@@ -20396,7 +20966,7 @@ function SemanticConvention(...names) {
20396
20966
  value
20397
20967
  ]));
20398
20968
  }
20399
- var WorkflowName, WorkflowOperation, WorkflowRunId, WorkflowRunStatus, WorkflowStartedAt, WorkflowEventsCount, WorkflowArgumentsCount, WorkflowResultType, WorkflowTracePropagated, WorkflowTraceMode, WorkflowTurbo, WorkflowErrorName, WorkflowErrorMessage, WorkflowErrorCode, WorkflowStepsCreated, WorkflowHooksCreated, WorkflowWaitsCreated, WorkflowOwnedRecoverySteps, WorkflowBackstopWakesArmed, WorkflowRouteType, WorkflowRouteHandlerCached, WorkflowRouteInvocationCount, WorkflowRouteEntrypointAgeMs, WorkflowRouteModuleBodyInitMs, StepName, StepId, StepAttempt, StepStatus, StepMaxRetries, StepTracePropagated, StepTtfsMs, StepStsoMs, StepRsfsMs, StepFinalSchedulingReplayMs, StepLatencyOptimizations, StepSkipped, StepSkipReason, StepArgumentsCount, StepResultType, StepErrorName, StepErrorMessage, StepFatalError, StepRetryExhausted, StepRetryTimeoutSeconds, StepRetryWillRetry, MessagingSystem, MessagingDestinationName, MessagingMessageId, MessagingOperationType, QueueOverheadMs, DeploymentId, HookToken, HookId, HookFound, WebhookHandlersTriggered, WorkflowSuspensionState, WorkflowSuspensionHookCount, WorkflowSuspensionStepCount, WorkflowSuspensionWaitCount, HttpRequestMethod, HttpRoute, UrlFull, ServerAddress, ServerPort, HttpResponseStatusCode, ErrorType, WorldParseFormat, WorkflowEventsPagesLoaded, QueueDeserializeTimeMs, QueueExecutionTimeMs, QueueSerializeTimeMs, SerializationOperation, SerializationCompressed, SerializationCodec, SerializationUncompressedBytes, SerializationStoredBytes, SerializationCompressionRatio, PeerService, RpcSystem, RpcService, RpcMethod, ErrorRetryable, ErrorCategory;
20969
+ var WorkflowName, WorkflowOperation, WorkflowRunId, WorkflowRunStatus, WorkflowStartedAt, WorkflowEventsCount, WorkflowArgumentsCount, WorkflowResultType, WorkflowTracePropagated, WorkflowTraceMode, WorkflowTurbo, WorkflowErrorName, WorkflowErrorMessage, WorkflowErrorCode, WorkflowStepsCreated, WorkflowHooksCreated, WorkflowWaitsCreated, WorkflowOwnedRecoverySteps, WorkflowBackstopWakesArmed, WorkflowRouteType, WorkflowRouteHandlerCached, WorkflowRouteInvocationCount, WorkflowRouteEntrypointAgeMs, WorkflowRouteModuleBodyInitMs, FaasInstance, StepName, StepId, StepAttempt, StepStatus, StepMaxRetries, StepTracePropagated, StepTtfsMs, StepStsoMs, StepRsfsMs, StepFinalSchedulingReplayMs, StepLatencyOptimizations, StepSkipped, StepSkipReason, StepArgumentsCount, StepResultType, StepErrorName, StepErrorMessage, StepFatalError, StepRetryExhausted, StepRetryTimeoutSeconds, StepRetryWillRetry, MessagingSystem, MessagingDestinationName, MessagingMessageId, MessagingOperationType, QueueOverheadMs, DeploymentId, HookToken, HookId, HookFound, HookResilientResume, HookResilientResumeMaterialized, WebhookHandlersTriggered, WorkflowSuspensionState, WorkflowSuspensionHookCount, WorkflowSuspensionStepCount, WorkflowSuspensionWaitCount, HttpRequestMethod, HttpRoute, UrlFull, ServerAddress, ServerPort, HttpResponseStatusCode, ErrorType, WorldParseFormat, WorkflowEventsPagesLoaded, QueueDeserializeTimeMs, QueueExecutionTimeMs, QueueSerializeTimeMs, SerializationOperation, SerializationCompressed, SerializationCodec, SerializationUncompressedBytes, SerializationStoredBytes, SerializationCompressionRatio, SerializationGuestCodeExecutions, SerializationGuestCodeDetails, PeerService, RpcSystem, RpcService, RpcMethod, ErrorRetryable, ErrorCategory;
20400
20970
  var init_semantic_conventions = __esm({
20401
20971
  "../core/dist/telemetry/semantic-conventions.js"() {
20402
20972
  "use strict";
@@ -20425,6 +20995,7 @@ var init_semantic_conventions = __esm({
20425
20995
  WorkflowRouteInvocationCount = SemanticConvention("workflow.route.invocation_count");
20426
20996
  WorkflowRouteEntrypointAgeMs = SemanticConvention("workflow.route.entrypoint_age_ms");
20427
20997
  WorkflowRouteModuleBodyInitMs = SemanticConvention("workflow.route.module_body_init_ms");
20998
+ FaasInstance = SemanticConvention("faas.instance");
20428
20999
  StepName = SemanticConvention("step.name");
20429
21000
  StepId = SemanticConvention("step.id");
20430
21001
  StepAttempt = SemanticConvention("step.attempt");
@@ -20455,6 +21026,8 @@ var init_semantic_conventions = __esm({
20455
21026
  HookToken = SemanticConvention("workflow.hook.token");
20456
21027
  HookId = SemanticConvention("workflow.hook.id");
20457
21028
  HookFound = SemanticConvention("workflow.hook.found");
21029
+ HookResilientResume = SemanticConvention("workflow.hook.resilient_resume");
21030
+ HookResilientResumeMaterialized = SemanticConvention("workflow.hook.resilient_resume_materialized");
20458
21031
  WebhookHandlersTriggered = SemanticConvention("webhook.handlers.triggered");
20459
21032
  WorkflowSuspensionState = SemanticConvention("workflow.suspension.state");
20460
21033
  WorkflowSuspensionHookCount = SemanticConvention("workflow.suspension.hook_count");
@@ -20478,6 +21051,8 @@ var init_semantic_conventions = __esm({
20478
21051
  SerializationUncompressedBytes = SemanticConvention("workflow.serialization.uncompressed_bytes");
20479
21052
  SerializationStoredBytes = SemanticConvention("workflow.serialization.stored_bytes");
20480
21053
  SerializationCompressionRatio = SemanticConvention("workflow.serialization.compression_ratio");
21054
+ SerializationGuestCodeExecutions = SemanticConvention("workflow.serialization.guest_code_executions");
21055
+ SerializationGuestCodeDetails = SemanticConvention("workflow.serialization.guest_code_details");
20481
21056
  PeerService = SemanticConvention("peer.service");
20482
21057
  RpcSystem = SemanticConvention("rpc.system");
20483
21058
  RpcService = SemanticConvention("rpc.service");
@@ -22920,7 +23495,11 @@ var init_context_storage = __esm({
22920
23495
  "../core/dist/step/context-storage.js"() {
22921
23496
  "use strict";
22922
23497
  CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("WORKFLOW_STEP_CONTEXT_STORAGE");
22923
- contextStorage = globalThis[CONTEXT_STORAGE_SYMBOL] ?? (globalThis[CONTEXT_STORAGE_SYMBOL] = new AsyncLocalStorage());
23498
+ contextStorage = (() => {
23499
+ const store = globalThis;
23500
+ store[CONTEXT_STORAGE_SYMBOL] ??= new AsyncLocalStorage();
23501
+ return store[CONTEXT_STORAGE_SYMBOL];
23502
+ })();
22924
23503
  }
22925
23504
  });
22926
23505
 
@@ -25060,6 +25639,11 @@ var init_capabilities = __esm({
25060
25639
  }
25061
25640
  ];
25062
25641
  CAPABILITY_VERSION_TABLE = [
25642
+ // TODO(release): verify this matches the actual version that ships byte-stream
25643
+ // framing. If a "Version Packages (beta)" PR merges before this change, bump
25644
+ // to the next beta. A too-low cutoff makes new producers write framed bytes to
25645
+ // consumers that cannot unframe them (silent corruption); too-high merely
25646
+ // delays the optimization (safe).
25063
25647
  {
25064
25648
  capability: "framedByteStreams",
25065
25649
  minVersion: "5.0.0-beta.15"
@@ -25072,12 +25656,53 @@ var init_capabilities = __esm({
25072
25656
  }
25073
25657
  });
25074
25658
 
25659
+ // ../core/dist/classify-error.js
25660
+ function isRetryableWorldError(err) {
25661
+ if (ThrottleError.is(err)) {
25662
+ return true;
25663
+ }
25664
+ if (!WorkflowWorldError.is(err)) {
25665
+ return false;
25666
+ }
25667
+ if (err.status !== void 0 && err.status >= 500) {
25668
+ return true;
25669
+ }
25670
+ return err.code !== void 0 && RETRYABLE_WORLD_ERROR_CODES.has(err.code);
25671
+ }
25672
+ var WORLD_CONTRACT_ERROR_CODES, RETRYABLE_WORLD_ERROR_CODES, RUNTIME_ERROR_CHECKS;
25673
+ var init_classify_error = __esm({
25674
+ "../core/dist/classify-error.js"() {
25675
+ "use strict";
25676
+ init_dist2();
25677
+ WORLD_CONTRACT_ERROR_CODES = /* @__PURE__ */ new Set([
25678
+ "PARSE_ERROR",
25679
+ "SCHEMA_VALIDATION",
25680
+ RUN_ERROR_CODES.WORLD_CONTRACT_ERROR
25681
+ ]);
25682
+ RETRYABLE_WORLD_ERROR_CODES = /* @__PURE__ */ new Set([
25683
+ "TRANSPORT",
25684
+ "TIMEOUT"
25685
+ ]);
25686
+ RUNTIME_ERROR_CHECKS = [
25687
+ WorkflowRuntimeError.is,
25688
+ StepNotRegisteredError.is,
25689
+ WorkflowNotRegisteredError.is,
25690
+ // SDK-level encryption failures (most notably AES-GCM auth-tag
25691
+ // mismatches surfacing as a native `OperationError` from
25692
+ // `AESCipherJob.onDone`) are wrapped in `RuntimeDecryptionError` at
25693
+ // the encryption module boundary.
25694
+ RuntimeDecryptionError.is
25695
+ ];
25696
+ __name(isRetryableWorldError, "isRetryableWorldError");
25697
+ }
25698
+ });
25699
+
25075
25700
  // ../core/dist/version.js
25076
25701
  var version2;
25077
25702
  var init_version = __esm({
25078
25703
  "../core/dist/version.js"() {
25079
25704
  "use strict";
25080
- version2 = "5.0.0-beta.38";
25705
+ version2 = "5.0.0-beta.39";
25081
25706
  }
25082
25707
  });
25083
25708
 
@@ -25166,6 +25791,9 @@ function parseHealthCheckResponse(chunks) {
25166
25791
  if (typeof r.encryptionPublicKey === "string") {
25167
25792
  parsed.encryptionPublicKey = r.encryptionPublicKey;
25168
25793
  }
25794
+ if (typeof r.hookResumeInputVersion === "number") {
25795
+ parsed.hookResumeInputVersion = r.hookResumeInputVersion;
25796
+ }
25169
25797
  return parsed;
25170
25798
  }
25171
25799
  async function healthCheck(world, options) {
@@ -26425,16 +27053,27 @@ __export(resume_hook_exports, {
26425
27053
  resumeHook: () => resumeHook,
26426
27054
  resumeWebhook: () => resumeWebhook
26427
27055
  });
27056
+ async function computeResumePayloadDigest(bytes) {
27057
+ const digest = await crypto.subtle.digest("SHA-256", bytes);
27058
+ const view = new Uint8Array(digest);
27059
+ let hex3 = "";
27060
+ for (const b of view) {
27061
+ hex3 += b.toString(16).padStart(2, "0");
27062
+ }
27063
+ return hex3;
27064
+ }
26428
27065
  function resumeContextFromRun(run2) {
26429
27066
  const coreVersion = run2.executionContext?.workflowCoreVersion;
26430
27067
  const traceCarrier = run2.executionContext?.traceCarrier;
27068
+ const hookResumeInputVersion = run2.executionContext?.hookResumeInputVersion;
26431
27069
  return {
26432
27070
  deploymentId: run2.deploymentId,
26433
27071
  workflowName: run2.workflowName,
26434
27072
  runSpecVersion: run2.specVersion,
26435
27073
  workflowCoreVersion: typeof coreVersion === "string" ? coreVersion : void 0,
26436
27074
  traceCarrier: traceCarrier && typeof traceCarrier === "object" ? traceCarrier : void 0,
26437
- encryptionPublicKey: run2.encryptionPublicKey
27075
+ encryptionPublicKey: run2.encryptionPublicKey,
27076
+ hookResumeInputVersion: typeof hookResumeInputVersion === "number" ? hookResumeInputVersion : void 0
26438
27077
  };
26439
27078
  }
26440
27079
  async function resolveHookResumeInfo(hook) {
@@ -26480,11 +27119,16 @@ async function getHookByToken(token) {
26480
27119
  return hook;
26481
27120
  }
26482
27121
  async function resumeHook(tokenOrHook, payload, encryptionKeyOverride) {
27122
+ return resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, false);
27123
+ }
27124
+ async function resumeHookImpl(tokenOrHook, payload, encryptionKeyOverride, hookFreshlyLookedUp) {
26483
27125
  return await waitedUntil(() => {
26484
27126
  return trace("hook.resume", async (span) => {
26485
27127
  const world = await getWorldLazy();
26486
27128
  try {
26487
- const hook = typeof tokenOrHook === "string" ? await world.hooks.getByToken(tokenOrHook) : tokenOrHook;
27129
+ const suppliedToken = typeof tokenOrHook === "string";
27130
+ const hook = suppliedToken ? await world.hooks.getByToken(tokenOrHook) : tokenOrHook;
27131
+ const hookResumeCapabilitiesAreFresh = suppliedToken || hookFreshlyLookedUp;
26488
27132
  const info = await resolveHookResumeInfo(hook);
26489
27133
  const { resumeContext } = info;
26490
27134
  span?.setAttributes({
@@ -26524,26 +27168,6 @@ async function resumeHook(tokenOrHook, payload, encryptionKeyOverride) {
26524
27168
  error: err instanceof Error ? err.message : String(err)
26525
27169
  });
26526
27170
  });
26527
- try {
26528
- await world.events.create(hook.runId, {
26529
- eventType: "hook_received",
26530
- specVersion: SPEC_VERSION_CURRENT,
26531
- correlationId: hook.hookId,
26532
- eventData: {
26533
- ...v1Compat ? {} : {
26534
- token: hook.token
26535
- },
26536
- payload: dehydratedPayload
26537
- }
26538
- }, {
26539
- v1Compat
26540
- });
26541
- } catch (err) {
26542
- if (HookNotFoundError.is(err) || EntityConflictError.is(err) || RunExpiredError.is(err)) {
26543
- throw new HookNotFoundError(hook.token);
26544
- }
26545
- throw err;
26546
- }
26547
27171
  span?.setAttributes({
26548
27172
  ...WorkflowName(resumeContext.workflowName)
26549
27173
  });
@@ -26551,15 +27175,108 @@ async function resumeHook(tokenOrHook, payload, encryptionKeyOverride) {
26551
27175
  if (originLink) {
26552
27176
  span?.addLink?.(originLink);
26553
27177
  }
26554
- await world.queue(getWorkflowQueueName(resumeContext.workflowName), {
26555
- runId: hook.runId,
26556
- // attach the trace carrier from the run's resume context
26557
- traceCarrier: resumeContext.traceCarrier ?? void 0
26558
- }, {
27178
+ const eventData = {
27179
+ ...v1Compat ? {} : {
27180
+ token: hook.token
27181
+ },
27182
+ payload: dehydratedPayload
27183
+ };
27184
+ const queueName = getWorkflowQueueName(resumeContext.workflowName);
27185
+ const queueOptions = {
26559
27186
  deploymentId: resumeContext.deploymentId,
26560
27187
  specVersion: resumeContext.runSpecVersion ?? SPEC_VERSION_LEGACY
27188
+ };
27189
+ const parallelResumeDisabled = process.env.WORKFLOW_DISABLE_LAZY_HOOK_RESUME === "1";
27190
+ const backendDedupSupported = (hookResumeCapabilitiesAreFresh ? hook.resumeCapabilities?.hookResumeDedupVersion ?? 0 : 0) >= HOOK_RESUME_DEDUP_VERSION || world.capabilities?.hookResumeDedup === true;
27191
+ const fallbackReason = parallelResumeDisabled ? "disabled" : !backendDedupSupported ? "backend_unsupported" : (resumeContext.hookResumeInputVersion ?? 0) < HOOK_RESUME_INPUT_VERSION ? "consumer_unsupported" : v1Compat ? "legacy" : (resumeContext.runSpecVersion ?? 0) < SPEC_VERSION_SUPPORTS_CBOR_QUEUE_TRANSPORT ? "non_cbor_transport" : !(dehydratedPayload instanceof Uint8Array) ? "non_bytes" : dehydratedPayload.byteLength > MAX_INLINE_RESUME_PAYLOAD_BYTES ? "oversized" : null;
27192
+ const useParallelResume = fallbackReason === null;
27193
+ span?.setAttributes({
27194
+ "workflow.hook.resume_strategy": useParallelResume ? "parallel" : "sequential",
27195
+ ...fallbackReason ? {
27196
+ "workflow.hook.resume_fallback_reason": fallbackReason
27197
+ } : {}
26561
27198
  });
26562
- return hook;
27199
+ const isHookGoneError = /* @__PURE__ */ __name((err) => HookNotFoundError.is(err) || EntityConflictError.is(err) || RunExpiredError.is(err), "isHookGoneError");
27200
+ if (!useParallelResume) {
27201
+ try {
27202
+ await world.events.create(hook.runId, {
27203
+ eventType: "hook_received",
27204
+ specVersion: SPEC_VERSION_CURRENT,
27205
+ correlationId: hook.hookId,
27206
+ eventData
27207
+ }, {
27208
+ v1Compat
27209
+ });
27210
+ } catch (err) {
27211
+ if (isHookGoneError(err)) {
27212
+ throw new HookNotFoundError(hook.token);
27213
+ }
27214
+ throw err;
27215
+ }
27216
+ await world.queue(queueName, {
27217
+ runId: hook.runId,
27218
+ traceCarrier: resumeContext.traceCarrier ?? void 0
27219
+ }, queueOptions);
27220
+ return hook;
27221
+ }
27222
+ const resumeId = generateResumeId();
27223
+ const payloadDigest = await computeResumePayloadDigest(dehydratedPayload);
27224
+ span?.setAttributes({
27225
+ "workflow.hook.resume_id": resumeId
27226
+ });
27227
+ const [eventResult, queueResult] = await Promise.allSettled([
27228
+ world.events.create(hook.runId, {
27229
+ eventType: "hook_received",
27230
+ specVersion: SPEC_VERSION_CURRENT,
27231
+ correlationId: hook.hookId,
27232
+ eventData
27233
+ }, {
27234
+ v1Compat,
27235
+ resumeId,
27236
+ resumePayloadDigest: payloadDigest
27237
+ }),
27238
+ world.queue(queueName, {
27239
+ runId: hook.runId,
27240
+ traceCarrier: resumeContext.traceCarrier ?? void 0,
27241
+ hookInput: {
27242
+ resumeId,
27243
+ hookId: hook.hookId,
27244
+ token: hook.token,
27245
+ payload: dehydratedPayload,
27246
+ payloadDigest
27247
+ }
27248
+ }, queueOptions)
27249
+ ]);
27250
+ if (queueResult.status === "rejected") {
27251
+ throw queueResult.reason;
27252
+ }
27253
+ let resilientResume = false;
27254
+ if (eventResult.status === "rejected") {
27255
+ const err = eventResult.reason;
27256
+ if (HookNotFoundError.is(err) || RunExpiredError.is(err)) {
27257
+ throw new HookNotFoundError(hook.token);
27258
+ }
27259
+ if (EntityConflictError.is(err) || isRetryableWorldError(err)) {
27260
+ resilientResume = true;
27261
+ span?.setAttributes({
27262
+ ...HookResilientResume(true),
27263
+ "workflow.hook.resume_event_write_recovered": true,
27264
+ "workflow.hook.resume_event_write_error": err instanceof Error ? err.name : "unknown"
27265
+ });
27266
+ runtimeLogger.warn("Hook resume event write failed, but the run was re-triggered via the queue. The hook_received event will be ensured by the queue consumer.", {
27267
+ workflowRunId: hook.runId,
27268
+ hookId: hook.hookId,
27269
+ resumeId,
27270
+ error: err instanceof Error ? err.message : String(err)
27271
+ });
27272
+ } else {
27273
+ throw err;
27274
+ }
27275
+ }
27276
+ return resilientResume ? {
27277
+ ...hook,
27278
+ resilientResume: true
27279
+ } : hook;
26563
27280
  } catch (err) {
26564
27281
  span?.setAttributes({
26565
27282
  ...HookToken(typeof tokenOrHook === "string" ? tokenOrHook : tokenOrHook.token),
@@ -26594,7 +27311,7 @@ async function resumeWebhook(token, request) {
26594
27311
  status: 202
26595
27312
  });
26596
27313
  }
26597
- await resumeHook(hook, request, encryptionKey);
27314
+ await resumeHookImpl(hook, request, encryptionKey, true);
26598
27315
  if (responseReadable) {
26599
27316
  const reader = responseReadable.getReader();
26600
27317
  const chunk = await reader.read();
@@ -26610,12 +27327,15 @@ async function resumeWebhook(token, request) {
26610
27327
  }
26611
27328
  return response;
26612
27329
  }
27330
+ var generateResumeId, MAX_INLINE_RESUME_PAYLOAD_BYTES;
26613
27331
  var init_resume_hook = __esm({
26614
27332
  "../core/dist/runtime/resume-hook.js"() {
26615
27333
  "use strict";
26616
27334
  init_dist2();
26617
27335
  init_dist4();
27336
+ init_node();
26618
27337
  init_capabilities();
27338
+ init_classify_error();
26619
27339
  init_encryption();
26620
27340
  init_logger();
26621
27341
  init_sealed_box();
@@ -26627,12 +27347,16 @@ var init_resume_hook = __esm({
26627
27347
  init_get_world_lazy();
26628
27348
  init_helpers();
26629
27349
  init_wait_until();
27350
+ generateResumeId = monotonicFactory();
27351
+ MAX_INLINE_RESUME_PAYLOAD_BYTES = 128 * 1024;
27352
+ __name(computeResumePayloadDigest, "computeResumePayloadDigest");
26630
27353
  __name(resumeContextFromRun, "resumeContextFromRun");
26631
27354
  __name(resolveHookResumeInfo, "resolveHookResumeInfo");
26632
27355
  __name(resolveHookEncryptionKey, "resolveHookEncryptionKey");
26633
27356
  __name(getHookByTokenWithKey, "getHookByTokenWithKey");
26634
27357
  __name(getHookByToken, "getHookByToken");
26635
27358
  __name(resumeHook, "resumeHook");
27359
+ __name(resumeHookImpl, "resumeHookImpl");
26636
27360
  __name(resumeWebhook, "resumeWebhook");
26637
27361
  }
26638
27362
  });
@@ -26676,6 +27400,21 @@ async function recordCompression(stats, operation) {
26676
27400
  } catch {
26677
27401
  }
26678
27402
  }
27403
+ async function recordGuestCodeExecutions(stats) {
27404
+ if (stats.executions.length === 0) return;
27405
+ try {
27406
+ const span = await getActiveSpan();
27407
+ if (!span) return;
27408
+ const details = [
27409
+ ...new Set(stats.executions.map((e) => e.detail ? `${e.kind} (${e.detail})` : e.kind))
27410
+ ];
27411
+ span.setAttributes({
27412
+ ...SerializationGuestCodeExecutions(stats.executions.length),
27413
+ ...SerializationGuestCodeDetails(details)
27414
+ });
27415
+ } catch {
27416
+ }
27417
+ }
26679
27418
  function getSerializeStream(reducers, cryptoKey) {
26680
27419
  const encoder2 = new TextEncoder();
26681
27420
  const keyState = {
@@ -27066,33 +27805,34 @@ function getAllBaseReducers(global2 = globalThis) {
27066
27805
  // Request and Response reducers are mode-specific and added by
27067
27806
  // getExternalReducers / getWorkflowReducers / getStepReducers below.
27068
27807
  Request: /* @__PURE__ */ __name((value) => {
27069
- if (!(value instanceof global2.Request)) return false;
27808
+ if (!isInstanceOfPrototype(value, getHostClassPrototype(global2, "Request"))) return false;
27070
27809
  const data = {
27071
- method: value.method,
27072
- url: value.url,
27073
- headers: value.headers,
27074
- body: value.body,
27075
- duplex: value.duplex
27810
+ method: readProperty(value, "method"),
27811
+ url: readProperty(value, "url"),
27812
+ headers: readProperty(value, "headers"),
27813
+ body: readProperty(value, "body"),
27814
+ duplex: readProperty(value, "duplex")
27076
27815
  };
27077
- const responseWritable = value[WEBHOOK_RESPONSE_WRITABLE];
27816
+ const responseWritable = readProperty(value, WEBHOOK_RESPONSE_WRITABLE);
27078
27817
  if (responseWritable) {
27079
27818
  data.responseWritable = responseWritable;
27080
27819
  }
27081
- if (value.signal && (value.signal.aborted || value.signal[ABORT_STREAM_NAME])) {
27082
- data.signal = value.signal;
27820
+ const signal = readProperty(value, "signal");
27821
+ if (signal && (readProperty(signal, "aborted") || readProperty(signal, ABORT_STREAM_NAME))) {
27822
+ data.signal = signal;
27083
27823
  }
27084
27824
  return data;
27085
27825
  }, "Request"),
27086
27826
  Response: /* @__PURE__ */ __name((value) => {
27087
- if (!(value instanceof global2.Response)) return false;
27827
+ if (!isInstanceOfPrototype(value, getHostClassPrototype(global2, "Response"))) return false;
27088
27828
  return {
27089
- type: value.type,
27090
- url: value.url,
27091
- status: value.status,
27092
- statusText: value.statusText,
27093
- headers: value.headers,
27094
- body: value.body,
27095
- redirected: value.redirected
27829
+ type: readProperty(value, "type"),
27830
+ url: readProperty(value, "url"),
27831
+ status: readProperty(value, "status"),
27832
+ statusText: readProperty(value, "statusText"),
27833
+ headers: readProperty(value, "headers"),
27834
+ body: readProperty(value, "body"),
27835
+ redirected: readProperty(value, "redirected")
27096
27836
  };
27097
27837
  }, "Response")
27098
27838
  };
@@ -27222,48 +27962,63 @@ function getExternalReducers(global2 = globalThis, ops, runId, cryptoKey, framed
27222
27962
  }, "AbortSignal")
27223
27963
  };
27224
27964
  }
27965
+ function getStreamPrototype(global2, kind) {
27966
+ return getHostClassPrototype(global2, `${kind}Stream`);
27967
+ }
27968
+ function getHostClassPrototype(global2, name) {
27969
+ const ctor = global2[name] ?? globalThis[name] ?? void 0;
27970
+ return typeof ctor === "function" ? ctor.prototype : void 0;
27971
+ }
27972
+ function getAbortControllerPrototype(global2) {
27973
+ const ctor = global2.AbortController ?? globalThis.AbortController;
27974
+ return typeof ctor === "function" ? ctor.prototype : void 0;
27975
+ }
27976
+ function getAbortSignalPrototype(global2) {
27977
+ const ctor = global2.AbortSignal ?? globalThis.AbortSignal;
27978
+ return typeof ctor === "function" ? ctor.prototype : void 0;
27979
+ }
27225
27980
  function getWorkflowReducers(global2 = globalThis) {
27226
27981
  return {
27227
27982
  ...getAllBaseReducers(global2),
27228
27983
  // Readable/Writable streams from within the workflow execution environment
27229
27984
  // are simply "handles" that can be passed around to other steps.
27230
27985
  ReadableStream: /* @__PURE__ */ __name((value) => {
27231
- if (!(value instanceof global2.ReadableStream)) return false;
27232
- const bodyInit = value[BODY_INIT_SYMBOL];
27986
+ if (!isInstanceOfPrototype(value, getStreamPrototype(global2, "Readable"))) return false;
27987
+ const bodyInit = readProperty(value, BODY_INIT_SYMBOL);
27233
27988
  if (bodyInit !== void 0) {
27234
27989
  return {
27235
27990
  bodyInit
27236
27991
  };
27237
27992
  }
27238
- const name = value[STREAM_NAME_SYMBOL];
27993
+ const name = readProperty(value, STREAM_NAME_SYMBOL);
27239
27994
  if (!name) {
27240
27995
  throw new WorkflowRuntimeError("ReadableStream `name` is not set");
27241
27996
  }
27242
27997
  const s = {
27243
27998
  name
27244
27999
  };
27245
- const type = value[STREAM_TYPE_SYMBOL];
28000
+ const type = readProperty(value, STREAM_TYPE_SYMBOL);
27246
28001
  if (type) s.type = type;
27247
- const framing = value[STREAM_FRAMING_SYMBOL];
28002
+ const framing = readProperty(value, STREAM_FRAMING_SYMBOL);
27248
28003
  if (framing) s.framing = framing;
27249
28004
  return s;
27250
28005
  }, "ReadableStream"),
27251
28006
  WritableStream: /* @__PURE__ */ __name((value) => {
27252
- if (!(value instanceof global2.WritableStream)) return false;
27253
- const name = value[STREAM_NAME_SYMBOL];
28007
+ if (!isInstanceOfPrototype(value, getStreamPrototype(global2, "Writable"))) return false;
28008
+ const name = readProperty(value, STREAM_NAME_SYMBOL);
27254
28009
  if (!name) {
27255
28010
  throw new WorkflowRuntimeError("WritableStream `name` is not set");
27256
28011
  }
27257
28012
  const s = {
27258
28013
  name
27259
28014
  };
27260
- const foreignRunId = value[STREAM_SERVER_RUN_ID_SYMBOL];
28015
+ const foreignRunId = readProperty(value, STREAM_SERVER_RUN_ID_SYMBOL);
27261
28016
  if (typeof foreignRunId === "string") s.runId = foreignRunId;
27262
- const foreignDeploymentId = value[STREAM_SERVER_DEPLOYMENT_ID_SYMBOL];
28017
+ const foreignDeploymentId = readProperty(value, STREAM_SERVER_DEPLOYMENT_ID_SYMBOL);
27263
28018
  if (typeof foreignDeploymentId === "string") {
27264
28019
  s.deploymentId = foreignDeploymentId;
27265
28020
  }
27266
- const foreignPublicKey = value[STREAM_SERVER_PUBLIC_KEY_SYMBOL];
28021
+ const foreignPublicKey = readProperty(value, STREAM_SERVER_PUBLIC_KEY_SYMBOL);
27267
28022
  if (typeof foreignPublicKey === "string") {
27268
28023
  s.encryptionPublicKey = foreignPublicKey;
27269
28024
  }
@@ -27274,17 +28029,24 @@ function getWorkflowReducers(global2 = globalThis) {
27274
28029
  // is a plain object (not a class), so instanceof checks won't work for signals.
27275
28030
  // Detect instances by the presence of the ABORT_STREAM_NAME symbol instead.
27276
28031
  AbortController: /* @__PURE__ */ __name((value) => {
27277
- if (!value || !value.signal) return false;
28032
+ if (value === null || typeof value !== "object") return false;
27278
28033
  const holder = value;
27279
- const hasAbortSymbol = holder[ABORT_STREAM_NAME] ?? holder.signal?.[ABORT_STREAM_NAME];
27280
- const isNativeAbortController = global2.AbortController && typeof global2.AbortController === "function" && value instanceof global2.AbortController;
27281
- if (!hasAbortSymbol && !isNativeAbortController) return false;
27282
- return reduceAbortBySymbol(value.signal, holder);
28034
+ const ownSymbol = readProperty(value, ABORT_STREAM_NAME);
28035
+ const isNativeAbortController = isInstanceOfPrototype(value, getAbortControllerPrototype(global2));
28036
+ if (ownSymbol === void 0 && !isNativeAbortController) {
28037
+ const maybeSignal = readProperty(value, "signal");
28038
+ if (maybeSignal === null || typeof maybeSignal !== "object" || readProperty(maybeSignal, ABORT_STREAM_NAME) === void 0) {
28039
+ return false;
28040
+ }
28041
+ }
28042
+ const signal = readProperty(value, "signal");
28043
+ if (!signal) return false;
28044
+ return reduceAbortBySymbol(signal, holder);
27283
28045
  }, "AbortController"),
27284
28046
  AbortSignal: /* @__PURE__ */ __name((value) => {
27285
- const signal = value;
27286
- const hasAbortSymbol = signal?.[ABORT_STREAM_NAME];
27287
- const isNativeAbortSignal = global2.AbortSignal && typeof global2.AbortSignal === "function" && value instanceof global2.AbortSignal;
28047
+ if (value === null || typeof value !== "object") return false;
28048
+ const hasAbortSymbol = readProperty(value, ABORT_STREAM_NAME) !== void 0;
28049
+ const isNativeAbortSignal = isInstanceOfPrototype(value, getAbortSignalPrototype(global2));
27288
28050
  if (!hasAbortSymbol && !isNativeAbortSignal) return false;
27289
28051
  return reduceAbortBySymbol(value, value);
27290
28052
  }, "AbortSignal")
@@ -27812,20 +28574,25 @@ async function hydrateWorkflowReturnValue(value, runId, key, ops = [], global2 =
27812
28574
  await recordCompression(compressionStats, "deserialize");
27813
28575
  return result;
27814
28576
  }
27815
- async function dehydrateStepArguments(value, _runId, key, global2 = globalThis, v1Compat = false, compression = false) {
28577
+ async function dehydrateStepArguments(value, _runId, key, global2 = globalThis, v1Compat = false, compression = false, guestCodeStatsOut) {
27816
28578
  if (v1Compat) {
27817
28579
  const str = stringify(value, getWorkflowReducers(global2));
27818
28580
  return revive(str);
27819
28581
  }
27820
28582
  try {
27821
28583
  const compressionStats = {};
28584
+ const guestCodeStats = guestCodeStatsOut ?? {
28585
+ executions: []
28586
+ };
27822
28587
  const result = await serialize2(value, key, {
27823
28588
  global: global2,
27824
28589
  extraReducers: getStreamAndRequestReducers(getWorkflowReducers(global2)),
27825
28590
  compression,
27826
- compressionStats
28591
+ compressionStats,
28592
+ guestCodeStats
27827
28593
  });
27828
28594
  await recordCompression(compressionStats, "serialize");
28595
+ await recordGuestCodeExecutions(guestCodeStats);
27829
28596
  return result;
27830
28597
  } catch (error48) {
27831
28598
  const cause = unwrapSerializationCause(error48);
@@ -27919,7 +28686,6 @@ var init_serialization2 = __esm({
27919
28686
  init_dist4();
27920
28687
  init_devalue();
27921
28688
  init_node();
27922
- init_sealed_box();
27923
28689
  init_encryption();
27924
28690
  init_flushable_stream();
27925
28691
  init_private();
@@ -27930,6 +28696,7 @@ var init_serialization2 = __esm({
27930
28696
  init_encryption2();
27931
28697
  init_errors3();
27932
28698
  init_format();
28699
+ init_hardened();
27933
28700
  init_class();
27934
28701
  init_common();
27935
28702
  init_step_function();
@@ -27947,6 +28714,7 @@ var init_serialization2 = __esm({
27947
28714
  FRAME_HEADER_SIZE = 4;
27948
28715
  __name(unwrapSerializationCause, "unwrapSerializationCause");
27949
28716
  __name(recordCompression, "recordCompression");
28717
+ __name(recordGuestCodeExecutions, "recordGuestCodeExecutions");
27950
28718
  __name(getSerializeStream, "getSerializeStream");
27951
28719
  __name(getDeserializeStream, "getDeserializeStream");
27952
28720
  MAX_FRAME_SIZE = 1e8;
@@ -28071,7 +28839,7 @@ var init_serialization2 = __esm({
28071
28839
  let inFlight = null;
28072
28840
  let sinkError;
28073
28841
  let resolvedFlushIntervalMs = getEnvStreamFlushIntervalMs();
28074
- let flushIntervalResolution = null;
28842
+ let _flushIntervalResolution = null;
28075
28843
  const maxChunksPerRequest = getMaxChunksPerBatch();
28076
28844
  const maxBytesPerRequest = getMaxBytesPerBatch();
28077
28845
  const maxBufferedChunks = getMaxInflightChunks();
@@ -28169,7 +28937,7 @@ var init_serialization2 = __esm({
28169
28937
  const scheduleGroupCommit = /* @__PURE__ */ __name(() => {
28170
28938
  if (flushTimer || inFlight) return;
28171
28939
  if (resolvedFlushIntervalMs === void 0) {
28172
- flushIntervalResolution ??= Promise.resolve(worldPromise).then((world) => {
28940
+ _flushIntervalResolution ??= Promise.resolve(worldPromise).then((world) => {
28173
28941
  resolvedFlushIntervalMs = world.streamFlushIntervalMs ?? STREAM_FLUSH_INTERVAL_MS;
28174
28942
  }, () => {
28175
28943
  resolvedFlushIntervalMs = STREAM_FLUSH_INTERVAL_MS;
@@ -28257,6 +29025,10 @@ var init_serialization2 = __esm({
28257
29025
  __name(reduceAbortBySymbol, "reduceAbortBySymbol");
28258
29026
  __name(attachAbortListenerOnce, "attachAbortListenerOnce");
28259
29027
  __name(getExternalReducers, "getExternalReducers");
29028
+ __name(getStreamPrototype, "getStreamPrototype");
29029
+ __name(getHostClassPrototype, "getHostClassPrototype");
29030
+ __name(getAbortControllerPrototype, "getAbortControllerPrototype");
29031
+ __name(getAbortSignalPrototype, "getAbortSignalPrototype");
28260
29032
  __name(getWorkflowReducers, "getWorkflowReducers");
28261
29033
  __name(getStepReducers, "getStepReducers");
28262
29034
  __name(setupAbortStreamReader, "setupAbortStreamReader");
@@ -28432,43 +29204,7 @@ __name(normalizeAttributeChanges, "normalizeAttributeChanges");
28432
29204
 
28433
29205
  // ../core/dist/runtime/start.js
28434
29206
  init_capabilities();
28435
-
28436
- // ../core/dist/classify-error.js
28437
- init_dist2();
28438
- var WORLD_CONTRACT_ERROR_CODES = /* @__PURE__ */ new Set([
28439
- "PARSE_ERROR",
28440
- "SCHEMA_VALIDATION",
28441
- RUN_ERROR_CODES.WORLD_CONTRACT_ERROR
28442
- ]);
28443
- var RETRYABLE_WORLD_ERROR_CODES = /* @__PURE__ */ new Set([
28444
- "TRANSPORT",
28445
- "TIMEOUT"
28446
- ]);
28447
- var RUNTIME_ERROR_CHECKS = [
28448
- WorkflowRuntimeError.is,
28449
- StepNotRegisteredError.is,
28450
- WorkflowNotRegisteredError.is,
28451
- // SDK-level encryption failures (most notably AES-GCM auth-tag
28452
- // mismatches surfacing as a native `OperationError` from
28453
- // `AESCipherJob.onDone`) are wrapped in `RuntimeDecryptionError` at
28454
- // the encryption module boundary.
28455
- RuntimeDecryptionError.is
28456
- ];
28457
- function isRetryableWorldError(err) {
28458
- if (ThrottleError.is(err)) {
28459
- return true;
28460
- }
28461
- if (!WorkflowWorldError.is(err)) {
28462
- return false;
28463
- }
28464
- if (err.status !== void 0 && err.status >= 500) {
28465
- return true;
28466
- }
28467
- return err.code !== void 0 && RETRYABLE_WORLD_ERROR_CODES.has(err.code);
28468
- }
28469
- __name(isRetryableWorldError, "isRetryableWorldError");
28470
-
28471
- // ../core/dist/runtime/start.js
29207
+ init_classify_error();
28472
29208
  init_encryption();
28473
29209
  init_logger();
28474
29210
  init_sealed_box();
@@ -28538,13 +29274,16 @@ async function start(workflow, argsOrOptions, options) {
28538
29274
  const runId = `wrun_${world.createRunId ? world.createRunId(opts) : ulid3()}`;
28539
29275
  let framedByteStreams;
28540
29276
  let targetSupportsCompression;
29277
+ let targetHookResumeInputVersion;
28541
29278
  let probedRunPublicKey;
28542
29279
  if (deploymentId === currentDeploymentId) {
28543
29280
  framedByteStreams = true;
28544
29281
  targetSupportsCompression = true;
29282
+ targetHookResumeInputVersion = HOOK_RESUME_INPUT_VERSION;
28545
29283
  } else if (typeof world.streams?.get !== "function") {
28546
29284
  framedByteStreams = false;
28547
29285
  targetSupportsCompression = false;
29286
+ targetHookResumeInputVersion = void 0;
28548
29287
  } else {
28549
29288
  const probe = await healthCheck(world, {
28550
29289
  deploymentId,
@@ -28556,6 +29295,7 @@ async function start(workflow, argsOrOptions, options) {
28556
29295
  const capabilities = getRunCapabilities(probe?.workflowCoreVersion);
28557
29296
  framedByteStreams = capabilities.framedByteStreams;
28558
29297
  targetSupportsCompression = capabilities.supportedFormats.has(SerializationFormat.GZIP);
29298
+ targetHookResumeInputVersion = probe?.hookResumeInputVersion;
28559
29299
  }
28560
29300
  const ops = [];
28561
29301
  const traceCarrier = await serializeTraceCarrier();
@@ -28610,12 +29350,25 @@ async function start(workflow, argsOrOptions, options) {
28610
29350
  }
28611
29351
  const compression = targetSupportsCompression && specVersion >= SPEC_VERSION_SUPPORTS_COMPRESSION;
28612
29352
  const workflowArguments = await dehydrateWorkflowArguments(args, runId, encryptionKey, ops, globalThis, v1Compat, framedByteStreams, compression);
29353
+ const creatorEnvironment = world.getEnvironment?.();
28613
29354
  const executionContext = {
28614
29355
  traceCarrier,
28615
29356
  workflowCoreVersion: version2,
28616
29357
  features: {
28617
29358
  encryption: !!encryptionKey
28618
29359
  },
29360
+ // Attest that the *consumer* deployment's runtime re-ensures a
29361
+ // `hook_received` event from a queue message's `hookInput` on replay.
29362
+ // A resume of this run reads the marker (mirrored onto the hook's
29363
+ // resumeContext by the server) to decide whether the parallel fast
29364
+ // path is safe. For a cross-deployment start the consumer is the
29365
+ // target deployment, so we stamp the *target's* value carried back on
29366
+ // the health-check probe — never the caller's. Omitted when we could
29367
+ // not attest the target (older target, timeout, or no probe channel),
29368
+ // which fails the resume gate closed to the sequential path.
29369
+ ...targetHookResumeInputVersion !== void 0 ? {
29370
+ hookResumeInputVersion: targetHookResumeInputVersion
29371
+ } : {},
28619
29372
  ...opts.replayedFromRunId ? {
28620
29373
  replayedFromRunId: opts.replayedFromRunId
28621
29374
  } : {}
@@ -28650,6 +29403,9 @@ async function start(workflow, argsOrOptions, options) {
28650
29403
  ...encryptionPublicKey ? {
28651
29404
  encryptionPublicKey
28652
29405
  } : {},
29406
+ ...creatorEnvironment !== void 0 ? {
29407
+ environment: creatorEnvironment
29408
+ } : {},
28653
29409
  ...attributeSeed
28654
29410
  }
28655
29411
  } : {}
@@ -28716,7 +29472,7 @@ __name(start, "start");
28716
29472
  value: "start",
28717
29473
  configurable: true
28718
29474
  });
28719
- })(start, "step//@workflow/core/runtime/start@5.0.0-beta.38//start");
29475
+ })(start, "step//@workflow/core/runtime/start@5.0.0-beta.39//start");
28720
29476
 
28721
29477
  // ../core/dist/runtime/runs.js
28722
29478
  async function wakeUpRun(world, runId, options) {
@@ -29052,7 +29808,7 @@ var Run = class _Run {
29052
29808
  value: "wakeUp",
29053
29809
  configurable: true
29054
29810
  });
29055
- })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#wakeUp");
29811
+ })(Run.prototype["wakeUp"], "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#wakeUp");
29056
29812
  (function(__wf_fn, __wf_id) {
29057
29813
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29058
29814
  __wf_reg.set(__wf_id, __wf_fn);
@@ -29061,7 +29817,7 @@ var Run = class _Run {
29061
29817
  value: "cancel",
29062
29818
  configurable: true
29063
29819
  });
29064
- })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#cancel");
29820
+ })(Run.prototype["cancel"], "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#cancel");
29065
29821
  (function(__wf_fn, __wf_id) {
29066
29822
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29067
29823
  __wf_reg.set(__wf_id, __wf_fn);
@@ -29070,7 +29826,7 @@ var Run = class _Run {
29070
29826
  value: "getReadable",
29071
29827
  configurable: true
29072
29828
  });
29073
- })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#getReadable");
29829
+ })(Run.prototype["getReadable"], "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#getReadable");
29074
29830
  (function(__wf_fn, __wf_id) {
29075
29831
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29076
29832
  __wf_reg.set(__wf_id, __wf_fn);
@@ -29079,7 +29835,7 @@ var Run = class _Run {
29079
29835
  value: "exists",
29080
29836
  configurable: true
29081
29837
  });
29082
- })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#exists");
29838
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "exists").get, "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#exists");
29083
29839
  (function(__wf_fn, __wf_id) {
29084
29840
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29085
29841
  __wf_reg.set(__wf_id, __wf_fn);
@@ -29088,7 +29844,7 @@ var Run = class _Run {
29088
29844
  value: "status",
29089
29845
  configurable: true
29090
29846
  });
29091
- })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#status");
29847
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "status").get, "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#status");
29092
29848
  (function(__wf_fn, __wf_id) {
29093
29849
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29094
29850
  __wf_reg.set(__wf_id, __wf_fn);
@@ -29097,7 +29853,7 @@ var Run = class _Run {
29097
29853
  value: "returnValue",
29098
29854
  configurable: true
29099
29855
  });
29100
- })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#returnValue");
29856
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "returnValue").get, "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#returnValue");
29101
29857
  (function(__wf_fn, __wf_id) {
29102
29858
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29103
29859
  __wf_reg.set(__wf_id, __wf_fn);
@@ -29106,7 +29862,7 @@ var Run = class _Run {
29106
29862
  value: "workflowName",
29107
29863
  configurable: true
29108
29864
  });
29109
- })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#workflowName");
29865
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "workflowName").get, "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#workflowName");
29110
29866
  (function(__wf_fn, __wf_id) {
29111
29867
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29112
29868
  __wf_reg.set(__wf_id, __wf_fn);
@@ -29115,7 +29871,7 @@ var Run = class _Run {
29115
29871
  value: "createdAt",
29116
29872
  configurable: true
29117
29873
  });
29118
- })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#createdAt");
29874
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "createdAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#createdAt");
29119
29875
  (function(__wf_fn, __wf_id) {
29120
29876
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29121
29877
  __wf_reg.set(__wf_id, __wf_fn);
@@ -29124,7 +29880,7 @@ var Run = class _Run {
29124
29880
  value: "startedAt",
29125
29881
  configurable: true
29126
29882
  });
29127
- })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#startedAt");
29883
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "startedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#startedAt");
29128
29884
  (function(__wf_fn, __wf_id) {
29129
29885
  var __wf_sym = /* @__PURE__ */ Symbol.for("@workflow/core//registeredSteps"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29130
29886
  __wf_reg.set(__wf_id, __wf_fn);
@@ -29133,7 +29889,7 @@ var Run = class _Run {
29133
29889
  value: "completedAt",
29134
29890
  configurable: true
29135
29891
  });
29136
- })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.38//Run#completedAt");
29892
+ })(Object.getOwnPropertyDescriptor(Run.prototype, "completedAt").get, "step//@workflow/core/runtime/run@5.0.0-beta.39//Run#completedAt");
29137
29893
  (function(__wf_cls, __wf_id) {
29138
29894
  var __wf_sym = /* @__PURE__ */ Symbol.for("workflow-class-registry"), __wf_reg = globalThis[__wf_sym] || (globalThis[__wf_sym] = /* @__PURE__ */ new Map());
29139
29895
  __wf_reg.set(__wf_id, __wf_cls);
@@ -29143,7 +29899,7 @@ var Run = class _Run {
29143
29899
  enumerable: false,
29144
29900
  configurable: false
29145
29901
  });
29146
- })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.38//Run");
29902
+ })(Run, "class//@workflow/core/runtime/run@5.0.0-beta.39//Run");
29147
29903
 
29148
29904
  // ../workflow/dist/stdlib.js
29149
29905
  async function fetch2(...args) {
@@ -29250,7 +30006,9 @@ function renderPlain(c) {
29250
30006
  const first = isLast ? "\u2570\u25B6 " : "\u251C\u25B6 ";
29251
30007
  const cont = isLast ? " " : "\u2502 ";
29252
30008
  const raw = renderDetailPlain(detail).split("\n");
29253
- raw.forEach((line, i) => lines.push(`${i === 0 ? first : cont}${line}`));
30009
+ raw.forEach((line, i) => {
30010
+ lines.push(`${i === 0 ? first : cont}${line}`);
30011
+ });
29254
30012
  });
29255
30013
  return lines.join("\n");
29256
30014
  }