@trigger.dev/sdk 0.2.15-next.0 → 0.2.16-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -348,9 +348,11 @@ var ResolveRunOnceOuputSchema = import_zod8.z.object({
348
348
  });
349
349
 
350
350
  // src/events.ts
351
+ var import_zod9 = require("zod");
351
352
  var import_slug = __toESM(require("slug"));
352
353
  var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"));
353
354
  function customEvent(options) {
355
+ const schema = options.schema ?? import_zod9.z.any();
354
356
  return {
355
357
  metadata: {
356
358
  type: "CUSTOM_EVENT",
@@ -362,9 +364,9 @@ function customEvent(options) {
362
364
  ],
363
365
  payload: options.filter ?? {}
364
366
  },
365
- schema: (0, import_zod_to_json_schema.default)(options.schema)
367
+ schema: (0, import_zod_to_json_schema.default)(schema)
366
368
  },
367
- schema: options.schema
369
+ schema
368
370
  };
369
371
  }
370
372
  __name(customEvent, "customEvent");
@@ -381,6 +383,7 @@ function scheduleEvent(options) {
381
383
  }
382
384
  __name(scheduleEvent, "scheduleEvent");
383
385
  function webhookEvent(options) {
386
+ const schema = options.schema ?? import_zod9.z.any();
384
387
  return {
385
388
  metadata: {
386
389
  type: "WEBHOOK",
@@ -402,7 +405,7 @@ function webhookEvent(options) {
402
405
  event: options.eventName
403
406
  },
404
407
  manualRegistration: true,
405
- schema: (0, import_zod_to_json_schema.default)(options.schema)
408
+ schema: (0, import_zod_to_json_schema.default)(schema)
406
409
  },
407
410
  schema: options.schema
408
411
  };
@@ -410,263 +413,299 @@ function webhookEvent(options) {
410
413
  __name(webhookEvent, "webhookEvent");
411
414
 
412
415
  // ../internal-bridge/src/schemas/host.ts
413
- var import_zod9 = require("zod");
416
+ var import_zod10 = require("zod");
414
417
  var HostRPCSchema = {
415
418
  TRIGGER_WORKFLOW: {
416
- request: import_zod9.z.object({
417
- id: import_zod9.z.string(),
418
- trigger: import_zod9.z.object({
419
+ request: import_zod10.z.object({
420
+ id: import_zod10.z.string(),
421
+ trigger: import_zod10.z.object({
419
422
  input: JsonSchema.default({}),
420
423
  context: JsonSchema.default({})
421
424
  }),
422
- meta: import_zod9.z.object({
423
- environment: import_zod9.z.string(),
424
- workflowId: import_zod9.z.string(),
425
- organizationId: import_zod9.z.string(),
426
- apiKey: import_zod9.z.string(),
427
- isTest: import_zod9.z.boolean().default(false),
428
- appOrigin: import_zod9.z.string()
425
+ meta: import_zod10.z.object({
426
+ environment: import_zod10.z.string(),
427
+ workflowId: import_zod10.z.string(),
428
+ organizationId: import_zod10.z.string(),
429
+ apiKey: import_zod10.z.string(),
430
+ isTest: import_zod10.z.boolean().default(false),
431
+ appOrigin: import_zod10.z.string()
429
432
  })
430
433
  }),
431
- response: import_zod9.z.boolean()
434
+ response: import_zod10.z.boolean()
432
435
  },
433
436
  RESOLVE_REQUEST: {
434
- request: import_zod9.z.object({
435
- id: import_zod9.z.string(),
436
- key: import_zod9.z.string(),
437
+ request: import_zod10.z.object({
438
+ id: import_zod10.z.string(),
439
+ key: import_zod10.z.string(),
437
440
  output: JsonSchema.default({}),
438
- meta: import_zod9.z.object({
439
- environment: import_zod9.z.string(),
440
- workflowId: import_zod9.z.string(),
441
- organizationId: import_zod9.z.string(),
442
- apiKey: import_zod9.z.string(),
443
- runId: import_zod9.z.string()
441
+ meta: import_zod10.z.object({
442
+ environment: import_zod10.z.string(),
443
+ workflowId: import_zod10.z.string(),
444
+ organizationId: import_zod10.z.string(),
445
+ apiKey: import_zod10.z.string(),
446
+ runId: import_zod10.z.string()
444
447
  })
445
448
  }),
446
- response: import_zod9.z.boolean()
449
+ response: import_zod10.z.boolean()
447
450
  },
448
451
  RESOLVE_DELAY: {
449
- request: import_zod9.z.object({
450
- id: import_zod9.z.string(),
451
- key: import_zod9.z.string(),
452
- meta: import_zod9.z.object({
453
- environment: import_zod9.z.string(),
454
- workflowId: import_zod9.z.string(),
455
- organizationId: import_zod9.z.string(),
456
- apiKey: import_zod9.z.string(),
457
- runId: import_zod9.z.string()
452
+ request: import_zod10.z.object({
453
+ id: import_zod10.z.string(),
454
+ key: import_zod10.z.string(),
455
+ meta: import_zod10.z.object({
456
+ environment: import_zod10.z.string(),
457
+ workflowId: import_zod10.z.string(),
458
+ organizationId: import_zod10.z.string(),
459
+ apiKey: import_zod10.z.string(),
460
+ runId: import_zod10.z.string()
458
461
  })
459
462
  }),
460
- response: import_zod9.z.boolean()
463
+ response: import_zod10.z.boolean()
461
464
  },
462
465
  REJECT_REQUEST: {
463
- request: import_zod9.z.object({
464
- id: import_zod9.z.string(),
465
- key: import_zod9.z.string(),
466
+ request: import_zod10.z.object({
467
+ id: import_zod10.z.string(),
468
+ key: import_zod10.z.string(),
466
469
  error: JsonSchema.default({}),
467
- meta: import_zod9.z.object({
468
- environment: import_zod9.z.string(),
469
- workflowId: import_zod9.z.string(),
470
- organizationId: import_zod9.z.string(),
471
- apiKey: import_zod9.z.string(),
472
- runId: import_zod9.z.string()
470
+ meta: import_zod10.z.object({
471
+ environment: import_zod10.z.string(),
472
+ workflowId: import_zod10.z.string(),
473
+ organizationId: import_zod10.z.string(),
474
+ apiKey: import_zod10.z.string(),
475
+ runId: import_zod10.z.string()
473
476
  })
474
477
  }),
475
- response: import_zod9.z.boolean()
478
+ response: import_zod10.z.boolean()
476
479
  },
477
480
  RESOLVE_FETCH_REQUEST: {
478
- request: import_zod9.z.object({
479
- id: import_zod9.z.string(),
480
- key: import_zod9.z.string(),
481
+ request: import_zod10.z.object({
482
+ id: import_zod10.z.string(),
483
+ key: import_zod10.z.string(),
481
484
  output: FetchOutputSchema,
482
- meta: import_zod9.z.object({
483
- environment: import_zod9.z.string(),
484
- workflowId: import_zod9.z.string(),
485
- organizationId: import_zod9.z.string(),
486
- apiKey: import_zod9.z.string(),
487
- runId: import_zod9.z.string()
485
+ meta: import_zod10.z.object({
486
+ environment: import_zod10.z.string(),
487
+ workflowId: import_zod10.z.string(),
488
+ organizationId: import_zod10.z.string(),
489
+ apiKey: import_zod10.z.string(),
490
+ runId: import_zod10.z.string()
488
491
  })
489
492
  }),
490
- response: import_zod9.z.boolean()
493
+ response: import_zod10.z.boolean()
491
494
  },
492
495
  REJECT_FETCH_REQUEST: {
493
- request: import_zod9.z.object({
494
- id: import_zod9.z.string(),
495
- key: import_zod9.z.string(),
496
+ request: import_zod10.z.object({
497
+ id: import_zod10.z.string(),
498
+ key: import_zod10.z.string(),
496
499
  error: JsonSchema.default({}),
497
- meta: import_zod9.z.object({
498
- environment: import_zod9.z.string(),
499
- workflowId: import_zod9.z.string(),
500
- organizationId: import_zod9.z.string(),
501
- apiKey: import_zod9.z.string(),
502
- runId: import_zod9.z.string()
500
+ meta: import_zod10.z.object({
501
+ environment: import_zod10.z.string(),
502
+ workflowId: import_zod10.z.string(),
503
+ organizationId: import_zod10.z.string(),
504
+ apiKey: import_zod10.z.string(),
505
+ runId: import_zod10.z.string()
503
506
  })
504
507
  }),
505
- response: import_zod9.z.boolean()
508
+ response: import_zod10.z.boolean()
506
509
  },
507
510
  RESOLVE_RUN_ONCE: {
508
- request: import_zod9.z.object({
509
- id: import_zod9.z.string(),
510
- key: import_zod9.z.string(),
511
+ request: import_zod10.z.object({
512
+ id: import_zod10.z.string(),
513
+ key: import_zod10.z.string(),
511
514
  output: ResolveRunOnceOuputSchema,
512
- meta: import_zod9.z.object({
513
- environment: import_zod9.z.string(),
514
- workflowId: import_zod9.z.string(),
515
- organizationId: import_zod9.z.string(),
516
- apiKey: import_zod9.z.string(),
517
- runId: import_zod9.z.string()
515
+ meta: import_zod10.z.object({
516
+ environment: import_zod10.z.string(),
517
+ workflowId: import_zod10.z.string(),
518
+ organizationId: import_zod10.z.string(),
519
+ apiKey: import_zod10.z.string(),
520
+ runId: import_zod10.z.string()
518
521
  })
519
522
  }),
520
- response: import_zod9.z.boolean()
523
+ response: import_zod10.z.boolean()
521
524
  }
522
525
  };
523
526
 
524
527
  // ../internal-bridge/src/schemas/server.ts
525
- var import_zod10 = require("zod");
528
+ var import_zod11 = require("zod");
526
529
  var ServerRPCSchema = {
527
530
  INITIALIZE_DELAY: {
528
- request: import_zod10.z.object({
529
- runId: import_zod10.z.string(),
530
- key: import_zod10.z.string(),
531
+ request: import_zod11.z.object({
532
+ runId: import_zod11.z.string(),
533
+ key: import_zod11.z.string(),
531
534
  wait: WaitSchema,
532
- timestamp: import_zod10.z.string()
535
+ timestamp: import_zod11.z.string()
533
536
  }),
534
- response: import_zod10.z.boolean()
537
+ response: import_zod11.z.boolean()
535
538
  },
536
539
  SEND_REQUEST: {
537
- request: import_zod10.z.object({
538
- runId: import_zod10.z.string(),
539
- key: import_zod10.z.string(),
540
- request: import_zod10.z.object({
541
- service: import_zod10.z.string(),
542
- endpoint: import_zod10.z.string(),
543
- params: import_zod10.z.any(),
544
- version: import_zod10.z.string().optional()
540
+ request: import_zod11.z.object({
541
+ runId: import_zod11.z.string(),
542
+ key: import_zod11.z.string(),
543
+ request: import_zod11.z.object({
544
+ service: import_zod11.z.string(),
545
+ endpoint: import_zod11.z.string(),
546
+ params: import_zod11.z.any(),
547
+ version: import_zod11.z.string().optional()
545
548
  }),
546
- timestamp: import_zod10.z.string()
549
+ timestamp: import_zod11.z.string()
547
550
  }),
548
- response: import_zod10.z.boolean()
551
+ response: import_zod11.z.boolean()
549
552
  },
550
553
  SEND_FETCH: {
551
- request: import_zod10.z.object({
552
- runId: import_zod10.z.string(),
553
- key: import_zod10.z.string(),
554
+ request: import_zod11.z.object({
555
+ runId: import_zod11.z.string(),
556
+ key: import_zod11.z.string(),
554
557
  fetch: FetchRequestSchema,
555
- timestamp: import_zod10.z.string()
558
+ timestamp: import_zod11.z.string()
556
559
  }),
557
- response: import_zod10.z.boolean()
560
+ response: import_zod11.z.boolean()
558
561
  },
559
562
  SEND_LOG: {
560
- request: import_zod10.z.object({
561
- runId: import_zod10.z.string(),
562
- key: import_zod10.z.string(),
563
- log: import_zod10.z.object({
564
- message: import_zod10.z.string(),
565
- level: import_zod10.z.enum([
563
+ request: import_zod11.z.object({
564
+ runId: import_zod11.z.string(),
565
+ key: import_zod11.z.string(),
566
+ log: import_zod11.z.object({
567
+ message: import_zod11.z.string(),
568
+ level: import_zod11.z.enum([
566
569
  "DEBUG",
567
570
  "INFO",
568
571
  "WARN",
569
572
  "ERROR"
570
573
  ]),
571
- properties: import_zod10.z.string().optional()
574
+ properties: import_zod11.z.string().optional()
572
575
  }),
573
- timestamp: import_zod10.z.string()
576
+ timestamp: import_zod11.z.string()
574
577
  }),
575
- response: import_zod10.z.boolean()
578
+ response: import_zod11.z.boolean()
576
579
  },
577
580
  SEND_EVENT: {
578
- request: import_zod10.z.object({
579
- runId: import_zod10.z.string(),
580
- key: import_zod10.z.string(),
581
+ request: import_zod11.z.object({
582
+ runId: import_zod11.z.string(),
583
+ key: import_zod11.z.string(),
581
584
  event: CustomEventSchema,
582
- timestamp: import_zod10.z.string()
585
+ timestamp: import_zod11.z.string()
583
586
  }),
584
- response: import_zod10.z.boolean()
587
+ response: import_zod11.z.boolean()
585
588
  },
586
589
  INITIALIZE_HOST: {
587
- request: import_zod10.z.object({
588
- apiKey: import_zod10.z.string(),
589
- workflowId: import_zod10.z.string(),
590
- workflowName: import_zod10.z.string(),
590
+ request: import_zod11.z.object({
591
+ apiKey: import_zod11.z.string(),
592
+ workflowId: import_zod11.z.string(),
593
+ workflowName: import_zod11.z.string(),
594
+ trigger: TriggerMetadataSchema,
595
+ packageVersion: import_zod11.z.string(),
596
+ packageName: import_zod11.z.string(),
597
+ triggerTTL: import_zod11.z.number().optional()
598
+ }),
599
+ response: import_zod11.z.discriminatedUnion("type", [
600
+ import_zod11.z.object({
601
+ type: import_zod11.z.literal("success")
602
+ }),
603
+ import_zod11.z.object({
604
+ type: import_zod11.z.literal("error"),
605
+ message: import_zod11.z.string()
606
+ })
607
+ ]).nullable()
608
+ },
609
+ INITIALIZE_HOST_V2: {
610
+ request: import_zod11.z.object({
611
+ apiKey: import_zod11.z.string(),
612
+ workflowId: import_zod11.z.string(),
613
+ workflowName: import_zod11.z.string(),
591
614
  trigger: TriggerMetadataSchema,
592
- packageVersion: import_zod10.z.string(),
593
- packageName: import_zod10.z.string(),
594
- triggerTTL: import_zod10.z.number().optional()
615
+ packageVersion: import_zod11.z.string(),
616
+ packageName: import_zod11.z.string(),
617
+ triggerTTL: import_zod11.z.number().optional()
595
618
  }),
596
- response: import_zod10.z.discriminatedUnion("type", [
597
- import_zod10.z.object({
598
- type: import_zod10.z.literal("success")
619
+ response: import_zod11.z.discriminatedUnion("type", [
620
+ import_zod11.z.object({
621
+ type: import_zod11.z.literal("success"),
622
+ data: import_zod11.z.object({
623
+ workflow: import_zod11.z.object({
624
+ id: import_zod11.z.string(),
625
+ slug: import_zod11.z.string()
626
+ }),
627
+ environment: import_zod11.z.object({
628
+ id: import_zod11.z.string(),
629
+ slug: import_zod11.z.string()
630
+ }),
631
+ organization: import_zod11.z.object({
632
+ id: import_zod11.z.string(),
633
+ slug: import_zod11.z.string()
634
+ }),
635
+ isNew: import_zod11.z.boolean(),
636
+ url: import_zod11.z.string()
637
+ })
599
638
  }),
600
- import_zod10.z.object({
601
- type: import_zod10.z.literal("error"),
602
- message: import_zod10.z.string()
639
+ import_zod11.z.object({
640
+ type: import_zod11.z.literal("error"),
641
+ message: import_zod11.z.string()
603
642
  })
604
643
  ]).nullable()
605
644
  },
606
645
  START_WORKFLOW_RUN: {
607
- request: import_zod10.z.object({
608
- runId: import_zod10.z.string(),
609
- timestamp: import_zod10.z.string()
646
+ request: import_zod11.z.object({
647
+ runId: import_zod11.z.string(),
648
+ timestamp: import_zod11.z.string()
610
649
  }),
611
- response: import_zod10.z.boolean()
650
+ response: import_zod11.z.boolean()
612
651
  },
613
652
  COMPLETE_WORKFLOW_RUN: {
614
- request: import_zod10.z.object({
615
- runId: import_zod10.z.string(),
616
- output: import_zod10.z.string().optional(),
617
- timestamp: import_zod10.z.string()
653
+ request: import_zod11.z.object({
654
+ runId: import_zod11.z.string(),
655
+ output: import_zod11.z.string().optional(),
656
+ timestamp: import_zod11.z.string()
618
657
  }),
619
- response: import_zod10.z.boolean()
658
+ response: import_zod11.z.boolean()
620
659
  },
621
660
  SEND_WORKFLOW_ERROR: {
622
- request: import_zod10.z.object({
623
- runId: import_zod10.z.string(),
624
- error: import_zod10.z.object({
625
- name: import_zod10.z.string(),
626
- message: import_zod10.z.string(),
627
- stackTrace: import_zod10.z.string().optional()
661
+ request: import_zod11.z.object({
662
+ runId: import_zod11.z.string(),
663
+ error: import_zod11.z.object({
664
+ name: import_zod11.z.string(),
665
+ message: import_zod11.z.string(),
666
+ stackTrace: import_zod11.z.string().optional()
628
667
  }),
629
- timestamp: import_zod10.z.string()
668
+ timestamp: import_zod11.z.string()
630
669
  }),
631
- response: import_zod10.z.boolean()
670
+ response: import_zod11.z.boolean()
632
671
  },
633
672
  INITIALIZE_RUN_ONCE: {
634
- request: import_zod10.z.object({
635
- runId: import_zod10.z.string(),
636
- key: import_zod10.z.string(),
637
- timestamp: import_zod10.z.string(),
673
+ request: import_zod11.z.object({
674
+ runId: import_zod11.z.string(),
675
+ key: import_zod11.z.string(),
676
+ timestamp: import_zod11.z.string(),
638
677
  runOnce: InitializeRunOnceSchema
639
678
  }),
640
- response: import_zod10.z.boolean()
679
+ response: import_zod11.z.boolean()
641
680
  },
642
681
  COMPLETE_RUN_ONCE: {
643
- request: import_zod10.z.object({
644
- runId: import_zod10.z.string(),
645
- key: import_zod10.z.string(),
646
- timestamp: import_zod10.z.string(),
682
+ request: import_zod11.z.object({
683
+ runId: import_zod11.z.string(),
684
+ key: import_zod11.z.string(),
685
+ timestamp: import_zod11.z.string(),
647
686
  runOnce: CompleteRunOnceSchema
648
687
  }),
649
- response: import_zod10.z.boolean()
688
+ response: import_zod11.z.boolean()
650
689
  }
651
690
  };
652
691
 
653
692
  // ../internal-bridge/src/schemas/common.ts
654
- var import_zod11 = require("zod");
655
- var MESSAGE_META = import_zod11.z.object({
656
- data: import_zod11.z.any(),
657
- id: import_zod11.z.string(),
658
- type: import_zod11.z.union([
659
- import_zod11.z.literal("ACK"),
660
- import_zod11.z.literal("MESSAGE")
693
+ var import_zod12 = require("zod");
694
+ var MESSAGE_META = import_zod12.z.object({
695
+ data: import_zod12.z.any(),
696
+ id: import_zod12.z.string(),
697
+ type: import_zod12.z.union([
698
+ import_zod12.z.literal("ACK"),
699
+ import_zod12.z.literal("MESSAGE")
661
700
  ])
662
701
  });
663
- var TriggerEnvironmentSchema = import_zod11.z.enum([
702
+ var TriggerEnvironmentSchema = import_zod12.z.enum([
664
703
  "live",
665
704
  "development"
666
705
  ]);
667
706
 
668
707
  // ../internal-bridge/src/zodRPC.ts
669
- var import_zod12 = require("zod");
708
+ var import_zod13 = require("zod");
670
709
  var import_node_crypto = require("crypto");
671
710
 
672
711
  // ../internal-bridge/src/logger.ts
@@ -704,6 +743,11 @@ var Logger = class {
704
743
  ...__privateMethod(this, _formatTags, formatTags_fn).call(this)
705
744
  ]);
706
745
  }
746
+ logClean(...args) {
747
+ if (__privateGet(this, _level) < 1)
748
+ return;
749
+ console.log(`${__privateMethod(this, _formatName, formatName_fn).call(this)} `, ...args);
750
+ }
707
751
  error(...args) {
708
752
  if (__privateGet(this, _level) < 2)
709
753
  return;
@@ -767,11 +811,11 @@ function formattedDateTime() {
767
811
  __name(formattedDateTime, "formattedDateTime");
768
812
 
769
813
  // ../internal-bridge/src/zodRPC.ts
770
- var RPCMessageSchema = import_zod12.z.object({
771
- id: import_zod12.z.string(),
772
- methodName: import_zod12.z.string(),
773
- data: import_zod12.z.any(),
774
- kind: import_zod12.z.enum([
814
+ var RPCMessageSchema = import_zod13.z.object({
815
+ id: import_zod13.z.string(),
816
+ methodName: import_zod13.z.string(),
817
+ data: import_zod13.z.any(),
818
+ kind: import_zod13.z.enum([
775
819
  "CALL",
776
820
  "RESPONSE"
777
821
  ])
@@ -851,7 +895,7 @@ onCall_fn = /* @__PURE__ */ __name(async function(message) {
851
895
  try {
852
896
  await __privateMethod(this, _handleCall, handleCall_fn).call(this, message);
853
897
  } catch (callError) {
854
- if (callError instanceof import_zod12.ZodError) {
898
+ if (callError instanceof import_zod13.ZodError) {
855
899
  __privateGet(this, _logger).error(`[ZodRPC] Received invalid call:
856
900
  ${JSON.stringify(message)}: `, callError.errors);
857
901
  } else {
@@ -865,7 +909,7 @@ onResponse_fn = /* @__PURE__ */ __name(async function(message1) {
865
909
  try {
866
910
  await __privateMethod(this, _handleResponse, handleResponse_fn).call(this, message1);
867
911
  } catch (callError) {
868
- if (callError instanceof import_zod12.ZodError) {
912
+ if (callError instanceof import_zod13.ZodError) {
869
913
  __privateGet(this, _logger).error(`[ZodRPC] Received invalid response
870
914
 
871
915
  ${JSON.stringify(message1)}: `, callError.flatten());
@@ -941,11 +985,11 @@ __name(packageResponse, "packageResponse");
941
985
  // src/client.ts
942
986
  var import_uuid2 = require("uuid");
943
987
  var import_ws = require("ws");
944
- var import_zod13 = require("zod");
988
+ var import_zod14 = require("zod");
945
989
 
946
990
  // package.json
947
991
  var name = "@trigger.dev/sdk";
948
- var version = "0.2.15-next.0";
992
+ var version = "0.2.16-next.0";
949
993
 
950
994
  // src/connection.ts
951
995
  var import_uuid = require("uuid");
@@ -1198,12 +1242,13 @@ __name(ContextLogger, "ContextLogger");
1198
1242
 
1199
1243
  // src/client.ts
1200
1244
  var import_zod_error = require("zod-error");
1245
+ var import_terminal_link = __toESM(require("terminal-link"));
1201
1246
  var zodErrorMessageOptions = {
1202
1247
  delimiter: {
1203
1248
  error: " \u{1F525} "
1204
1249
  }
1205
1250
  };
1206
- var _trigger, _options, _connection2, _serverRPC, _apiKey, _endpoint, _isConnected, _retryIntervalMs, _logger3, _closedByUser, _responseCompleteCallbacks, _waitForCallbacks, _fetchCallbacks, _runOnceCallbacks, _initializeConnection, initializeConnection_fn, _initializeRPC, initializeRPC_fn, _initializeHost, initializeHost_fn, _send, send_fn;
1251
+ var _trigger, _options, _connection2, _serverRPC, _apiKey, _endpoint, _isConnected, _retryIntervalMs, _logger3, _closedByUser, _registerResponse, _responseCompleteCallbacks, _waitForCallbacks, _fetchCallbacks, _runOnceCallbacks, _initializeConnection, initializeConnection_fn, _initializeRPC, initializeRPC_fn, _initializeHost, initializeHost_fn, _send, send_fn;
1207
1252
  var TriggerClient = class {
1208
1253
  constructor(trigger, options) {
1209
1254
  __privateAdd(this, _initializeConnection);
@@ -1220,6 +1265,7 @@ var TriggerClient = class {
1220
1265
  __privateAdd(this, _retryIntervalMs, 3e3);
1221
1266
  __privateAdd(this, _logger3, void 0);
1222
1267
  __privateAdd(this, _closedByUser, false);
1268
+ __privateAdd(this, _registerResponse, void 0);
1223
1269
  __privateAdd(this, _responseCompleteCallbacks, /* @__PURE__ */ new Map());
1224
1270
  __privateAdd(this, _waitForCallbacks, /* @__PURE__ */ new Map());
1225
1271
  __privateAdd(this, _fetchCallbacks, /* @__PURE__ */ new Map());
@@ -1242,7 +1288,15 @@ var TriggerClient = class {
1242
1288
  await __privateMethod(this, _initializeConnection, initializeConnection_fn).call(this, instanceId);
1243
1289
  __privateMethod(this, _initializeRPC, initializeRPC_fn).call(this);
1244
1290
  await __privateMethod(this, _initializeHost, initializeHost_fn).call(this);
1245
- __privateGet(this, _logger3).log(`\u2728 Connected and listening for events`);
1291
+ if (__privateGet(this, _registerResponse)?.isNew) {
1292
+ __privateGet(this, _logger3).logClean(`\u{1F389} Successfully registered "${__privateGet(this, _trigger).name}" to trigger.dev \u{1F449} ${(0, import_terminal_link.default)("View on dashboard", __privateGet(this, _registerResponse).url, {
1293
+ fallback: (text, url) => `${text}: (${url})`
1294
+ })}. Listening for events...`);
1295
+ } else {
1296
+ __privateGet(this, _logger3).log(`\u2728 Connected and listening for events \u{1F449} ${(0, import_terminal_link.default)("View on dashboard", __privateGet(this, _registerResponse).url, {
1297
+ fallback: (text, url) => `${text}: (${url})`
1298
+ })}`);
1299
+ }
1246
1300
  } catch (error) {
1247
1301
  __privateGet(this, _logger3).log(`\u{1F6A9} Could not connect to trigger.dev`);
1248
1302
  this.close();
@@ -1268,6 +1322,7 @@ _isConnected = new WeakMap();
1268
1322
  _retryIntervalMs = new WeakMap();
1269
1323
  _logger3 = new WeakMap();
1270
1324
  _closedByUser = new WeakMap();
1325
+ _registerResponse = new WeakMap();
1271
1326
  _responseCompleteCallbacks = new WeakMap();
1272
1327
  _waitForCallbacks = new WeakMap();
1273
1328
  _fetchCallbacks = new WeakMap();
@@ -1434,7 +1489,7 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
1434
1489
  status: response.status,
1435
1490
  ok: response.ok,
1436
1491
  headers: response.headers,
1437
- body: response.body ? (options.responseSchema ?? import_zod13.z.any()).parse(response.body) : void 0
1492
+ body: response.body ? (options.responseSchema ?? import_zod14.z.any()).parse(response.body) : void 0
1438
1493
  };
1439
1494
  }, "fetchFunction");
1440
1495
  const ctx = {
@@ -1602,7 +1657,9 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
1602
1657
  timestamp: String(highPrecisionTimestamp())
1603
1658
  }).then(() => {
1604
1659
  return __privateGet(this, _trigger).options.run(eventData, ctx).then((output) => {
1605
- __privateGet(this, _logger3).log(`Run ${data.id} complete \u{1F3C3}`);
1660
+ __privateGet(this, _logger3).log(`Run ${data.id} complete \u{1F449} ${(0, import_terminal_link.default)("View on dashboard", `${__privateGet(this, _registerResponse).url}/runs/${data.id}`, {
1661
+ fallback: (text, url) => `${text}: (${url})`
1662
+ })}`);
1606
1663
  return serverRPC.send("COMPLETE_WORKFLOW_RUN", {
1607
1664
  runId: data.id,
1608
1665
  output: JSON.stringify(output),
@@ -1617,9 +1674,9 @@ initializeRPC_fn = /* @__PURE__ */ __name(async function() {
1617
1674
  stackTrace: error2.stack
1618
1675
  };
1619
1676
  }
1620
- const parsedError = import_zod13.z.object({
1621
- name: import_zod13.z.string(),
1622
- message: import_zod13.z.string()
1677
+ const parsedError = import_zod14.z.object({
1678
+ name: import_zod14.z.string(),
1679
+ message: import_zod14.z.string()
1623
1680
  }).passthrough().safeParse(error2);
1624
1681
  if (parsedError.success) {
1625
1682
  return parsedError.data;
@@ -1659,7 +1716,7 @@ initializeHost_fn = /* @__PURE__ */ __name(async function() {
1659
1716
  if (!__privateGet(this, _serverRPC)) {
1660
1717
  throw new Error("Cannot initialize host without an RPC connection");
1661
1718
  }
1662
- const response = await __privateMethod(this, _send, send_fn).call(this, "INITIALIZE_HOST", {
1719
+ const response = await __privateMethod(this, _send, send_fn).call(this, "INITIALIZE_HOST_V2", {
1663
1720
  apiKey: __privateGet(this, _apiKey),
1664
1721
  workflowId: __privateGet(this, _trigger).id,
1665
1722
  workflowName: __privateGet(this, _trigger).name,
@@ -1668,9 +1725,13 @@ initializeHost_fn = /* @__PURE__ */ __name(async function() {
1668
1725
  packageName: name,
1669
1726
  triggerTTL: __privateGet(this, _options).triggerTTL
1670
1727
  });
1728
+ if (!response) {
1729
+ throw new Error("Could not initialize workflow with server");
1730
+ }
1671
1731
  if (response?.type === "error") {
1672
1732
  throw new Error(response.message);
1673
1733
  }
1734
+ __privateSet(this, _registerResponse, response.data);
1674
1735
  __privateGet(this, _logger3).debug("Successfully initialized workflow with server");
1675
1736
  }, "#initializeHost");
1676
1737
  _send = new WeakSet();
@@ -1731,20 +1792,18 @@ _client = new WeakMap();
1731
1792
 
1732
1793
  // src/customEvents.ts
1733
1794
  var import_node_fetch = __toESM(require("node-fetch"));
1734
- var import_ulid = require("ulid");
1735
- function sendEvent(id, event) {
1795
+ function sendEvent(idOrKey, event) {
1736
1796
  const triggerRun = triggerRunLocalStorage.getStore();
1737
1797
  if (!triggerRun) {
1738
- return sendEventFetch(event);
1798
+ return sendEventFetch(idOrKey, event);
1739
1799
  }
1740
- return triggerRun.sendEvent(id, event);
1800
+ return triggerRun.sendEvent(idOrKey, event);
1741
1801
  }
1742
1802
  __name(sendEvent, "sendEvent");
1743
- async function sendEventFetch(event) {
1803
+ async function sendEventFetch(id, event) {
1744
1804
  if (!process.env.TRIGGER_API_KEY) {
1745
1805
  throw new Error(`There was a problem sending a custom event: the TRIGGER_API_KEY environment variable is not set`);
1746
1806
  }
1747
- const id = (0, import_ulid.ulid)();
1748
1807
  const baseUrl = process.env.TRIGGER_API_URL || "https://app.trigger.dev";
1749
1808
  const url = `${baseUrl}/api/v1/events`;
1750
1809
  const response = await (0, import_node_fetch.default)(url, {