@keystrokehq/keystroke 1.0.14 → 1.0.15

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.
Files changed (53) hide show
  1. package/dist/action.cjs +1 -1
  2. package/dist/action.mjs +1 -1
  3. package/dist/agent.cjs +3 -3
  4. package/dist/agent.mjs +3 -3
  5. package/dist/app.cjs +1 -1
  6. package/dist/app.mjs +1 -1
  7. package/dist/client.cjs +1 -1
  8. package/dist/client.mjs +1 -1
  9. package/dist/config.d.cts +2 -2
  10. package/dist/config.d.cts.map +1 -1
  11. package/dist/config.d.mts +2 -2
  12. package/dist/config.d.mts.map +1 -1
  13. package/dist/credentials.cjs +1 -1
  14. package/dist/credentials.mjs +1 -1
  15. package/dist/{dist-DtejauR-.mjs → dist-BWGuF7Bi.mjs} +22 -9
  16. package/dist/dist-BWGuF7Bi.mjs.map +1 -0
  17. package/dist/{dist-C5UmW-zB.cjs → dist-CDMCEgV0.cjs} +22 -9
  18. package/dist/dist-CDMCEgV0.cjs.map +1 -0
  19. package/dist/{dist-DpZL1LE1.cjs → dist-CIXPxH8Y.cjs} +7 -3
  20. package/dist/dist-CIXPxH8Y.cjs.map +1 -0
  21. package/dist/{dist-DSbrc1sP.mjs → dist-DESn8Gyx.mjs} +3 -3
  22. package/dist/{dist-DSbrc1sP.mjs.map → dist-DESn8Gyx.mjs.map} +1 -1
  23. package/dist/{dist-Zh8nB_45.cjs → dist-jju5p8QW.cjs} +3 -3
  24. package/dist/{dist-Zh8nB_45.cjs.map → dist-jju5p8QW.cjs.map} +1 -1
  25. package/dist/{dist-D53HZMV9.mjs → dist-qrlBz5eZ.mjs} +7 -3
  26. package/dist/dist-qrlBz5eZ.mjs.map +1 -0
  27. package/dist/index-BTz2OMAM.d.cts.map +1 -1
  28. package/dist/index-Cq2F2XdS.d.mts.map +1 -1
  29. package/dist/index-WT4ULMiw.d.cts.map +1 -1
  30. package/dist/index-WT4ULMiw.d.mts.map +1 -1
  31. package/dist/{mistral-tahkZ8Hu.mjs → mistral-B3AiRi15.mjs} +2 -2
  32. package/dist/{mistral-tahkZ8Hu.mjs.map → mistral-B3AiRi15.mjs.map} +1 -1
  33. package/dist/{mistral-6XMKgah3.cjs → mistral-HS6Ekkp2.cjs} +2 -2
  34. package/dist/{mistral-6XMKgah3.cjs.map → mistral-HS6Ekkp2.cjs.map} +1 -1
  35. package/dist/{sse-CSbz_aIR.mjs → sse-DISKrIFa.mjs} +2 -2
  36. package/dist/{sse-CSbz_aIR.mjs.map → sse-DISKrIFa.mjs.map} +1 -1
  37. package/dist/{sse-PotOG2Pc.cjs → sse-ELfo0nZE.cjs} +2 -2
  38. package/dist/{sse-PotOG2Pc.cjs.map → sse-ELfo0nZE.cjs.map} +1 -1
  39. package/dist/trigger.cjs +135 -35
  40. package/dist/trigger.cjs.map +1 -1
  41. package/dist/trigger.d.cts +87 -20
  42. package/dist/trigger.d.cts.map +1 -1
  43. package/dist/trigger.d.mts +87 -20
  44. package/dist/trigger.d.mts.map +1 -1
  45. package/dist/trigger.mjs +122 -36
  46. package/dist/trigger.mjs.map +1 -1
  47. package/dist/workflow.cjs +1 -1
  48. package/dist/workflow.mjs +1 -1
  49. package/package.json +1 -1
  50. package/dist/dist-C5UmW-zB.cjs.map +0 -1
  51. package/dist/dist-D53HZMV9.mjs.map +0 -1
  52. package/dist/dist-DpZL1LE1.cjs.map +0 -1
  53. package/dist/dist-DtejauR-.mjs.map +0 -1
package/dist/trigger.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_dist = require("./dist-Zh8nB_45.cjs");
2
+ const require_dist = require("./dist-jju5p8QW.cjs");
3
3
  let zod = require("zod");
4
4
  //#region ../../node_modules/.pnpm/cron-schedule@6.0.0/node_modules/cron-schedule/dist/utils.js
5
5
  function extractDateElements(date) {
@@ -439,8 +439,21 @@ const zodSchema = zod.z.custom((v) => v instanceof zod.z.ZodType, "must be a Zod
439
439
  const workflowSchema = zod.z.custom((v) => require_dist.isWorkflow(v), "must be defineWorkflow(...)");
440
440
  const agentSchema = zod.z.custom((v) => typeof v === "object" && v !== null && typeof v.slug === "string" && v.slug.trim().length > 0 && typeof v.prompt === "function", "must be defineAgent(...)");
441
441
  const promptSchema = zod.z.union([zod.z.string(), zod.z.function()]);
442
+ /** backwards-compat: normalize legacy `key` fields to canonical `slug` before validation. */
443
+ function normalizeLegacySlugFields(value) {
444
+ if (typeof value !== "object" || value === null) return value;
445
+ const next = { ...value };
446
+ if (typeof next.slug !== "string" && typeof next.key === "string") next.slug = next.key;
447
+ delete next.key;
448
+ if (typeof next.source === "object" && next.source !== null) next.source = normalizeLegacySlugFields(next.source);
449
+ return next;
450
+ }
451
+ const slugField = zod.z.string().trim().min(1);
452
+ const optionalTextField = zod.z.string().optional();
442
453
  const baseSourceShape = {
443
- key: zod.z.string().trim().min(1),
454
+ slug: slugField,
455
+ name: optionalTextField,
456
+ description: optionalTextField,
444
457
  attach: zod.z.function()
445
458
  };
446
459
  const webhookSourceSchema = zod.z.object({
@@ -466,27 +479,32 @@ const pollSourceSchema = zod.z.object({
466
479
  passes: zod.z.function()
467
480
  });
468
481
  /** Runtime validation for a trigger source (webhook | cron | poll). */
469
- const triggerSourceSchema = zod.z.discriminatedUnion("kind", [
482
+ const triggerSourceSchema = zod.z.preprocess(normalizeLegacySlugFields, zod.z.discriminatedUnion("kind", [
470
483
  webhookSourceSchema,
471
484
  cronSourceSchema,
472
485
  pollSourceSchema
473
- ]);
486
+ ]));
474
487
  const workflowAttachmentSchema = zod.z.object({
475
- key: zod.z.string().trim().min(1),
488
+ slug: slugField,
489
+ name: optionalTextField,
490
+ description: optionalTextField,
476
491
  source: triggerSourceSchema,
477
492
  target: zod.z.literal("workflow"),
478
493
  workflow: workflowSchema,
479
494
  transform: zod.z.function().optional()
480
495
  });
481
496
  const agentAttachmentSchema = zod.z.object({
482
- key: zod.z.string().trim().min(1),
497
+ slug: slugField,
498
+ name: optionalTextField,
499
+ description: optionalTextField,
483
500
  source: triggerSourceSchema,
484
501
  target: zod.z.literal("agent"),
485
502
  agent: agentSchema,
486
503
  prompt: promptSchema
487
504
  });
505
+ const triggerAttachmentCoreSchemaBase = zod.z.discriminatedUnion("target", [workflowAttachmentSchema, agentAttachmentSchema]);
488
506
  /** Runtime validation for an unbranded trigger attachment. */
489
- const triggerAttachmentCoreSchema = zod.z.discriminatedUnion("target", [workflowAttachmentSchema, agentAttachmentSchema]);
507
+ const triggerAttachmentCoreSchema = zod.z.preprocess(normalizeLegacySlugFields, triggerAttachmentCoreSchemaBase);
490
508
  const TRIGGER_ATTACHMENT = Symbol.for("keystroke.triggerAttachment");
491
509
  /**
492
510
  * Validates brand + shape via `triggerAttachmentCoreSchema` so server discovery
@@ -503,19 +521,54 @@ function isWorkflowTriggerAttachment(attachment) {
503
521
  function isAgentTriggerAttachment(attachment) {
504
522
  return attachment.target === "agent";
505
523
  }
506
- function workflowKeyFromDefinition(workflow) {
524
+ /** Resolve slug from authoring options (`slug` preferred, `key` fallback). */
525
+ function resolveAuthoringSlug(input, label = "trigger") {
526
+ const slug = input.slug?.trim() || input.key?.trim();
527
+ if (!slug) throw new Error(`${label} requires a non-empty slug`);
528
+ return slug;
529
+ }
530
+ /** Composite attachment slug `{sourceSlug}:{targetSlug}`. */
531
+ function attachmentSlugFrom(sourceSlug, targetSlug) {
532
+ return `${sourceSlug}:${targetSlug}`;
533
+ }
534
+ /** Read slug from a trigger source (`slug` preferred, legacy `key` fallback). */
535
+ function sourceSlugFrom(source) {
536
+ const slug = source.slug?.trim() || source.key?.trim();
537
+ if (!slug) throw new Error("Trigger source requires slug or legacy key");
538
+ return slug;
539
+ }
540
+ /** Read slug from a trigger attachment (`slug` preferred, legacy `key` fallback). */
541
+ function attachmentSlugFromRecord(attachment) {
542
+ const slug = attachment.slug?.trim() || attachment.key?.trim();
543
+ if (!slug) throw new Error("Trigger attachment requires slug or legacy key");
544
+ return slug;
545
+ }
546
+ /** Source slug prefix from a composite attachment slug. */
547
+ function triggerSourceSlugFromAttachmentSlug(attachmentSlug) {
548
+ const separator = attachmentSlug.indexOf(":");
549
+ return separator === -1 ? attachmentSlug : attachmentSlug.slice(0, separator);
550
+ }
551
+ /** Target slug suffix from a composite attachment slug. */
552
+ function triggerTargetSlugFromAttachmentSlug(attachmentSlug) {
553
+ const separator = attachmentSlug.indexOf(":");
554
+ return separator === -1 ? attachmentSlug : attachmentSlug.slice(separator + 1);
555
+ }
556
+ function workflowSlugFromDefinition(workflow) {
507
557
  const slug = workflow.slug?.trim();
508
558
  if (!slug) throw new Error("Workflow definition requires a non-empty slug");
509
559
  return slug;
510
560
  }
511
- function agentKeyFromAgent(agent) {
561
+ function agentSlugFromAgent(agent) {
512
562
  const slug = agent.slug?.trim();
513
563
  if (!slug) throw new Error("Agent definition requires a non-empty slug");
514
564
  return slug;
515
565
  }
516
- function attachmentKeyFrom(triggerKey, targetKey) {
517
- return `${triggerKey}:${targetKey}`;
518
- }
566
+ /** @deprecated Use {@link attachmentSlugFrom}. */
567
+ const attachmentKeyFrom = attachmentSlugFrom;
568
+ /** @deprecated Use {@link workflowSlugFromDefinition}. */
569
+ const workflowKeyFromDefinition = workflowSlugFromDefinition;
570
+ /** @deprecated Use {@link agentSlugFromAgent}. */
571
+ const agentKeyFromAgent = agentSlugFromAgent;
519
572
  function isAgentAttachOptions(options) {
520
573
  return "agent" in options;
521
574
  }
@@ -528,7 +581,7 @@ function defineTriggerAttachment(input) {
528
581
  const result = triggerAttachmentCoreSchema.safeParse(input);
529
582
  if (!result.success) throw new Error(`Invalid trigger attachment: ${formatIssues(result.error.issues)}`);
530
583
  return {
531
- ...input,
584
+ ...result.data,
532
585
  [TRIGGER_ATTACHMENT]: true
533
586
  };
534
587
  }
@@ -537,16 +590,40 @@ function formatIssues(issues) {
537
590
  return `${issue.path.length > 0 ? `${issue.path.join(".")}: ` : ""}${issue.message}`;
538
591
  }).join("; ");
539
592
  }
540
- function attachFromSource(source, triggerKey, options) {
593
+ function triggerMetaFromSource(source) {
594
+ return {
595
+ ...source.name !== void 0 ? { name: source.name } : {},
596
+ ...source.description !== void 0 ? { description: source.description } : {}
597
+ };
598
+ }
599
+ function triggerMetaFromAttachment(attachment) {
600
+ const name = attachment.name ?? attachment.source.name;
601
+ const description = attachment.description ?? attachment.source.description;
602
+ return {
603
+ ...name !== void 0 ? { name } : {},
604
+ ...description !== void 0 ? { description } : {}
605
+ };
606
+ }
607
+ function triggerMetaRecordFromAttachment(attachment) {
608
+ const meta = triggerMetaFromAttachment(attachment);
609
+ return {
610
+ name: meta.name ?? null,
611
+ description: meta.description ?? null
612
+ };
613
+ }
614
+ function attachFromSource(source, sourceSlug, options) {
615
+ const meta = triggerMetaFromSource(source);
541
616
  if (isAgentAttachOptions(options)) return defineTriggerAttachment({
542
- key: attachmentKeyFrom(triggerKey, agentKeyFromAgent(options.agent)),
617
+ slug: attachmentSlugFrom(sourceSlug, agentSlugFromAgent(options.agent)),
618
+ ...meta,
543
619
  source,
544
620
  target: "agent",
545
621
  agent: options.agent,
546
622
  prompt: options.prompt
547
623
  });
548
624
  return defineTriggerAttachment({
549
- key: attachmentKeyFrom(triggerKey, workflowKeyFromDefinition(options.workflow)),
625
+ slug: attachmentSlugFrom(sourceSlug, workflowSlugFromDefinition(options.workflow)),
626
+ ...meta,
550
627
  source,
551
628
  target: "workflow",
552
629
  workflow: options.workflow,
@@ -569,7 +646,7 @@ function matchWebhookPayload(raw, schemas) {
569
646
  const data = matchShapeAndFilter(zod.z.fromJSONSchema(schema.requestSchema), schema.filterSchema ? zod.z.fromJSONSchema(schema.filterSchema) : void 0, raw);
570
647
  if (data === void 0) continue;
571
648
  matches.push({
572
- attachmentKey: schema.attachmentKey,
649
+ attachmentSlug: schema.attachmentSlug,
573
650
  data
574
651
  });
575
652
  }
@@ -590,19 +667,21 @@ function webhookObjectSchema(schema) {
590
667
  * Defines a webhook trigger source — fires its attached workflow when a request
591
668
  * hits `/triggers/{endpoint}` and satisfies `request` plus any optional `filter`.
592
669
  *
593
- * @param options.key - Stable trigger key; attachment id is `{key}:{workflowKey}`.
670
+ * @param options.slug - Stable trigger source slug; attachment slug is `{slug}:{targetSlug}`.
671
+ * @param options.key - **Deprecated.** Accepted for backwards-compatible definitions.
594
672
  * @param options.endpoint - Shared route suffix under `/triggers/` (e.g. `"stripe"`).
595
673
  */
596
674
  function defineWebhookSource(options) {
597
- const triggerKey = options.key.trim();
598
- if (!triggerKey) throw new Error("defineWebhookSource requires a non-empty key");
675
+ const sourceSlug = resolveAuthoringSlug(options, "defineWebhookSource");
599
676
  const endpoint = normalizeWebhookEndpoint(options.endpoint);
600
677
  if (!endpoint) throw new Error("defineWebhookSource requires a non-empty endpoint");
601
678
  const request = webhookObjectSchema(options.request);
602
679
  const filter = options.filter ? webhookObjectSchema(options.filter) : void 0;
603
680
  const source = {
604
681
  kind: "webhook",
605
- key: triggerKey,
682
+ slug: sourceSlug,
683
+ ...options.name !== void 0 ? { name: options.name } : {},
684
+ ...options.description !== void 0 ? { description: options.description } : {},
606
685
  endpoint,
607
686
  request,
608
687
  filter,
@@ -610,7 +689,7 @@ function defineWebhookSource(options) {
610
689
  return passesTriggerMatch(request, filter, payload);
611
690
  },
612
691
  attach(attachOptions) {
613
- return attachFromSource(source, triggerKey, attachOptions);
692
+ return attachFromSource(source, sourceSlug, attachOptions);
614
693
  }
615
694
  };
616
695
  return source;
@@ -618,23 +697,28 @@ function defineWebhookSource(options) {
618
697
  /**
619
698
  * Defines a cron trigger source — fires its attached workflow on a schedule.
620
699
  *
621
- * @param options.key - Stable trigger key; the attachment id is `{key}:{workflowKey}`.
700
+ * @param options.slug - Stable trigger source slug; attachment slug is `{slug}:{targetSlug}`.
701
+ * @param options.key - **Deprecated.** Accepted for backwards-compatible definitions.
702
+ * @param options.name - Optional human-readable name shown in the platform.
703
+ * @param options.description - Optional short description shown in the platform.
622
704
  * @param options.schedule - A cron expression. Pass a 5-field literal (e.g.
623
705
  * `"0 9 * * *"`) for compile-time shape checking, or wrap with
624
706
  * `parseCronSchedule(...)` for 6-field, named (`MON`), or `@daily`-style
625
707
  * schedules. Validated at runtime; throws if the expression is invalid.
626
708
  * @example
627
- * defineCronSource({ key: "morning", schedule: "0 9 * * *" }).attach({ workflow });
709
+ * defineCronSource({ slug: "morning", schedule: "0 9 * * *" }).attach({ workflow });
628
710
  */
629
711
  function defineCronSource(options) {
630
- const triggerKey = options.key.trim();
631
- if (!triggerKey) throw new Error("defineCronSource requires a non-empty key");
712
+ const sourceSlug = resolveAuthoringSlug(options, "defineCronSource");
713
+ const schedule = parseCronSchedule(options.schedule);
632
714
  const source = {
633
715
  kind: "cron",
634
- key: triggerKey,
635
- schedule: parseCronSchedule(options.schedule),
716
+ slug: sourceSlug,
717
+ ...options.name !== void 0 ? { name: options.name } : {},
718
+ ...options.description !== void 0 ? { description: options.description } : {},
719
+ schedule,
636
720
  attach(attachOptions) {
637
- return attachFromSource(source, triggerKey, attachOptions);
721
+ return attachFromSource(source, sourceSlug, attachOptions);
638
722
  }
639
723
  };
640
724
  return source;
@@ -643,25 +727,27 @@ function defineCronSource(options) {
643
727
  * Defines a poll trigger source — runs `run` on a schedule and, when the result
644
728
  * passes any `.filter(...)`, fires the attached workflow with it.
645
729
  *
646
- * @param options.key - Stable trigger key; the attachment id is `{key}:{workflowKey}`.
730
+ * @param options.slug - Stable trigger source slug; attachment slug is `{slug}:{targetSlug}`.
731
+ * @param options.key - **Deprecated.** Accepted for backwards-compatible definitions.
647
732
  * @param options.id - Optional group id; poll sources sharing an id poll together.
648
733
  * @param options.schedule - Cron expression for the poll cadence (see `defineCronSource`).
649
734
  * @param options.run - Produces the payload checked by `filter` and passed to the workflow.
650
735
  * @param options.filter - Source-level predicate; the workflow only fires when it returns true.
651
736
  * @example
652
- * definePollSource({ key: "inbox", schedule: "0 * * * *", run: fetchInbox })
737
+ * definePollSource({ slug: "inbox", schedule: "0 * * * *", run: fetchInbox })
653
738
  * .filter((r) => r.length > 0)
654
739
  * .attach({ workflow });
655
740
  */
656
741
  function definePollSource(options) {
657
- const triggerKey = options.key.trim();
658
- if (!triggerKey) throw new Error("definePollSource requires a non-empty key");
742
+ const sourceSlug = resolveAuthoringSlug(options, "definePollSource");
659
743
  const schedule = parseCronSchedule(options.schedule);
660
744
  const filters = [];
661
745
  if (options.filter) filters.push(options.filter);
662
746
  const source = {
663
747
  kind: "poll",
664
- key: triggerKey,
748
+ slug: sourceSlug,
749
+ ...options.name !== void 0 ? { name: options.name } : {},
750
+ ...options.description !== void 0 ? { description: options.description } : {},
665
751
  id: options.id,
666
752
  schedule,
667
753
  run: options.run,
@@ -670,7 +756,7 @@ function definePollSource(options) {
670
756
  return source.filters.every((candidate) => candidate(payload));
671
757
  },
672
758
  attach(attachOptions) {
673
- return attachFromSource(source, triggerKey, attachOptions);
759
+ return attachFromSource(source, sourceSlug, attachOptions);
674
760
  }
675
761
  };
676
762
  const chain = source;
@@ -759,6 +845,11 @@ function resolveAttachmentInput(attachment, payload) {
759
845
  }
760
846
  //#endregion
761
847
  exports.TRIGGER_ATTACHMENT = TRIGGER_ATTACHMENT;
848
+ exports.agentKeyFromAgent = agentKeyFromAgent;
849
+ exports.agentSlugFromAgent = agentSlugFromAgent;
850
+ exports.attachmentKeyFrom = attachmentKeyFrom;
851
+ exports.attachmentSlugFrom = attachmentSlugFrom;
852
+ exports.attachmentSlugFromRecord = attachmentSlugFromRecord;
762
853
  exports.cronScheduleSchema = cronScheduleSchema;
763
854
  exports.defineCronSource = defineCronSource;
764
855
  exports.definePollSource = definePollSource;
@@ -776,6 +867,15 @@ exports.parseTriggerSchedule = parseTriggerSchedule;
776
867
  exports.resolveAgentPrompt = resolveAgentPrompt;
777
868
  exports.resolveAttachmentInput = resolveAttachmentInput;
778
869
  exports.resolveAttachmentTransform = resolveAttachmentTransform;
870
+ exports.resolveAuthoringSlug = resolveAuthoringSlug;
779
871
  exports.resolveCronSchedule = resolveCronSchedule;
872
+ exports.sourceSlugFrom = sourceSlugFrom;
873
+ exports.triggerMetaFromAttachment = triggerMetaFromAttachment;
874
+ exports.triggerMetaFromSource = triggerMetaFromSource;
875
+ exports.triggerMetaRecordFromAttachment = triggerMetaRecordFromAttachment;
876
+ exports.triggerSourceSlugFromAttachmentSlug = triggerSourceSlugFromAttachmentSlug;
877
+ exports.triggerTargetSlugFromAttachmentSlug = triggerTargetSlugFromAttachmentSlug;
878
+ exports.workflowKeyFromDefinition = workflowKeyFromDefinition;
879
+ exports.workflowSlugFromDefinition = workflowSlugFromDefinition;
780
880
 
781
881
  //# sourceMappingURL=trigger.cjs.map