@workflow/world-testing 4.1.0-beta.65 → 4.1.0-beta.67

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.
@@ -45611,6 +45611,193 @@ var WaitSchema = external_exports.object({
45611
45611
  specVersion: external_exports.number().optional()
45612
45612
  });
45613
45613
 
45614
+ // ../../node_modules/.pnpm/ulid@3.0.1/node_modules/ulid/dist/node/index.js
45615
+ var import_node_crypto = __toESM(require("node:crypto"), 1);
45616
+ var ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
45617
+ var ENCODING_LEN = 32;
45618
+ var RANDOM_LEN = 16;
45619
+ var TIME_LEN = 10;
45620
+ var TIME_MAX = 281474976710655;
45621
+ var ULIDErrorCode;
45622
+ (function(ULIDErrorCode2) {
45623
+ ULIDErrorCode2["Base32IncorrectEncoding"] = "B32_ENC_INVALID";
45624
+ ULIDErrorCode2["DecodeTimeInvalidCharacter"] = "DEC_TIME_CHAR";
45625
+ ULIDErrorCode2["DecodeTimeValueMalformed"] = "DEC_TIME_MALFORMED";
45626
+ ULIDErrorCode2["EncodeTimeNegative"] = "ENC_TIME_NEG";
45627
+ ULIDErrorCode2["EncodeTimeSizeExceeded"] = "ENC_TIME_SIZE_EXCEED";
45628
+ ULIDErrorCode2["EncodeTimeValueMalformed"] = "ENC_TIME_MALFORMED";
45629
+ ULIDErrorCode2["PRNGDetectFailure"] = "PRNG_DETECT";
45630
+ ULIDErrorCode2["ULIDInvalid"] = "ULID_INVALID";
45631
+ ULIDErrorCode2["Unexpected"] = "UNEXPECTED";
45632
+ ULIDErrorCode2["UUIDInvalid"] = "UUID_INVALID";
45633
+ })(ULIDErrorCode || (ULIDErrorCode = {}));
45634
+ var ULIDError = class extends Error {
45635
+ static {
45636
+ __name(this, "ULIDError");
45637
+ }
45638
+ constructor(errorCode, message) {
45639
+ super(`${message} (${errorCode})`);
45640
+ this.name = "ULIDError";
45641
+ this.code = errorCode;
45642
+ }
45643
+ };
45644
+ function randomChar(prng) {
45645
+ const randomPosition = Math.floor(prng() * ENCODING_LEN) % ENCODING_LEN;
45646
+ return ENCODING.charAt(randomPosition);
45647
+ }
45648
+ __name(randomChar, "randomChar");
45649
+ function replaceCharAt(str, index, char) {
45650
+ if (index > str.length - 1) {
45651
+ return str;
45652
+ }
45653
+ return str.substr(0, index) + char + str.substr(index + 1);
45654
+ }
45655
+ __name(replaceCharAt, "replaceCharAt");
45656
+ function incrementBase32(str) {
45657
+ let done = void 0, index = str.length, char, charIndex, output = str;
45658
+ const maxCharIndex = ENCODING_LEN - 1;
45659
+ while (!done && index-- >= 0) {
45660
+ char = output[index];
45661
+ charIndex = ENCODING.indexOf(char);
45662
+ if (charIndex === -1) {
45663
+ throw new ULIDError(ULIDErrorCode.Base32IncorrectEncoding, "Incorrectly encoded string");
45664
+ }
45665
+ if (charIndex === maxCharIndex) {
45666
+ output = replaceCharAt(output, index, ENCODING[0]);
45667
+ continue;
45668
+ }
45669
+ done = replaceCharAt(output, index, ENCODING[charIndex + 1]);
45670
+ }
45671
+ if (typeof done === "string") {
45672
+ return done;
45673
+ }
45674
+ throw new ULIDError(ULIDErrorCode.Base32IncorrectEncoding, "Failed incrementing string");
45675
+ }
45676
+ __name(incrementBase32, "incrementBase32");
45677
+ function decodeTime(id) {
45678
+ if (id.length !== TIME_LEN + RANDOM_LEN) {
45679
+ throw new ULIDError(ULIDErrorCode.DecodeTimeValueMalformed, "Malformed ULID");
45680
+ }
45681
+ const time3 = id.substr(0, TIME_LEN).toUpperCase().split("").reverse().reduce((carry, char, index) => {
45682
+ const encodingIndex = ENCODING.indexOf(char);
45683
+ if (encodingIndex === -1) {
45684
+ throw new ULIDError(ULIDErrorCode.DecodeTimeInvalidCharacter, `Time decode error: Invalid character: ${char}`);
45685
+ }
45686
+ return carry += encodingIndex * Math.pow(ENCODING_LEN, index);
45687
+ }, 0);
45688
+ if (time3 > TIME_MAX) {
45689
+ throw new ULIDError(ULIDErrorCode.DecodeTimeValueMalformed, `Malformed ULID: timestamp too large: ${time3}`);
45690
+ }
45691
+ return time3;
45692
+ }
45693
+ __name(decodeTime, "decodeTime");
45694
+ function detectPRNG(root) {
45695
+ const rootLookup = detectRoot();
45696
+ const globalCrypto = rootLookup && (rootLookup.crypto || rootLookup.msCrypto) || (typeof import_node_crypto.default !== "undefined" ? import_node_crypto.default : null);
45697
+ if (typeof globalCrypto?.getRandomValues === "function") {
45698
+ return () => {
45699
+ const buffer = new Uint8Array(1);
45700
+ globalCrypto.getRandomValues(buffer);
45701
+ return buffer[0] / 255;
45702
+ };
45703
+ } else if (typeof globalCrypto?.randomBytes === "function") {
45704
+ return () => globalCrypto.randomBytes(1).readUInt8() / 255;
45705
+ } else if (import_node_crypto.default?.randomBytes) {
45706
+ return () => import_node_crypto.default.randomBytes(1).readUInt8() / 255;
45707
+ }
45708
+ throw new ULIDError(ULIDErrorCode.PRNGDetectFailure, "Failed to find a reliable PRNG");
45709
+ }
45710
+ __name(detectPRNG, "detectPRNG");
45711
+ function detectRoot() {
45712
+ if (inWebWorker())
45713
+ return self;
45714
+ if (typeof window !== "undefined") {
45715
+ return window;
45716
+ }
45717
+ if (typeof global !== "undefined") {
45718
+ return global;
45719
+ }
45720
+ if (typeof globalThis !== "undefined") {
45721
+ return globalThis;
45722
+ }
45723
+ return null;
45724
+ }
45725
+ __name(detectRoot, "detectRoot");
45726
+ function encodeRandom(len, prng) {
45727
+ let str = "";
45728
+ for (; len > 0; len--) {
45729
+ str = randomChar(prng) + str;
45730
+ }
45731
+ return str;
45732
+ }
45733
+ __name(encodeRandom, "encodeRandom");
45734
+ function encodeTime(now, len = TIME_LEN) {
45735
+ if (isNaN(now)) {
45736
+ throw new ULIDError(ULIDErrorCode.EncodeTimeValueMalformed, `Time must be a number: ${now}`);
45737
+ } else if (now > TIME_MAX) {
45738
+ throw new ULIDError(ULIDErrorCode.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${TIME_MAX}: ${now}`);
45739
+ } else if (now < 0) {
45740
+ throw new ULIDError(ULIDErrorCode.EncodeTimeNegative, `Time must be positive: ${now}`);
45741
+ } else if (Number.isInteger(now) === false) {
45742
+ throw new ULIDError(ULIDErrorCode.EncodeTimeValueMalformed, `Time must be an integer: ${now}`);
45743
+ }
45744
+ let mod, str = "";
45745
+ for (let currentLen = len; currentLen > 0; currentLen--) {
45746
+ mod = now % ENCODING_LEN;
45747
+ str = ENCODING.charAt(mod) + str;
45748
+ now = (now - mod) / ENCODING_LEN;
45749
+ }
45750
+ return str;
45751
+ }
45752
+ __name(encodeTime, "encodeTime");
45753
+ function inWebWorker() {
45754
+ return typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope;
45755
+ }
45756
+ __name(inWebWorker, "inWebWorker");
45757
+ function monotonicFactory(prng) {
45758
+ const currentPRNG = prng || detectPRNG();
45759
+ let lastTime = 0, lastRandom;
45760
+ return /* @__PURE__ */ __name(function _ulid2(seedTime) {
45761
+ const seed = !seedTime || isNaN(seedTime) ? Date.now() : seedTime;
45762
+ if (seed <= lastTime) {
45763
+ const incrementedRandom = lastRandom = incrementBase32(lastRandom);
45764
+ return encodeTime(lastTime, TIME_LEN) + incrementedRandom;
45765
+ }
45766
+ lastTime = seed;
45767
+ const newRandom = lastRandom = encodeRandom(RANDOM_LEN, currentPRNG);
45768
+ return encodeTime(seed, TIME_LEN) + newRandom;
45769
+ }, "_ulid");
45770
+ }
45771
+ __name(monotonicFactory, "monotonicFactory");
45772
+
45773
+ // ../world/dist/ulid.js
45774
+ var UlidSchema = external_exports.string().ulid();
45775
+ var DEFAULT_TIMESTAMP_THRESHOLD_MS = 5 * 60 * 1e3;
45776
+ function ulidToDate(maybeUlid) {
45777
+ const ulid5 = UlidSchema.safeParse(maybeUlid);
45778
+ if (!ulid5.success) {
45779
+ return null;
45780
+ }
45781
+ return new Date(decodeTime(ulid5.data));
45782
+ }
45783
+ __name(ulidToDate, "ulidToDate");
45784
+ function validateUlidTimestamp(prefixedUlid, prefix, thresholdMs = DEFAULT_TIMESTAMP_THRESHOLD_MS) {
45785
+ const raw = prefixedUlid.startsWith(prefix) ? prefixedUlid.slice(prefix.length) : prefixedUlid;
45786
+ const ulidTimestamp = ulidToDate(raw);
45787
+ if (!ulidTimestamp) {
45788
+ return `Invalid runId: "${prefixedUlid}" is not a valid ULID`;
45789
+ }
45790
+ const serverTimestamp = /* @__PURE__ */ new Date();
45791
+ const driftMs = Math.abs(serverTimestamp.getTime() - ulidTimestamp.getTime());
45792
+ if (driftMs <= thresholdMs) {
45793
+ return null;
45794
+ }
45795
+ const driftSeconds = Math.round(driftMs / 1e3);
45796
+ const thresholdSeconds = Math.round(thresholdMs / 1e3);
45797
+ return `Invalid runId timestamp: embedded timestamp differs from server time by ${driftSeconds}s (threshold: ${thresholdSeconds}s)`;
45798
+ }
45799
+ __name(validateUlidTimestamp, "validateUlidTimestamp");
45800
+
45614
45801
  // ../core/dist/encryption.js
45615
45802
  var NONCE_LENGTH = 12;
45616
45803
  var TAG_LENGTH = 128;
@@ -45948,169 +46135,13 @@ var webhookLogger = createLogger("webhook");
45948
46135
  var eventsLogger = createLogger("events");
45949
46136
  var adapterLogger = createLogger("adapter");
45950
46137
 
45951
- // ../../node_modules/.pnpm/ulid@3.0.1/node_modules/ulid/dist/node/index.js
45952
- var import_node_crypto = __toESM(require("node:crypto"), 1);
45953
- var ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
45954
- var ENCODING_LEN = 32;
45955
- var RANDOM_LEN = 16;
45956
- var TIME_LEN = 10;
45957
- var TIME_MAX = 281474976710655;
45958
- var ULIDErrorCode;
45959
- (function(ULIDErrorCode2) {
45960
- ULIDErrorCode2["Base32IncorrectEncoding"] = "B32_ENC_INVALID";
45961
- ULIDErrorCode2["DecodeTimeInvalidCharacter"] = "DEC_TIME_CHAR";
45962
- ULIDErrorCode2["DecodeTimeValueMalformed"] = "DEC_TIME_MALFORMED";
45963
- ULIDErrorCode2["EncodeTimeNegative"] = "ENC_TIME_NEG";
45964
- ULIDErrorCode2["EncodeTimeSizeExceeded"] = "ENC_TIME_SIZE_EXCEED";
45965
- ULIDErrorCode2["EncodeTimeValueMalformed"] = "ENC_TIME_MALFORMED";
45966
- ULIDErrorCode2["PRNGDetectFailure"] = "PRNG_DETECT";
45967
- ULIDErrorCode2["ULIDInvalid"] = "ULID_INVALID";
45968
- ULIDErrorCode2["Unexpected"] = "UNEXPECTED";
45969
- ULIDErrorCode2["UUIDInvalid"] = "UUID_INVALID";
45970
- })(ULIDErrorCode || (ULIDErrorCode = {}));
45971
- var ULIDError = class extends Error {
45972
- static {
45973
- __name(this, "ULIDError");
45974
- }
45975
- constructor(errorCode, message) {
45976
- super(`${message} (${errorCode})`);
45977
- this.name = "ULIDError";
45978
- this.code = errorCode;
45979
- }
45980
- };
45981
- function randomChar(prng) {
45982
- const randomPosition = Math.floor(prng() * ENCODING_LEN) % ENCODING_LEN;
45983
- return ENCODING.charAt(randomPosition);
45984
- }
45985
- __name(randomChar, "randomChar");
45986
- function replaceCharAt(str, index, char) {
45987
- if (index > str.length - 1) {
45988
- return str;
45989
- }
45990
- return str.substr(0, index) + char + str.substr(index + 1);
45991
- }
45992
- __name(replaceCharAt, "replaceCharAt");
45993
- function incrementBase32(str) {
45994
- let done = void 0, index = str.length, char, charIndex, output = str;
45995
- const maxCharIndex = ENCODING_LEN - 1;
45996
- while (!done && index-- >= 0) {
45997
- char = output[index];
45998
- charIndex = ENCODING.indexOf(char);
45999
- if (charIndex === -1) {
46000
- throw new ULIDError(ULIDErrorCode.Base32IncorrectEncoding, "Incorrectly encoded string");
46001
- }
46002
- if (charIndex === maxCharIndex) {
46003
- output = replaceCharAt(output, index, ENCODING[0]);
46004
- continue;
46005
- }
46006
- done = replaceCharAt(output, index, ENCODING[charIndex + 1]);
46007
- }
46008
- if (typeof done === "string") {
46009
- return done;
46010
- }
46011
- throw new ULIDError(ULIDErrorCode.Base32IncorrectEncoding, "Failed incrementing string");
46012
- }
46013
- __name(incrementBase32, "incrementBase32");
46014
- function decodeTime(id) {
46015
- if (id.length !== TIME_LEN + RANDOM_LEN) {
46016
- throw new ULIDError(ULIDErrorCode.DecodeTimeValueMalformed, "Malformed ULID");
46017
- }
46018
- const time3 = id.substr(0, TIME_LEN).toUpperCase().split("").reverse().reduce((carry, char, index) => {
46019
- const encodingIndex = ENCODING.indexOf(char);
46020
- if (encodingIndex === -1) {
46021
- throw new ULIDError(ULIDErrorCode.DecodeTimeInvalidCharacter, `Time decode error: Invalid character: ${char}`);
46022
- }
46023
- return carry += encodingIndex * Math.pow(ENCODING_LEN, index);
46024
- }, 0);
46025
- if (time3 > TIME_MAX) {
46026
- throw new ULIDError(ULIDErrorCode.DecodeTimeValueMalformed, `Malformed ULID: timestamp too large: ${time3}`);
46027
- }
46028
- return time3;
46029
- }
46030
- __name(decodeTime, "decodeTime");
46031
- function detectPRNG(root) {
46032
- const rootLookup = detectRoot();
46033
- const globalCrypto = rootLookup && (rootLookup.crypto || rootLookup.msCrypto) || (typeof import_node_crypto.default !== "undefined" ? import_node_crypto.default : null);
46034
- if (typeof globalCrypto?.getRandomValues === "function") {
46035
- return () => {
46036
- const buffer = new Uint8Array(1);
46037
- globalCrypto.getRandomValues(buffer);
46038
- return buffer[0] / 255;
46039
- };
46040
- } else if (typeof globalCrypto?.randomBytes === "function") {
46041
- return () => globalCrypto.randomBytes(1).readUInt8() / 255;
46042
- } else if (import_node_crypto.default?.randomBytes) {
46043
- return () => import_node_crypto.default.randomBytes(1).readUInt8() / 255;
46044
- }
46045
- throw new ULIDError(ULIDErrorCode.PRNGDetectFailure, "Failed to find a reliable PRNG");
46046
- }
46047
- __name(detectPRNG, "detectPRNG");
46048
- function detectRoot() {
46049
- if (inWebWorker())
46050
- return self;
46051
- if (typeof window !== "undefined") {
46052
- return window;
46053
- }
46054
- if (typeof global !== "undefined") {
46055
- return global;
46056
- }
46057
- if (typeof globalThis !== "undefined") {
46058
- return globalThis;
46059
- }
46060
- return null;
46061
- }
46062
- __name(detectRoot, "detectRoot");
46063
- function encodeRandom(len, prng) {
46064
- let str = "";
46065
- for (; len > 0; len--) {
46066
- str = randomChar(prng) + str;
46067
- }
46068
- return str;
46069
- }
46070
- __name(encodeRandom, "encodeRandom");
46071
- function encodeTime(now, len = TIME_LEN) {
46072
- if (isNaN(now)) {
46073
- throw new ULIDError(ULIDErrorCode.EncodeTimeValueMalformed, `Time must be a number: ${now}`);
46074
- } else if (now > TIME_MAX) {
46075
- throw new ULIDError(ULIDErrorCode.EncodeTimeSizeExceeded, `Cannot encode a time larger than ${TIME_MAX}: ${now}`);
46076
- } else if (now < 0) {
46077
- throw new ULIDError(ULIDErrorCode.EncodeTimeNegative, `Time must be positive: ${now}`);
46078
- } else if (Number.isInteger(now) === false) {
46079
- throw new ULIDError(ULIDErrorCode.EncodeTimeValueMalformed, `Time must be an integer: ${now}`);
46080
- }
46081
- let mod, str = "";
46082
- for (let currentLen = len; currentLen > 0; currentLen--) {
46083
- mod = now % ENCODING_LEN;
46084
- str = ENCODING.charAt(mod) + str;
46085
- now = (now - mod) / ENCODING_LEN;
46086
- }
46087
- return str;
46088
- }
46089
- __name(encodeTime, "encodeTime");
46090
- function inWebWorker() {
46091
- return typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope;
46092
- }
46093
- __name(inWebWorker, "inWebWorker");
46094
- function monotonicFactory(prng) {
46095
- const currentPRNG = prng || detectPRNG();
46096
- let lastTime = 0, lastRandom;
46097
- return /* @__PURE__ */ __name(function _ulid2(seedTime) {
46098
- const seed = !seedTime || isNaN(seedTime) ? Date.now() : seedTime;
46099
- if (seed <= lastTime) {
46100
- const incrementedRandom = lastRandom = incrementBase32(lastRandom);
46101
- return encodeTime(lastTime, TIME_LEN) + incrementedRandom;
46102
- }
46103
- lastTime = seed;
46104
- const newRandom = lastRandom = encodeRandom(RANDOM_LEN, currentPRNG);
46105
- return encodeTime(seed, TIME_LEN) + newRandom;
46106
- }, "_ulid");
46107
- }
46108
- __name(monotonicFactory, "monotonicFactory");
46109
-
46110
46138
  // ../core/dist/runtime/world.js
46111
46139
  var import_node_module = require("node:module");
46112
46140
  var import_node_path9 = require("node:path");
46113
46141
 
46142
+ // ../world-local/dist/index.js
46143
+ var import_promises4 = require("node:fs/promises");
46144
+
46114
46145
  // ../utils/dist/get-port.js
46115
46146
  var import_node_child_process = require("node:child_process");
46116
46147
  var import_promises = require("node:fs/promises");
@@ -48982,6 +49013,7 @@ function createQueue(config3) {
48982
49013
  const generateId2 = monotonicFactory();
48983
49014
  const semaphore = new import_async_sema.Sema(WORKFLOW_LOCAL_QUEUE_CONCURRENCY);
48984
49015
  const inflightMessages = /* @__PURE__ */ new Map();
49016
+ const directHandlers = /* @__PURE__ */ new Map();
48985
49017
  const queue = /* @__PURE__ */ __name(async (queueName, message, opts) => {
48986
49018
  const cleanup = [];
48987
49019
  if (opts?.idempotencyKey) {
@@ -48992,10 +49024,13 @@ function createQueue(config3) {
48992
49024
  }
48993
49025
  const body = transport.serialize(message);
48994
49026
  let pathname;
49027
+ let prefix;
48995
49028
  if (queueName.startsWith("__wkf_step_")) {
48996
49029
  pathname = `step`;
49030
+ prefix = "__wkf_step_";
48997
49031
  } else if (queueName.startsWith("__wkf_workflow_")) {
48998
49032
  pathname = `flow`;
49033
+ prefix = "__wkf_workflow_";
48999
49034
  } else {
49000
49035
  throw new Error("Unknown queue name prefix");
49001
49036
  }
@@ -49015,22 +49050,34 @@ function createQueue(config3) {
49015
49050
  }
49016
49051
  try {
49017
49052
  let defaultRetriesLeft = 3;
49018
- const baseUrl = await resolveBaseUrl(config3);
49053
+ const directHandler = directHandlers.get(prefix);
49019
49054
  for (let attempt = 0; defaultRetriesLeft > 0; attempt++) {
49020
49055
  defaultRetriesLeft--;
49021
- const response = await fetch(`${baseUrl}/.well-known/workflow/v1/${pathname}`, {
49022
- method: "POST",
49023
- duplex: "half",
49024
- dispatcher: httpAgent,
49025
- headers: {
49026
- ...opts?.headers,
49027
- "content-type": "application/json",
49028
- "x-vqs-queue-name": queueName,
49029
- "x-vqs-message-id": messageId,
49030
- "x-vqs-message-attempt": String(attempt + 1)
49031
- },
49032
- body
49033
- });
49056
+ let response;
49057
+ const headers = {
49058
+ ...opts?.headers,
49059
+ "content-type": "application/json",
49060
+ "x-vqs-queue-name": queueName,
49061
+ "x-vqs-message-id": messageId,
49062
+ "x-vqs-message-attempt": String(attempt + 1)
49063
+ };
49064
+ if (directHandler) {
49065
+ const req = new Request("http://localhost/.well-known/workflow/v1/" + pathname, {
49066
+ method: "POST",
49067
+ headers,
49068
+ body
49069
+ });
49070
+ response = await directHandler(req);
49071
+ } else {
49072
+ const baseUrl = await resolveBaseUrl(config3);
49073
+ response = await fetch(`${baseUrl}/.well-known/workflow/v1/${pathname}`, {
49074
+ method: "POST",
49075
+ duplex: "half",
49076
+ dispatcher: httpAgent,
49077
+ headers,
49078
+ body
49079
+ });
49080
+ }
49034
49081
  if (response.ok) {
49035
49082
  return;
49036
49083
  }
@@ -49095,7 +49142,7 @@ function createQueue(config3) {
49095
49142
  if (typeof result?.timeoutSeconds === "number") {
49096
49143
  timeoutSeconds = Math.min(result.timeoutSeconds, LOCAL_QUEUE_MAX_VISIBILITY);
49097
49144
  }
49098
- if (timeoutSeconds) {
49145
+ if (timeoutSeconds != null) {
49099
49146
  return Response.json({ timeoutSeconds }, { status: 503 });
49100
49147
  }
49101
49148
  return Response.json({ ok: true });
@@ -49112,6 +49159,9 @@ function createQueue(config3) {
49112
49159
  queue,
49113
49160
  createQueueHandler,
49114
49161
  getDeploymentId,
49162
+ registerHandler(prefix, handler) {
49163
+ directHandlers.set(prefix, handler);
49164
+ },
49115
49165
  async close() {
49116
49166
  await httpAgent.close();
49117
49167
  }
@@ -49232,7 +49282,6 @@ var import_node_path5 = __toESM(require("node:path"), 1);
49232
49282
  var import_node_fs = require("node:fs");
49233
49283
  var import_node_path2 = __toESM(require("node:path"), 1);
49234
49284
  var ulid3 = monotonicFactory(() => Math.random());
49235
- var Ulid = external_exports.string().ulid();
49236
49285
  var isWindows = process.platform === "win32";
49237
49286
  async function withWindowsRetry(fn, maxRetries = 5) {
49238
49287
  if (!isWindows)
@@ -49254,14 +49303,6 @@ async function withWindowsRetry(fn, maxRetries = 5) {
49254
49303
  }
49255
49304
  __name(withWindowsRetry, "withWindowsRetry");
49256
49305
  var createdFilesCache = /* @__PURE__ */ new Set();
49257
- function ulidToDate(maybeUlid) {
49258
- const ulid5 = Ulid.safeParse(maybeUlid);
49259
- if (!ulid5.success) {
49260
- return null;
49261
- }
49262
- return new Date(decodeTime(ulid5.data));
49263
- }
49264
- __name(ulidToDate, "ulidToDate");
49265
49306
  async function ensureDir(dirPath) {
49266
49307
  try {
49267
49308
  await import_node_fs.promises.mkdir(dirPath, { recursive: true });
@@ -49672,6 +49713,12 @@ function createEventsStorage(basedir) {
49672
49713
  } else {
49673
49714
  effectiveRunId = runId;
49674
49715
  }
49716
+ if (data.eventType === "run_created" && runId && runId !== "") {
49717
+ const validationError = validateUlidTimestamp(effectiveRunId, "wrun_");
49718
+ if (validationError) {
49719
+ throw new WorkflowAPIError(validationError, { status: 400 });
49720
+ }
49721
+ }
49675
49722
  const effectiveSpecVersion = data.specVersion ?? SPEC_VERSION_CURRENT;
49676
49723
  const isRunTerminal = /* @__PURE__ */ __name((status) => ["completed", "failed", "cancelled"].includes(status), "isRunTerminal");
49677
49724
  const isStepTerminal = /* @__PURE__ */ __name((status) => ["completed", "failed"].includes(status), "isStepTerminal");
@@ -50486,6 +50533,10 @@ function createLocalWorld(args) {
50486
50533
  },
50487
50534
  async close() {
50488
50535
  await queue.close();
50536
+ },
50537
+ async clear() {
50538
+ await (0, import_promises4.rm)(mergedConfig.dataDir, { recursive: true, force: true });
50539
+ await initDataDir(mergedConfig.dataDir);
50489
50540
  }
50490
50541
  };
50491
50542
  }
@@ -53025,7 +53076,7 @@ var RpcService3 = SemanticConvention3("rpc.service");
53025
53076
  var RpcMethod3 = SemanticConvention3("rpc.method");
53026
53077
 
53027
53078
  // ../world-vercel/dist/version.js
53028
- var version2 = "4.1.0-beta.38";
53079
+ var version2 = "4.1.0-beta.40";
53029
53080
 
53030
53081
  // ../world-vercel/dist/utils.js
53031
53082
  var WORKFLOW_SERVER_URL_OVERRIDE = "";
@@ -53337,7 +53388,7 @@ function createQueue2(config3) {
53337
53388
  attempt: metadata.deliveryCount
53338
53389
  });
53339
53390
  if (typeof result?.timeoutSeconds === "number") {
53340
- const delaySeconds = Math.min(result.timeoutSeconds, MAX_DELAY_SECONDS);
53391
+ const delaySeconds = result.timeoutSeconds > 0 ? Math.min(result.timeoutSeconds, MAX_DELAY_SECONDS) : void 0;
53341
53392
  await queue(queueName, payload, { deploymentId, delaySeconds });
53342
53393
  }
53343
53394
  });
@@ -53885,6 +53936,12 @@ async function createWorkflowRunEvent(id, data, params, config3) {
53885
53936
  });
53886
53937
  return { event: wireResult2 };
53887
53938
  }
53939
+ if (data.eventType === "run_created" && id) {
53940
+ const validationError = validateUlidTimestamp(id, "wrun_");
53941
+ if (validationError) {
53942
+ throw new WorkflowAPIError(validationError, { status: 400 });
53943
+ }
53944
+ }
53888
53945
  const runIdPath = id === null ? "null" : id;
53889
53946
  const remoteRefBehavior = eventsNeedingResolve.has(data.eventType) ? "resolve" : "lazy";
53890
53947
  if (remoteRefBehavior === "resolve") {
@@ -56314,7 +56371,7 @@ async function handleSuspension({ suspension, world, run, span }) {
56314
56371
  ...WorkflowWaitsCreated(waitItems.length)
56315
56372
  });
56316
56373
  if (hasHookConflict) {
56317
- return { timeoutSeconds: 1 };
56374
+ return { timeoutSeconds: 0 };
56318
56375
  }
56319
56376
  if (minTimeoutSeconds !== null) {
56320
56377
  return { timeoutSeconds: minTimeoutSeconds };
@@ -57539,7 +57596,8 @@ async function runWorkflow(workflowCode2, workflowRun, events, encryptionKey) {
57539
57596
  if (!startedAt) {
57540
57597
  throw new Error(`Workflow run "${workflowRun.runId}" has no "startedAt" timestamp (should not happen)`);
57541
57598
  }
57542
- const port = await getPort();
57599
+ const isVercel = process.env.VERCEL_URL !== void 0;
57600
+ const port = isVercel ? void 0 : await getPort();
57543
57601
  const { context: context2, globalThis: vmGlobalThis, updateTimestamp } = createContext({
57544
57602
  seed: `${workflowRun.runId}:${workflowRun.workflowName}:${+startedAt}`,
57545
57603
  fixedTimestamp: +startedAt
@@ -57598,7 +57656,7 @@ async function runWorkflow(workflowCode2, workflowRun, events, encryptionKey) {
57598
57656
  vmGlobalThis[WORKFLOW_CREATE_HOOK] = createHook;
57599
57657
  vmGlobalThis[WORKFLOW_SLEEP] = sleep;
57600
57658
  vmGlobalThis[WORKFLOW_GET_STREAM_ID] = (namespace) => getWorkflowRunStreamId(workflowRun.runId, namespace);
57601
- const url2 = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : `http://localhost:${port ?? 3e3}`;
57659
+ const url2 = isVercel ? `https://${process.env.VERCEL_URL}` : `http://localhost:${port ?? 3e3}`;
57602
57660
  const ctx = {
57603
57661
  workflowRunId: workflowRun.runId,
57604
57662
  workflowStartedAt: new vmGlobalThis.Date(+startedAt),
@@ -58019,8 +58077,9 @@ var stepHandler = getWorldHandlers().createQueueHandler("__wkf_step_", async (me
58019
58077
  return await withTraceContext(traceContext, async () => {
58020
58078
  const stepName = metadata.queueName.slice("__wkf_step_".length);
58021
58079
  const world = getWorld();
58080
+ const isVercel = process.env.VERCEL_URL !== void 0;
58022
58081
  const [port, spanKind] = await Promise.all([
58023
- getPort(),
58082
+ isVercel ? void 0 : getPort(),
58024
58083
  getSpanKind("CONSUMER")
58025
58084
  ]);
58026
58085
  return trace2(`STEP ${stepName}`, { kind: spanKind, links: spanLinks }, async (span) => {
@@ -58205,7 +58264,7 @@ var stepHandler = getWorldHandlers().createQueueHandler("__wkf_step_", async (me
58205
58264
  workflowStartedAt: /* @__PURE__ */ new Date(+workflowStartedAt),
58206
58265
  // TODO: there should be a getUrl method on the world interface itself. This
58207
58266
  // solution only works for vercel + local worlds.
58208
- url: process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : `http://localhost:${port ?? 3e3}`
58267
+ url: isVercel ? `https://${process.env.VERCEL_URL}` : `http://localhost:${port ?? 3e3}`
58209
58268
  },
58210
58269
  ops,
58211
58270
  closureVars: hydratedInput.closureVars,
@@ -58882,7 +58941,7 @@ function getWritable(options = {}) {
58882
58941
  __name(getWritable, "getWritable");
58883
58942
 
58884
58943
  // ../workflow/dist/stdlib.js
58885
- var fetch = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//workflow@4.2.0-beta.64//fetch");
58944
+ var fetch = globalThis[/* @__PURE__ */ Symbol.for("WORKFLOW_USE_STEP")]("step//workflow@4.2.0-beta.66//fetch");
58886
58945
 
58887
58946
  // ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.js
58888
58947
  var NEVER = Object.freeze({