@trigger.dev/core 0.0.0-v3-canary-20240322220011 → 0.0.0-v3-canary-20240325170325

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/v3/index.js CHANGED
@@ -256,7 +256,8 @@ var BackgroundWorkerServerMessages = zod.z.discriminatedUnion("type", [
256
256
  id: zod.z.string(),
257
257
  image: zod.z.string(),
258
258
  envId: zod.z.string(),
259
- runId: zod.z.string()
259
+ runId: zod.z.string(),
260
+ version: zod.z.string()
260
261
  })
261
262
  ]);
262
263
  var serverWebsocketMessages = {
@@ -356,17 +357,62 @@ var RateLimitOptions = zod.z.discriminatedUnion("type", [
356
357
  SlidingWindowRateLimit
357
358
  ]);
358
359
  var RetryOptions = zod.z.object({
360
+ /** The number of attempts before giving up */
359
361
  maxAttempts: zod.z.number().int().optional(),
362
+ /** The exponential factor to use when calculating the next retry time.
363
+ *
364
+ * Each subsequent retry will be calculated as `previousTimeout * factor`
365
+ */
360
366
  factor: zod.z.number().optional(),
367
+ /** The minimum time to wait before retrying */
361
368
  minTimeoutInMs: zod.z.number().int().optional(),
369
+ /** The maximum time to wait before retrying */
362
370
  maxTimeoutInMs: zod.z.number().int().optional(),
371
+ /** Randomize the timeout between retries.
372
+ *
373
+ * This can be useful to prevent the thundering herd problem where all retries happen at the same time.
374
+ */
363
375
  randomize: zod.z.boolean().optional()
364
376
  });
365
377
  var QueueOptions = zod.z.object({
366
- /** @deprecated This feature is coming soon */
367
- rateLimit: RateLimitOptions.optional(),
378
+ /** You can define a shared queue and then pass the name in to your task.
379
+ *
380
+ * @example
381
+ *
382
+ * ```ts
383
+ * const myQueue = queue({
384
+ name: "my-queue",
385
+ concurrencyLimit: 1,
386
+ });
387
+
388
+ export const task1 = task({
389
+ id: "task-1",
390
+ queue: {
391
+ name: "my-queue",
392
+ },
393
+ run: async (payload: { message: string }) => {
394
+ // ...
395
+ },
396
+ });
397
+
398
+ export const task2 = task({
399
+ id: "task-2",
400
+ queue: {
401
+ name: "my-queue",
402
+ },
403
+ run: async (payload: { message: string }) => {
404
+ // ...
405
+ },
406
+ });
407
+ * ```
408
+ */
409
+ name: zod.z.string().optional(),
410
+ /** An optional property that specifies the maximum number of concurrent run executions.
411
+ *
412
+ * If this property is omitted, the task can potentially use up the full concurrency of an environment. */
368
413
  concurrencyLimit: zod.z.number().int().min(1).max(1e3).optional(),
369
- name: zod.z.string().optional()
414
+ /** @deprecated This feature is coming soon */
415
+ rateLimit: RateLimitOptions.optional()
370
416
  });
371
417
  var TaskMetadata = zod.z.object({
372
418
  id: zod.z.string(),
@@ -443,10 +489,21 @@ var ProdChildToWorkerMessages = {
443
489
  READY_TO_DISPOSE: {
444
490
  message: zod.z.undefined()
445
491
  },
492
+ READY_FOR_CHECKPOINT: {
493
+ message: zod.z.object({
494
+ version: zod.z.literal("v1").default("v1")
495
+ })
496
+ },
497
+ CANCEL_CHECKPOINT: {
498
+ message: zod.z.object({
499
+ version: zod.z.literal("v1").default("v1")
500
+ })
501
+ },
446
502
  WAIT_FOR_DURATION: {
447
503
  message: zod.z.object({
448
504
  version: zod.z.literal("v1").default("v1"),
449
- ms: zod.z.number()
505
+ ms: zod.z.number(),
506
+ now: zod.z.number()
450
507
  }),
451
508
  callback: zod.z.object({
452
509
  willCheckpointAndRestore: zod.z.boolean()
@@ -455,14 +512,14 @@ var ProdChildToWorkerMessages = {
455
512
  WAIT_FOR_TASK: {
456
513
  message: zod.z.object({
457
514
  version: zod.z.literal("v1").default("v1"),
458
- id: zod.z.string()
515
+ friendlyId: zod.z.string()
459
516
  })
460
517
  },
461
518
  WAIT_FOR_BATCH: {
462
519
  message: zod.z.object({
463
520
  version: zod.z.literal("v1").default("v1"),
464
- id: zod.z.string(),
465
- runs: zod.z.string().array()
521
+ batchFriendlyId: zod.z.string(),
522
+ runFriendlyIds: zod.z.string().array()
466
523
  })
467
524
  },
468
525
  UNCAUGHT_EXCEPTION: {
@@ -676,6 +733,11 @@ var Machine = zod.z.object({
676
733
  cpu: zod.z.string().default("1").optional(),
677
734
  memory: zod.z.string().default("500Mi").optional()
678
735
  });
736
+ var WaitReason = zod.z.enum([
737
+ "WAIT_FOR_DURATION",
738
+ "WAIT_FOR_TASK",
739
+ "WAIT_FOR_BATCH"
740
+ ]);
679
741
  var ProviderToPlatformMessages = {
680
742
  LOG: {
681
743
  message: zod.z.object({
@@ -706,7 +768,7 @@ var PlatformToProviderMessages = {
706
768
  message: zod.z.object({
707
769
  version: zod.z.literal("v1").default("v1"),
708
770
  imageTag: zod.z.string(),
709
- contentHash: zod.z.string(),
771
+ shortCode: zod.z.string(),
710
772
  envId: zod.z.string(),
711
773
  apiKey: zod.z.string(),
712
774
  apiUrl: zod.z.string()
@@ -737,13 +799,13 @@ var PlatformToProviderMessages = {
737
799
  version: zod.z.literal("v1").default("v1"),
738
800
  checkpointId: zod.z.string(),
739
801
  runId: zod.z.string(),
740
- attemptId: zod.z.string(),
741
802
  type: zod.z.enum([
742
803
  "DOCKER",
743
804
  "KUBERNETES"
744
805
  ]),
745
806
  location: zod.z.string(),
746
- reason: zod.z.string().optional()
807
+ reason: zod.z.string().optional(),
808
+ imageRef: zod.z.string()
747
809
  })
748
810
  },
749
811
  DELETE: {
@@ -795,8 +857,8 @@ var CoordinatorToPlatformMessages = {
795
857
  READY_FOR_EXECUTION: {
796
858
  message: zod.z.object({
797
859
  version: zod.z.literal("v1").default("v1"),
798
- attemptId: zod.z.string(),
799
- runId: zod.z.string()
860
+ runId: zod.z.string(),
861
+ totalCompletions: zod.z.number()
800
862
  }),
801
863
  callback: zod.z.discriminatedUnion("success", [
802
864
  zod.z.object({
@@ -811,19 +873,19 @@ var CoordinatorToPlatformMessages = {
811
873
  READY_FOR_RESUME: {
812
874
  message: zod.z.object({
813
875
  version: zod.z.literal("v1").default("v1"),
814
- attemptId: zod.z.string(),
815
- type: zod.z.enum([
816
- "WAIT_FOR_DURATION",
817
- "WAIT_FOR_TASK",
818
- "WAIT_FOR_BATCH"
819
- ])
876
+ attemptFriendlyId: zod.z.string(),
877
+ type: WaitReason
820
878
  })
821
879
  },
822
880
  TASK_RUN_COMPLETED: {
823
881
  message: zod.z.object({
824
882
  version: zod.z.literal("v1").default("v1"),
825
883
  execution: ProdTaskRunExecution,
826
- completion: TaskRunExecutionResult
884
+ completion: TaskRunExecutionResult,
885
+ checkpoint: zod.z.object({
886
+ docker: zod.z.boolean(),
887
+ location: zod.z.string()
888
+ }).optional()
827
889
  })
828
890
  },
829
891
  TASK_HEARTBEAT: {
@@ -835,21 +897,23 @@ var CoordinatorToPlatformMessages = {
835
897
  CHECKPOINT_CREATED: {
836
898
  message: zod.z.object({
837
899
  version: zod.z.literal("v1").default("v1"),
838
- attemptId: zod.z.string(),
900
+ attemptFriendlyId: zod.z.string(),
839
901
  docker: zod.z.boolean(),
840
902
  location: zod.z.string(),
841
903
  reason: zod.z.discriminatedUnion("type", [
842
904
  zod.z.object({
843
905
  type: zod.z.literal("WAIT_FOR_DURATION"),
844
- ms: zod.z.number()
906
+ ms: zod.z.number(),
907
+ now: zod.z.number()
845
908
  }),
846
909
  zod.z.object({
847
910
  type: zod.z.literal("WAIT_FOR_BATCH"),
848
- id: zod.z.string()
911
+ batchFriendlyId: zod.z.string(),
912
+ runFriendlyIds: zod.z.string().array()
849
913
  }),
850
914
  zod.z.object({
851
915
  type: zod.z.literal("WAIT_FOR_TASK"),
852
- id: zod.z.string()
916
+ friendlyId: zod.z.string()
853
917
  }),
854
918
  zod.z.object({
855
919
  type: zod.z.literal("RETRYING_AFTER_FAILURE"),
@@ -871,10 +935,12 @@ var CoordinatorToPlatformMessages = {
871
935
  }
872
936
  };
873
937
  var PlatformToCoordinatorMessages = {
874
- RESUME: {
938
+ RESUME_AFTER_DEPENDENCY: {
875
939
  message: zod.z.object({
876
940
  version: zod.z.literal("v1").default("v1"),
941
+ runId: zod.z.string(),
877
942
  attemptId: zod.z.string(),
943
+ attemptFriendlyId: zod.z.string(),
878
944
  completions: TaskRunExecutionResult.array(),
879
945
  executions: TaskRunExecution.array()
880
946
  })
@@ -882,13 +948,21 @@ var PlatformToCoordinatorMessages = {
882
948
  RESUME_AFTER_DURATION: {
883
949
  message: zod.z.object({
884
950
  version: zod.z.literal("v1").default("v1"),
885
- attemptId: zod.z.string()
951
+ attemptId: zod.z.string(),
952
+ attemptFriendlyId: zod.z.string()
886
953
  })
887
954
  },
888
955
  REQUEST_ATTEMPT_CANCELLATION: {
889
956
  message: zod.z.object({
890
957
  version: zod.z.literal("v1").default("v1"),
891
- attemptId: zod.z.string()
958
+ attemptId: zod.z.string(),
959
+ attemptFriendlyId: zod.z.string()
960
+ })
961
+ },
962
+ READY_FOR_RETRY: {
963
+ message: zod.z.object({
964
+ version: zod.z.literal("v1").default("v1"),
965
+ runId: zod.z.string()
892
966
  })
893
967
  }
894
968
  };
@@ -955,19 +1029,25 @@ var ProdWorkerToCoordinatorMessages = {
955
1029
  READY_FOR_EXECUTION: {
956
1030
  message: zod.z.object({
957
1031
  version: zod.z.literal("v1").default("v1"),
958
- attemptId: zod.z.string(),
959
- runId: zod.z.string()
1032
+ runId: zod.z.string(),
1033
+ totalCompletions: zod.z.number()
960
1034
  })
961
1035
  },
962
1036
  READY_FOR_RESUME: {
963
1037
  message: zod.z.object({
964
1038
  version: zod.z.literal("v1").default("v1"),
965
- attemptId: zod.z.string(),
966
- type: zod.z.enum([
967
- "WAIT_FOR_DURATION",
968
- "WAIT_FOR_TASK",
969
- "WAIT_FOR_BATCH"
970
- ])
1039
+ attemptFriendlyId: zod.z.string(),
1040
+ type: WaitReason
1041
+ })
1042
+ },
1043
+ READY_FOR_CHECKPOINT: {
1044
+ message: zod.z.object({
1045
+ version: zod.z.literal("v1").default("v1")
1046
+ })
1047
+ },
1048
+ CANCEL_CHECKPOINT: {
1049
+ message: zod.z.object({
1050
+ version: zod.z.literal("v1").default("v1")
971
1051
  })
972
1052
  },
973
1053
  TASK_HEARTBEAT: {
@@ -983,14 +1063,16 @@ var ProdWorkerToCoordinatorMessages = {
983
1063
  completion: TaskRunExecutionResult
984
1064
  }),
985
1065
  callback: zod.z.object({
986
- didCheckpoint: zod.z.boolean(),
1066
+ willCheckpointAndRestore: zod.z.boolean(),
987
1067
  shouldExit: zod.z.boolean()
988
1068
  })
989
1069
  },
990
1070
  WAIT_FOR_DURATION: {
991
1071
  message: zod.z.object({
992
1072
  version: zod.z.literal("v1").default("v1"),
993
- ms: zod.z.number()
1073
+ ms: zod.z.number(),
1074
+ now: zod.z.number(),
1075
+ attemptFriendlyId: zod.z.string()
994
1076
  }),
995
1077
  callback: zod.z.object({
996
1078
  willCheckpointAndRestore: zod.z.boolean()
@@ -999,7 +1081,9 @@ var ProdWorkerToCoordinatorMessages = {
999
1081
  WAIT_FOR_TASK: {
1000
1082
  message: zod.z.object({
1001
1083
  version: zod.z.literal("v1").default("v1"),
1002
- id: zod.z.string()
1084
+ friendlyId: zod.z.string(),
1085
+ // This is the attempt that is waiting
1086
+ attemptFriendlyId: zod.z.string()
1003
1087
  }),
1004
1088
  callback: zod.z.object({
1005
1089
  willCheckpointAndRestore: zod.z.boolean()
@@ -1008,8 +1092,10 @@ var ProdWorkerToCoordinatorMessages = {
1008
1092
  WAIT_FOR_BATCH: {
1009
1093
  message: zod.z.object({
1010
1094
  version: zod.z.literal("v1").default("v1"),
1011
- id: zod.z.string(),
1012
- runs: zod.z.string().array()
1095
+ batchFriendlyId: zod.z.string(),
1096
+ runFriendlyIds: zod.z.string().array(),
1097
+ // This is the attempt that is waiting
1098
+ attemptFriendlyId: zod.z.string()
1013
1099
  }),
1014
1100
  callback: zod.z.object({
1015
1101
  willCheckpointAndRestore: zod.z.boolean()
@@ -1028,7 +1114,7 @@ var ProdWorkerToCoordinatorMessages = {
1028
1114
  }
1029
1115
  };
1030
1116
  var CoordinatorToProdWorkerMessages = {
1031
- RESUME: {
1117
+ RESUME_AFTER_DEPENDENCY: {
1032
1118
  message: zod.z.object({
1033
1119
  version: zod.z.literal("v1").default("v1"),
1034
1120
  attemptId: zod.z.string(),
@@ -1058,6 +1144,12 @@ var CoordinatorToProdWorkerMessages = {
1058
1144
  message: zod.z.object({
1059
1145
  version: zod.z.literal("v1").default("v1")
1060
1146
  })
1147
+ },
1148
+ READY_FOR_RETRY: {
1149
+ message: zod.z.object({
1150
+ version: zod.z.literal("v1").default("v1"),
1151
+ runId: zod.z.string()
1152
+ })
1061
1153
  }
1062
1154
  };
1063
1155
  var ProdWorkerSocketData = zod.z.object({
@@ -1065,9 +1157,10 @@ var ProdWorkerSocketData = zod.z.object({
1065
1157
  projectRef: zod.z.string(),
1066
1158
  envId: zod.z.string(),
1067
1159
  runId: zod.z.string(),
1068
- attemptId: zod.z.string(),
1160
+ attemptFriendlyId: zod.z.string().optional(),
1069
1161
  podName: zod.z.string(),
1070
- deploymentId: zod.z.string()
1162
+ deploymentId: zod.z.string(),
1163
+ deploymentVersion: zod.z.string()
1071
1164
  });
1072
1165
  var PRIMARY_VARIANT = "primary";
1073
1166
  var Variant = zod.z.enum([
@@ -1201,12 +1294,22 @@ var FetchRetryStrategy = zod.z.discriminatedUnion("strategy", [
1201
1294
  FetchRetryHeadersStrategy,
1202
1295
  FetchRetryBackoffStrategy
1203
1296
  ]);
1204
- var FetchRetryOptions = zod.z.record(FetchRetryStrategy);
1297
+ var FetchRetryByStatusOptions = zod.z.record(zod.z.string(), FetchRetryStrategy);
1205
1298
  var FetchTimeoutOptions = zod.z.object({
1206
1299
  /** The maximum time to wait for the request to complete. */
1207
1300
  durationInMs: zod.z.number().optional(),
1208
1301
  retry: RetryOptions.optional()
1209
1302
  });
1303
+ var FetchRetryOptions = zod.z.object({
1304
+ /** The retrying strategy for specific status codes. */
1305
+ byStatus: FetchRetryByStatusOptions.optional(),
1306
+ /** The timeout options for the request. */
1307
+ timeout: RetryOptions.optional(),
1308
+ /**
1309
+ * The retrying strategy for connection errors.
1310
+ */
1311
+ connectionError: RetryOptions.optional()
1312
+ });
1210
1313
  var ExceptionEventProperties = zod.z.object({
1211
1314
  type: zod.z.string().optional(),
1212
1315
  message: zod.z.string().optional(),
@@ -1245,6 +1348,18 @@ function isCancellationSpanEvent(event) {
1245
1348
  return event.name === "cancellation";
1246
1349
  }
1247
1350
  __name(isCancellationSpanEvent, "isCancellationSpanEvent");
1351
+ var SpanMessagingEvent = zod.z.object({
1352
+ system: zod.z.string().optional(),
1353
+ client_id: zod.z.string().optional(),
1354
+ operation: zod.z.enum([
1355
+ "publish",
1356
+ "create",
1357
+ "receive",
1358
+ "deliver"
1359
+ ]),
1360
+ message: zod.z.any(),
1361
+ destination: zod.z.string().optional()
1362
+ });
1248
1363
 
1249
1364
  // src/zodfetch.ts
1250
1365
  async function zodfetch(schema, url, requestInit) {
@@ -1325,9 +1440,9 @@ function flattenAttributes(obj, prefix) {
1325
1440
  if (Array.isArray(value)) {
1326
1441
  for (let i = 0; i < value.length; i++) {
1327
1442
  if (typeof value[i] === "object" && value[i] !== null) {
1328
- Object.assign(result, flattenAttributes(value[i], `${newPrefix}.${i}`));
1443
+ Object.assign(result, flattenAttributes(value[i], `${newPrefix}.[${i}]`));
1329
1444
  } else {
1330
- result[`${newPrefix}.${i}`] = value[i];
1445
+ result[`${newPrefix}.[${i}]`] = value[i];
1331
1446
  }
1332
1447
  }
1333
1448
  } else if (isRecord(value)) {
@@ -1346,32 +1461,45 @@ function isRecord(value) {
1346
1461
  }
1347
1462
  __name(isRecord, "isRecord");
1348
1463
  function unflattenAttributes(obj) {
1349
- if (obj === null || obj === void 0 || typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean" || Array.isArray(obj)) {
1464
+ if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
1350
1465
  return obj;
1351
1466
  }
1352
1467
  const result = {};
1353
1468
  for (const [key, value] of Object.entries(obj)) {
1354
- const parts = key.split(".");
1469
+ const parts = key.split(".").reduce((acc, part) => {
1470
+ if (detectIsArrayIndex(part)) {
1471
+ acc.push(part);
1472
+ } else {
1473
+ acc.push(...part.split(/\.\[(.*?)\]/).filter(Boolean));
1474
+ }
1475
+ return acc;
1476
+ }, []);
1355
1477
  let current = result;
1356
1478
  for (let i = 0; i < parts.length - 1; i++) {
1357
1479
  const part = parts[i];
1358
- if (typeof part === "string") {
1359
- const nextPart = parts[i + 1];
1360
- const isArray = nextPart ? parseInt(nextPart, 10).toString() === nextPart : false;
1361
- if (current[part] == null) {
1362
- current[part] = isArray ? [] : {};
1363
- }
1364
- current = current[part];
1480
+ const isArray = detectIsArrayIndex(part);
1481
+ const cleanPart = isArray ? part.substring(1, part.length - 1) : part;
1482
+ const nextIsArray = detectIsArrayIndex(parts[i + 1]);
1483
+ if (!current[cleanPart]) {
1484
+ current[cleanPart] = nextIsArray ? [] : {};
1365
1485
  }
1486
+ current = current[cleanPart];
1366
1487
  }
1367
1488
  const lastPart = parts[parts.length - 1];
1368
- if (typeof lastPart === "string") {
1369
- current[lastPart] = value;
1370
- }
1489
+ const cleanLastPart = detectIsArrayIndex(lastPart) ? parseInt(lastPart.substring(1, lastPart.length - 1), 10) : lastPart;
1490
+ current[cleanLastPart] = value;
1371
1491
  }
1372
1492
  return result;
1373
1493
  }
1374
1494
  __name(unflattenAttributes, "unflattenAttributes");
1495
+ function detectIsArrayIndex(key) {
1496
+ const match = key.match(/^\[(\d+)\]$/);
1497
+ if (match) {
1498
+ return true;
1499
+ }
1500
+ return false;
1501
+ }
1502
+ __name(detectIsArrayIndex, "detectIsArrayIndex");
1375
1503
  function primitiveValueOrflattenedAttributes(obj, prefix) {
1376
1504
  if (typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean" || obj === null || obj === void 0) {
1377
1505
  return obj;
@@ -1428,7 +1556,8 @@ var SemanticInternalAttributes = {
1428
1556
  METADATA: "$metadata",
1429
1557
  TRIGGER: "$trigger",
1430
1558
  PAYLOAD: "$payload",
1431
- SHOW_ACTIONS: "show.actions",
1559
+ SHOW: "$show",
1560
+ SHOW_ACTIONS: "$show.actions",
1432
1561
  WORKER_ID: "worker.id",
1433
1562
  WORKER_VERSION: "worker.version",
1434
1563
  CLI_VERSION: "cli.version",
@@ -1696,14 +1825,17 @@ var _ZodMessageHandler = class _ZodMessageHandler {
1696
1825
  };
1697
1826
  }
1698
1827
  registerHandlers(emitter, logger2) {
1699
- const log = logger2 ?? console.log;
1828
+ const log = logger2 ?? console;
1700
1829
  if (!__privateGet(this, _handlers)) {
1701
- log("No handlers provided");
1830
+ log.info("No handlers provided");
1702
1831
  return;
1703
1832
  }
1704
1833
  for (const eventName of Object.keys(__privateGet(this, _schema))) {
1705
1834
  emitter.on(eventName, async (message, callback) => {
1706
- log(`handling ${eventName}`, message);
1835
+ log.info(`handling ${eventName}`, {
1836
+ payload: message,
1837
+ hasCallback: !!callback
1838
+ });
1707
1839
  let ack;
1708
1840
  if ("payload" in message) {
1709
1841
  ack = await this.handleMessage({
@@ -1821,27 +1953,37 @@ var _ZodSocketMessageHandler = class _ZodSocketMessageHandler {
1821
1953
  };
1822
1954
  }
1823
1955
  registerHandlers(emitter, logger2) {
1824
- const log = logger2 ?? console.log;
1956
+ const log = logger2 ?? console;
1825
1957
  if (!__privateGet(this, _handlers2)) {
1826
- log("No handlers provided");
1958
+ log.info("No handlers provided");
1827
1959
  return;
1828
1960
  }
1829
1961
  for (const eventName of Object.keys(__privateGet(this, _handlers2))) {
1830
1962
  emitter.on(eventName, async (message, callback) => {
1831
- log(`handling ${eventName}`, message);
1963
+ log.info(`handling ${eventName}`, {
1964
+ payload: message,
1965
+ hasCallback: !!callback
1966
+ });
1832
1967
  let ack;
1833
- if ("payload" in message) {
1834
- ack = await this.handleMessage({
1835
- type: eventName,
1836
- ...message
1837
- });
1838
- } else {
1839
- const { version, ...payload } = message;
1840
- ack = await this.handleMessage({
1841
- type: eventName,
1842
- version,
1843
- payload
1968
+ try {
1969
+ if ("payload" in message) {
1970
+ ack = await this.handleMessage({
1971
+ type: eventName,
1972
+ ...message
1973
+ });
1974
+ } else {
1975
+ const { version, ...payload } = message;
1976
+ ack = await this.handleMessage({
1977
+ type: eventName,
1978
+ version,
1979
+ payload
1980
+ });
1981
+ }
1982
+ } catch (error) {
1983
+ log.error("Error while handling message", {
1984
+ error
1844
1985
  });
1986
+ return;
1845
1987
  }
1846
1988
  if (callback && typeof callback === "function") {
1847
1989
  callback(ack);
@@ -1912,7 +2054,9 @@ var _ZodSocketConnection = class _ZodSocketConnection {
1912
2054
  },
1913
2055
  extraHeaders: opts.extraHeaders
1914
2056
  });
1915
- __privateSet(this, _logger, createLogger(`[${opts.namespace}][${this.socket.id}]`));
2057
+ __privateSet(this, _logger, new SimpleStructuredLogger(opts.namespace, exports.LogLevel.info, {
2058
+ socketId: this.socket.id
2059
+ }));
1916
2060
  __privateSet(this, _handler, new ZodSocketMessageHandler({
1917
2061
  schema: opts.serverMessages,
1918
2062
  handlers: opts.handlers
@@ -1923,19 +2067,22 @@ var _ZodSocketConnection = class _ZodSocketConnection {
1923
2067
  socket: this.socket
1924
2068
  }));
1925
2069
  this.socket.on("connect_error", async (error) => {
1926
- __privateGet(this, _logger).call(this, `connect_error: ${error}`);
2070
+ __privateGet(this, _logger).error(`connect_error: ${error}`);
1927
2071
  if (opts.onError) {
1928
2072
  await opts.onError(this.socket, error, __privateGet(this, _logger));
1929
2073
  }
1930
2074
  });
1931
2075
  this.socket.on("connect", async () => {
1932
- __privateGet(this, _logger).call(this, "connect");
2076
+ __privateGet(this, _logger).info("connect");
1933
2077
  if (opts.onConnection) {
1934
2078
  await opts.onConnection(this.socket, __privateGet(this, _handler), __privateGet(this, _sender2), __privateGet(this, _logger));
1935
2079
  }
1936
2080
  });
1937
2081
  this.socket.on("disconnect", async (reason, description) => {
1938
- __privateGet(this, _logger).call(this, "disconnect");
2082
+ __privateGet(this, _logger).info("disconnect", {
2083
+ reason,
2084
+ description
2085
+ });
1939
2086
  if (opts.onDisconnect) {
1940
2087
  await opts.onDisconnect(this.socket, reason, description, __privateGet(this, _logger));
1941
2088
  }
@@ -1959,16 +2106,79 @@ _handler = new WeakMap();
1959
2106
  _logger = new WeakMap();
1960
2107
  __name(_ZodSocketConnection, "ZodSocketConnection");
1961
2108
  var ZodSocketConnection = _ZodSocketConnection;
1962
- function createLogger(prefix) {
1963
- return (...args) => console.log(prefix, ...args);
1964
- }
1965
- __name(createLogger, "createLogger");
1966
2109
 
1967
2110
  // src/v3/zodNamespace.ts
1968
- var _handler2;
2111
+ exports.LogLevel = void 0;
2112
+ (function(LogLevel2) {
2113
+ LogLevel2[LogLevel2["log"] = 0] = "log";
2114
+ LogLevel2[LogLevel2["error"] = 1] = "error";
2115
+ LogLevel2[LogLevel2["warn"] = 2] = "warn";
2116
+ LogLevel2[LogLevel2["info"] = 3] = "info";
2117
+ LogLevel2[LogLevel2["debug"] = 4] = "debug";
2118
+ })(exports.LogLevel || (exports.LogLevel = {}));
2119
+ var _structuredLog, structuredLog_fn;
2120
+ var _SimpleStructuredLogger = class _SimpleStructuredLogger {
2121
+ constructor(name, level = [
2122
+ "1",
2123
+ "true"
2124
+ ].includes(process.env.DEBUG ?? "") ? exports.LogLevel.debug : exports.LogLevel.info, fields) {
2125
+ __privateAdd(this, _structuredLog);
2126
+ this.name = name;
2127
+ this.level = level;
2128
+ this.fields = fields;
2129
+ }
2130
+ child(fields, level) {
2131
+ return new _SimpleStructuredLogger(this.name, level, {
2132
+ ...this.fields,
2133
+ ...fields
2134
+ });
2135
+ }
2136
+ log(message, ...args) {
2137
+ if (this.level < exports.LogLevel.log)
2138
+ return;
2139
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.log, message, "log", ...args);
2140
+ }
2141
+ error(message, ...args) {
2142
+ if (this.level < exports.LogLevel.error)
2143
+ return;
2144
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.error, message, "error", ...args);
2145
+ }
2146
+ warn(message, ...args) {
2147
+ if (this.level < exports.LogLevel.warn)
2148
+ return;
2149
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.warn, message, "warn", ...args);
2150
+ }
2151
+ info(message, ...args) {
2152
+ if (this.level < exports.LogLevel.info)
2153
+ return;
2154
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.info, message, "info", ...args);
2155
+ }
2156
+ debug(message, ...args) {
2157
+ if (this.level < exports.LogLevel.debug)
2158
+ return;
2159
+ __privateMethod(this, _structuredLog, structuredLog_fn).call(this, console.debug, message, "debug", ...args);
2160
+ }
2161
+ };
2162
+ _structuredLog = new WeakSet();
2163
+ structuredLog_fn = /* @__PURE__ */ __name(function(loggerFunction, message, level, ...args) {
2164
+ const structuredLog = {
2165
+ ...args.length === 1 ? args[0] : args,
2166
+ ...this.fields,
2167
+ timestamp: /* @__PURE__ */ new Date(),
2168
+ name: this.name,
2169
+ message,
2170
+ level
2171
+ };
2172
+ loggerFunction(JSON.stringify(structuredLog));
2173
+ }, "#structuredLog");
2174
+ __name(_SimpleStructuredLogger, "SimpleStructuredLogger");
2175
+ var SimpleStructuredLogger = _SimpleStructuredLogger;
2176
+ var _logger2, _handler2;
1969
2177
  var _ZodNamespace = class _ZodNamespace {
1970
2178
  constructor(opts) {
2179
+ __privateAdd(this, _logger2, void 0);
1971
2180
  __privateAdd(this, _handler2, void 0);
2181
+ __privateSet(this, _logger2, opts.logger ?? new SimpleStructuredLogger(opts.name));
1972
2182
  __privateSet(this, _handler2, new ZodSocketMessageHandler({
1973
2183
  schema: opts.clientMessages,
1974
2184
  handlers: opts.handlers
@@ -1990,7 +2200,10 @@ var _ZodNamespace = class _ZodNamespace {
1990
2200
  });
1991
2201
  if (opts.preAuth) {
1992
2202
  this.namespace.use(async (socket, next) => {
1993
- const logger2 = createLogger2(`[${opts.name}][${socket.id}][preAuth]`);
2203
+ const logger2 = __privateGet(this, _logger2).child({
2204
+ socketId: socket.id,
2205
+ socketStage: "preAuth"
2206
+ });
1994
2207
  if (typeof opts.preAuth === "function") {
1995
2208
  await opts.preAuth(socket, next, logger2);
1996
2209
  }
@@ -1998,34 +2211,43 @@ var _ZodNamespace = class _ZodNamespace {
1998
2211
  }
1999
2212
  if (opts.authToken) {
2000
2213
  this.namespace.use((socket, next) => {
2001
- const logger2 = createLogger2(`[${opts.name}][${socket.id}][auth]`);
2214
+ const logger2 = __privateGet(this, _logger2).child({
2215
+ socketId: socket.id,
2216
+ socketStage: "auth"
2217
+ });
2002
2218
  const { auth } = socket.handshake;
2003
2219
  if (!("token" in auth)) {
2004
- logger2("no token");
2220
+ logger2.error("no token");
2005
2221
  return socket.disconnect(true);
2006
2222
  }
2007
2223
  if (auth.token !== opts.authToken) {
2008
- logger2("invalid token");
2224
+ logger2.error("invalid token");
2009
2225
  return socket.disconnect(true);
2010
2226
  }
2011
- logger2("success");
2227
+ logger2.info("success");
2012
2228
  next();
2013
2229
  });
2014
2230
  }
2015
2231
  if (opts.postAuth) {
2016
2232
  this.namespace.use(async (socket, next) => {
2017
- const logger2 = createLogger2(`[${opts.name}][${socket.id}][postAuth]`);
2233
+ const logger2 = __privateGet(this, _logger2).child({
2234
+ socketId: socket.id,
2235
+ socketStage: "auth"
2236
+ });
2018
2237
  if (typeof opts.postAuth === "function") {
2019
2238
  await opts.postAuth(socket, next, logger2);
2020
2239
  }
2021
2240
  });
2022
2241
  }
2023
2242
  this.namespace.on("connection", async (socket) => {
2024
- const logger2 = createLogger2(`[${opts.name}][${socket.id}]`);
2025
- logger2("connection");
2243
+ const logger2 = __privateGet(this, _logger2).child({
2244
+ socketId: socket.id,
2245
+ socketStage: "connection"
2246
+ });
2247
+ logger2.info("connected");
2026
2248
  __privateGet(this, _handler2).registerHandlers(socket, logger2);
2027
2249
  socket.on("disconnect", async (reason, description) => {
2028
- logger2("disconnect", {
2250
+ logger2.info("disconnect", {
2029
2251
  reason,
2030
2252
  description
2031
2253
  });
@@ -2034,7 +2256,9 @@ var _ZodNamespace = class _ZodNamespace {
2034
2256
  }
2035
2257
  });
2036
2258
  socket.on("error", async (error) => {
2037
- logger2("error", error);
2259
+ logger2.error("error", {
2260
+ error
2261
+ });
2038
2262
  if (opts.onError) {
2039
2263
  await opts.onError(socket, error, logger2);
2040
2264
  }
@@ -2048,13 +2272,10 @@ var _ZodNamespace = class _ZodNamespace {
2048
2272
  return this.namespace.fetchSockets();
2049
2273
  }
2050
2274
  };
2275
+ _logger2 = new WeakMap();
2051
2276
  _handler2 = new WeakMap();
2052
2277
  __name(_ZodNamespace, "ZodNamespace");
2053
2278
  var ZodNamespace = _ZodNamespace;
2054
- function createLogger2(prefix) {
2055
- return (...args) => console.log(prefix, ...args);
2056
- }
2057
- __name(createLogger2, "createLogger");
2058
2279
  var messageSchema2 = zod.z.object({
2059
2280
  version: zod.z.literal("v1").default("v1"),
2060
2281
  type: zod.z.string(),
@@ -2829,6 +3050,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
2829
3050
  }
2830
3051
  async waitForDuration(ms) {
2831
3052
  let timeout;
3053
+ const now = Date.now();
2832
3054
  const resolveAfterDuration = new Promise((resolve) => {
2833
3055
  timeout = setTimeout(resolve, ms);
2834
3056
  });
@@ -2843,13 +3065,19 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
2843
3065
  };
2844
3066
  });
2845
3067
  const { willCheckpointAndRestore } = await this.ipc.sendWithAck("WAIT_FOR_DURATION", {
2846
- ms
3068
+ ms,
3069
+ now
2847
3070
  });
2848
3071
  if (!willCheckpointAndRestore) {
2849
3072
  await resolveAfterDuration;
2850
3073
  return;
2851
3074
  }
2852
- await waitForRestore;
3075
+ this.ipc.send("READY_FOR_CHECKPOINT", {});
3076
+ await Promise.race([
3077
+ waitForRestore,
3078
+ resolveAfterDuration
3079
+ ]);
3080
+ this.ipc.send("CANCEL_CHECKPOINT", {});
2853
3081
  clearTimeout(timeout);
2854
3082
  }
2855
3083
  resumeAfterRestore() {
@@ -2870,7 +3098,7 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
2870
3098
  });
2871
3099
  });
2872
3100
  await this.ipc.send("WAIT_FOR_TASK", {
2873
- id: params.id
3101
+ friendlyId: params.id
2874
3102
  });
2875
3103
  return await promise;
2876
3104
  }
@@ -2890,8 +3118,8 @@ var _ProdRuntimeManager = class _ProdRuntimeManager {
2890
3118
  });
2891
3119
  }));
2892
3120
  await this.ipc.send("WAIT_FOR_BATCH", {
2893
- id: params.id,
2894
- runs: params.runs
3121
+ batchFriendlyId: params.id,
3122
+ runFriendlyIds: params.runs
2895
3123
  });
2896
3124
  const results = await promise;
2897
3125
  return {
@@ -3184,6 +3412,16 @@ var defaultRetryOptions = {
3184
3412
  maxTimeoutInMs: 6e4,
3185
3413
  randomize: true
3186
3414
  };
3415
+ ({
3416
+ byStatus: {
3417
+ "429,408,409,5xx": {
3418
+ strategy: "backoff",
3419
+ ...defaultRetryOptions
3420
+ }
3421
+ },
3422
+ connectionError: defaultRetryOptions,
3423
+ timeout: defaultRetryOptions
3424
+ });
3187
3425
  function calculateNextRetryDelay(options, attempt) {
3188
3426
  const opts = {
3189
3427
  ...defaultRetryOptions,
@@ -3755,21 +3993,17 @@ var TaskExecutor = _TaskExecutor;
3755
3993
  // package.json
3756
3994
  var dependencies = {
3757
3995
  "@google-cloud/precise-date": "^4.0.0",
3758
- "@opentelemetry/api": "^1.7.0",
3996
+ "@opentelemetry/api": "^1.8.0",
3759
3997
  "@opentelemetry/api-logs": "^0.48.0",
3760
- "@opentelemetry/auto-instrumentations-node": "^0.40.3",
3761
- "@opentelemetry/exporter-collector": "^0.25.0",
3762
- "@opentelemetry/exporter-logs-otlp-http": "^0.48.0",
3763
- "@opentelemetry/exporter-trace-otlp-http": "^0.48.0",
3764
- "@opentelemetry/instrumentation": "^0.48.0",
3765
- "@opentelemetry/instrumentation-fetch": "^0.48.0",
3766
- "@opentelemetry/instrumentation-http": "^0.48.0",
3767
- "@opentelemetry/resources": "^1.21.0",
3768
- "@opentelemetry/sdk-logs": "^0.48.0",
3769
- "@opentelemetry/sdk-node": "^0.48.0",
3770
- "@opentelemetry/sdk-trace-base": "^1.21.0",
3771
- "@opentelemetry/sdk-trace-node": "^1.21.0",
3772
- "@opentelemetry/semantic-conventions": "^1.21.0",
3998
+ "@opentelemetry/exporter-logs-otlp-http": "^0.49.1",
3999
+ "@opentelemetry/exporter-trace-otlp-http": "^0.49.1",
4000
+ "@opentelemetry/instrumentation": "^0.49.1",
4001
+ "@opentelemetry/resources": "^1.22.0",
4002
+ "@opentelemetry/sdk-logs": "^0.49.1",
4003
+ "@opentelemetry/sdk-node": "^0.49.1",
4004
+ "@opentelemetry/sdk-trace-base": "^1.22.0",
4005
+ "@opentelemetry/sdk-trace-node": "^1.22.0",
4006
+ "@opentelemetry/semantic-conventions": "^1.22.0",
3773
4007
  "humanize-duration": "^3.27.3",
3774
4008
  "socket.io": "^4.7.4",
3775
4009
  "socket.io-client": "^4.7.4",
@@ -3818,6 +4052,7 @@ exports.ExceptionEventProperties = ExceptionEventProperties;
3818
4052
  exports.ExceptionSpanEvent = ExceptionSpanEvent;
3819
4053
  exports.ExternalBuildData = ExternalBuildData;
3820
4054
  exports.FetchRetryBackoffStrategy = FetchRetryBackoffStrategy;
4055
+ exports.FetchRetryByStatusOptions = FetchRetryByStatusOptions;
3821
4056
  exports.FetchRetryHeadersStrategy = FetchRetryHeadersStrategy;
3822
4057
  exports.FetchRetryOptions = FetchRetryOptions;
3823
4058
  exports.FetchRetryStrategy = FetchRetryStrategy;
@@ -3853,9 +4088,11 @@ exports.RateLimitOptions = RateLimitOptions;
3853
4088
  exports.RetryOptions = RetryOptions;
3854
4089
  exports.SemanticInternalAttributes = SemanticInternalAttributes;
3855
4090
  exports.SharedQueueToClientMessages = SharedQueueToClientMessages;
4091
+ exports.SimpleStructuredLogger = SimpleStructuredLogger;
3856
4092
  exports.SlidingWindowRateLimit = SlidingWindowRateLimit;
3857
4093
  exports.SpanEvent = SpanEvent;
3858
4094
  exports.SpanEvents = SpanEvents;
4095
+ exports.SpanMessagingEvent = SpanMessagingEvent;
3859
4096
  exports.StartDeploymentIndexingRequestBody = StartDeploymentIndexingRequestBody;
3860
4097
  exports.StartDeploymentIndexingResponseBody = StartDeploymentIndexingResponseBody;
3861
4098
  exports.TaskContextSpanProcessor = TaskContextSpanProcessor;
@@ -3890,6 +4127,7 @@ exports.TriggerTaskRequestBody = TriggerTaskRequestBody;
3890
4127
  exports.TriggerTaskResponse = TriggerTaskResponse;
3891
4128
  exports.TriggerTracer = TriggerTracer;
3892
4129
  exports.UncaughtExceptionMessage = UncaughtExceptionMessage;
4130
+ exports.WaitReason = WaitReason;
3893
4131
  exports.WhoAmIResponseSchema = WhoAmIResponseSchema;
3894
4132
  exports.ZodIpcConnection = ZodIpcConnection;
3895
4133
  exports.ZodMessageHandler = ZodMessageHandler;