@mastra/factory 0.26.0-alpha.2 → 0.26.0-alpha.3

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 (154) hide show
  1. package/README.md +74 -7
  2. package/dist/boards/define-board.d.ts +19 -0
  3. package/dist/boards/define-board.d.ts.map +1 -1
  4. package/dist/boards/define-board.js +41 -9
  5. package/dist/boards/define-board.js.map +1 -1
  6. package/dist/boards/project-boards.d.ts +78 -0
  7. package/dist/boards/project-boards.d.ts.map +1 -0
  8. package/dist/boards/project-boards.js +194 -0
  9. package/dist/boards/project-boards.js.map +1 -0
  10. package/dist/boards/review.js +2 -2
  11. package/dist/boards/review.js.map +1 -1
  12. package/dist/boards/stored-board.d.ts +101 -0
  13. package/dist/boards/stored-board.d.ts.map +1 -0
  14. package/dist/boards/stored-board.js +139 -0
  15. package/dist/boards/stored-board.js.map +1 -0
  16. package/dist/boards/work.d.ts.map +1 -1
  17. package/dist/boards/work.js +6 -3
  18. package/dist/boards/work.js.map +1 -1
  19. package/dist/capabilities/intake.d.ts +6 -0
  20. package/dist/capabilities/intake.d.ts.map +1 -1
  21. package/dist/factory.d.ts +15 -2
  22. package/dist/factory.d.ts.map +1 -1
  23. package/dist/factory.js +49 -10
  24. package/dist/factory.js.map +1 -1
  25. package/dist/integrations/jira/binding-scope.d.ts +30 -0
  26. package/dist/integrations/jira/binding-scope.d.ts.map +1 -0
  27. package/dist/integrations/jira/binding-scope.js +50 -0
  28. package/dist/integrations/jira/binding-scope.js.map +1 -0
  29. package/dist/integrations/jira/claim.d.ts +12 -0
  30. package/dist/integrations/jira/claim.d.ts.map +1 -1
  31. package/dist/integrations/jira/claim.js +24 -1
  32. package/dist/integrations/jira/claim.js.map +1 -1
  33. package/dist/integrations/jira/intake-jql.d.ts +32 -0
  34. package/dist/integrations/jira/intake-jql.d.ts.map +1 -0
  35. package/dist/integrations/jira/intake-jql.js +57 -0
  36. package/dist/integrations/jira/intake-jql.js.map +1 -0
  37. package/dist/integrations/jira/integration.d.ts +4 -3
  38. package/dist/integrations/jira/integration.d.ts.map +1 -1
  39. package/dist/integrations/jira/integration.js +14 -21
  40. package/dist/integrations/jira/integration.js.map +1 -1
  41. package/dist/integrations/jira/routes.d.ts +3 -0
  42. package/dist/integrations/jira/routes.d.ts.map +1 -1
  43. package/dist/integrations/jira/routes.js +16 -29
  44. package/dist/integrations/jira/routes.js.map +1 -1
  45. package/dist/integrations/jira/rules.d.ts.map +1 -1
  46. package/dist/integrations/jira/rules.js +8 -13
  47. package/dist/integrations/jira/rules.js.map +1 -1
  48. package/dist/integrations/platform/jira/integration.d.ts +7 -1
  49. package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
  50. package/dist/integrations/platform/jira/integration.js +26 -24
  51. package/dist/integrations/platform/jira/integration.js.map +1 -1
  52. package/dist/integrations/platform/jira/routes.d.ts +3 -0
  53. package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
  54. package/dist/integrations/platform/jira/routes.js +17 -28
  55. package/dist/integrations/platform/jira/routes.js.map +1 -1
  56. package/dist/routes/attention-providers.d.ts +2 -1
  57. package/dist/routes/attention-providers.d.ts.map +1 -1
  58. package/dist/routes/attention-providers.js +3 -2
  59. package/dist/routes/attention-providers.js.map +1 -1
  60. package/dist/routes/attention.d.ts +2 -1
  61. package/dist/routes/attention.d.ts.map +1 -1
  62. package/dist/routes/attention.js.map +1 -1
  63. package/dist/routes/boards.d.ts +30 -0
  64. package/dist/routes/boards.d.ts.map +1 -0
  65. package/dist/routes/boards.js +272 -0
  66. package/dist/routes/boards.js.map +1 -0
  67. package/dist/routes/contracts.d.ts +249 -0
  68. package/dist/routes/contracts.d.ts.map +1 -1
  69. package/dist/routes/contracts.js +107 -35
  70. package/dist/routes/contracts.js.map +1 -1
  71. package/dist/routes/intake.d.ts +15 -10
  72. package/dist/routes/intake.d.ts.map +1 -1
  73. package/dist/routes/intake.js +109 -22
  74. package/dist/routes/intake.js.map +1 -1
  75. package/dist/routes/projects.d.ts +3 -0
  76. package/dist/routes/projects.d.ts.map +1 -1
  77. package/dist/routes/projects.js +10 -1
  78. package/dist/routes/projects.js.map +1 -1
  79. package/dist/routes/surface.d.ts +10 -3
  80. package/dist/routes/surface.d.ts.map +1 -1
  81. package/dist/routes/surface.js +12 -1
  82. package/dist/routes/surface.js.map +1 -1
  83. package/dist/routes/tenant-credentials.d.ts +9 -0
  84. package/dist/routes/tenant-credentials.d.ts.map +1 -1
  85. package/dist/routes/tenant-credentials.js +24 -2
  86. package/dist/routes/tenant-credentials.js.map +1 -1
  87. package/dist/routes/work-items.d.ts +3 -1
  88. package/dist/routes/work-items.d.ts.map +1 -1
  89. package/dist/routes/work-items.js +64 -42
  90. package/dist/routes/work-items.js.map +1 -1
  91. package/dist/rules/dispatcher.d.ts +7 -1
  92. package/dist/rules/dispatcher.d.ts.map +1 -1
  93. package/dist/rules/dispatcher.js +70 -34
  94. package/dist/rules/dispatcher.js.map +1 -1
  95. package/dist/rules/processor.d.ts +3 -1
  96. package/dist/rules/processor.d.ts.map +1 -1
  97. package/dist/rules/processor.js +11 -6
  98. package/dist/rules/processor.js.map +1 -1
  99. package/dist/rules/tools.d.ts +2 -1
  100. package/dist/rules/tools.d.ts.map +1 -1
  101. package/dist/rules/tools.js +2 -1
  102. package/dist/rules/tools.js.map +1 -1
  103. package/dist/rules/transition-service.d.ts +3 -1
  104. package/dist/rules/transition-service.d.ts.map +1 -1
  105. package/dist/rules/transition-service.js +12 -12
  106. package/dist/rules/transition-service.js.map +1 -1
  107. package/dist/storage/domains/audit/actions.d.ts +1 -0
  108. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  109. package/dist/storage/domains/audit/actions.js +6 -1
  110. package/dist/storage/domains/audit/actions.js.map +1 -1
  111. package/dist/storage/domains/boards/base.d.ts +110 -0
  112. package/dist/storage/domains/boards/base.d.ts.map +1 -0
  113. package/dist/storage/domains/boards/base.js +292 -0
  114. package/dist/storage/domains/boards/base.js.map +1 -0
  115. package/dist/storage/domains/boards/schemas.d.ts +11 -0
  116. package/dist/storage/domains/boards/schemas.d.ts.map +1 -0
  117. package/dist/storage/domains/boards/schemas.js +106 -0
  118. package/dist/storage/domains/boards/schemas.js.map +1 -0
  119. package/dist/storage/domains/credentials/base.d.ts +4 -1
  120. package/dist/storage/domains/credentials/base.d.ts.map +1 -1
  121. package/dist/storage/domains/credentials/base.js +5 -2
  122. package/dist/storage/domains/credentials/base.js.map +1 -1
  123. package/dist/storage/domains/intake/base.d.ts +86 -5
  124. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  125. package/dist/storage/domains/intake/base.js +298 -59
  126. package/dist/storage/domains/intake/base.js.map +1 -1
  127. package/dist/storage/domains/projects/base.d.ts +2 -1
  128. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  129. package/dist/storage/domains/projects/base.js +15 -10
  130. package/dist/storage/domains/projects/base.js.map +1 -1
  131. package/dist/storage/domains/work-items/base.d.ts +14 -0
  132. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  133. package/dist/storage/domains/work-items/base.js +39 -11
  134. package/dist/storage/domains/work-items/base.js.map +1 -1
  135. package/dist/tools/read-tools.d.ts +3 -1
  136. package/dist/tools/read-tools.d.ts.map +1 -1
  137. package/dist/tools/read-tools.js +3 -2
  138. package/dist/tools/read-tools.js.map +1 -1
  139. package/dist/tools/session-tools.d.ts +3 -1
  140. package/dist/tools/session-tools.d.ts.map +1 -1
  141. package/dist/tools/session-tools.js +2 -1
  142. package/dist/tools/session-tools.js.map +1 -1
  143. package/dist/tools/sessions-state-processor.d.ts +3 -1
  144. package/dist/tools/sessions-state-processor.d.ts.map +1 -1
  145. package/dist/tools/sessions-state-processor.js +2 -1
  146. package/dist/tools/sessions-state-processor.js.map +1 -1
  147. package/dist/tools/work-item-tools.d.ts +3 -1
  148. package/dist/tools/work-item-tools.d.ts.map +1 -1
  149. package/dist/tools/work-item-tools.js +3 -2
  150. package/dist/tools/work-item-tools.js.map +1 -1
  151. package/dist/workspace.js +1 -1
  152. package/factory-skills/factory-plan/SKILL.md +1 -1
  153. package/factory-skills/factory-triage/SKILL.md +18 -7
  154. package/package.json +9 -9
@@ -0,0 +1,30 @@
1
+ import type { IntakeStorage } from '../../storage/domains/intake/base.js';
2
+ import type { JiraIntakeScope } from './intake-jql.js';
3
+ /** The selected Jira projects that feed one Factory project, and the slice of each it takes. */
4
+ export interface JiraProjectScope {
5
+ /** Bound board per source id, for the rules that land new cards. */
6
+ intakeBoards: Record<string, string>;
7
+ /** One JQL scope per bound source, narrowed to this Factory's label slice. */
8
+ scopes: JiraIntakeScope[];
9
+ /** Whether an issue from `sourceId` carrying `labels` belongs to this Factory. */
10
+ takes(sourceId: string, labels: readonly string[]): boolean;
11
+ }
12
+ /**
13
+ * Narrow the caller's selected Jira projects to the ones that feed this
14
+ * Factory project, with the label slice its binding takes from each.
15
+ *
16
+ * A Jira issue carries no Factory project of its own, so without a binding
17
+ * every board view would ingest every selected project's issues into whichever
18
+ * Factory happened to be on screen. Routing is explicit: a project feeds this
19
+ * Factory only when its binding names both the Factory project and a board.
20
+ * Several Factories may share a project; their slices are disjoint, so each
21
+ * issue feeds exactly one of them. A sibling binding without a board does not
22
+ * poll, so it takes nothing from the others' slices until its board is set.
23
+ */
24
+ export declare function scopeJiraSourcesToProject({ intake, orgId, factoryProjectId, selectedIds, }: {
25
+ intake: Pick<IntakeStorage, 'listBindings'>;
26
+ orgId: string;
27
+ factoryProjectId: string;
28
+ selectedIds: readonly string[];
29
+ }): Promise<JiraProjectScope>;
30
+ //# sourceMappingURL=binding-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding-scope.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/binding-scope.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAC/F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,gGAAgG;AAChG,MAAM,WAAW,gBAAgB;IAC/B,oEAAoE;IACpE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,8EAA8E;IAC9E,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,kFAAkF;IAClF,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC;CAC7D;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,yBAAyB,CAAC,EAC9C,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,WAAW,GACZ,EAAE;IACD,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CAChC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAyB5B"}
@@ -0,0 +1,50 @@
1
+ import { bindingLabelSlice, bindingTakesIssue } from "../../storage/domains/intake/base.js";
2
+ // src/integrations/jira/binding-scope.ts
3
+ /**
4
+ * Narrow the caller's selected Jira projects to the ones that feed this
5
+ * Factory project, with the label slice its binding takes from each.
6
+ *
7
+ * A Jira issue carries no Factory project of its own, so without a binding
8
+ * every board view would ingest every selected project's issues into whichever
9
+ * Factory happened to be on screen. Routing is explicit: a project feeds this
10
+ * Factory only when its binding names both the Factory project and a board.
11
+ * Several Factories may share a project; their slices are disjoint, so each
12
+ * issue feeds exactly one of them. A sibling binding without a board does not
13
+ * poll, so it takes nothing from the others' slices until its board is set.
14
+ */
15
+ async function scopeJiraSourcesToProject({ intake, orgId, factoryProjectId, selectedIds }) {
16
+ const selected = new Set(selectedIds);
17
+ const bySource = /* @__PURE__ */ new Map();
18
+ for (const binding of await intake.listBindings({
19
+ orgId,
20
+ integrationId: "jira"
21
+ })) bySource.set(binding.sourceId, [...bySource.get(binding.sourceId) ?? [], binding]);
22
+ const intakeBoards = {};
23
+ const scopes = [];
24
+ const owned = /* @__PURE__ */ new Map();
25
+ for (const [sourceId, siblings] of bySource) {
26
+ const binding = siblings.find((candidate) => candidate.factoryProjectId === factoryProjectId);
27
+ if (!binding?.board || !selected.has(sourceId)) continue;
28
+ const active = siblings.filter((sibling) => sibling.board);
29
+ intakeBoards[sourceId] = binding.board;
30
+ scopes.push({
31
+ projectId: sourceId,
32
+ ...bindingLabelSlice(binding, active)
33
+ });
34
+ owned.set(sourceId, {
35
+ binding,
36
+ siblings: active
37
+ });
38
+ }
39
+ return {
40
+ intakeBoards,
41
+ scopes,
42
+ takes(sourceId, labels) {
43
+ const entry = owned.get(sourceId);
44
+ return entry !== void 0 && bindingTakesIssue(entry.binding, entry.siblings, labels);
45
+ }
46
+ };
47
+ }
48
+ export { scopeJiraSourcesToProject };
49
+
50
+ //# sourceMappingURL=binding-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binding-scope.js","names":[],"sources":["../../../src/integrations/jira/binding-scope.ts"],"sourcesContent":["import { bindingLabelSlice, bindingTakesIssue } from '../../storage/domains/intake/base.js';\nimport type { IntakeSourceBinding, IntakeStorage } from '../../storage/domains/intake/base.js';\nimport type { JiraIntakeScope } from './intake-jql.js';\n\n/** The selected Jira projects that feed one Factory project, and the slice of each it takes. */\nexport interface JiraProjectScope {\n /** Bound board per source id, for the rules that land new cards. */\n intakeBoards: Record<string, string>;\n /** One JQL scope per bound source, narrowed to this Factory's label slice. */\n scopes: JiraIntakeScope[];\n /** Whether an issue from `sourceId` carrying `labels` belongs to this Factory. */\n takes(sourceId: string, labels: readonly string[]): boolean;\n}\n\n/**\n * Narrow the caller's selected Jira projects to the ones that feed this\n * Factory project, with the label slice its binding takes from each.\n *\n * A Jira issue carries no Factory project of its own, so without a binding\n * every board view would ingest every selected project's issues into whichever\n * Factory happened to be on screen. Routing is explicit: a project feeds this\n * Factory only when its binding names both the Factory project and a board.\n * Several Factories may share a project; their slices are disjoint, so each\n * issue feeds exactly one of them. A sibling binding without a board does not\n * poll, so it takes nothing from the others' slices until its board is set.\n */\nexport async function scopeJiraSourcesToProject({\n intake,\n orgId,\n factoryProjectId,\n selectedIds,\n}: {\n intake: Pick<IntakeStorage, 'listBindings'>;\n orgId: string;\n factoryProjectId: string;\n selectedIds: readonly string[];\n}): Promise<JiraProjectScope> {\n const selected = new Set(selectedIds);\n const bySource = new Map<string, IntakeSourceBinding[]>();\n for (const binding of await intake.listBindings({ orgId, integrationId: 'jira' })) {\n bySource.set(binding.sourceId, [...(bySource.get(binding.sourceId) ?? []), binding]);\n }\n const intakeBoards: Record<string, string> = {};\n const scopes: JiraIntakeScope[] = [];\n const owned = new Map<string, { binding: IntakeSourceBinding; siblings: IntakeSourceBinding[] }>();\n for (const [sourceId, siblings] of bySource) {\n const binding = siblings.find(candidate => candidate.factoryProjectId === factoryProjectId);\n if (!binding?.board || !selected.has(sourceId)) continue;\n const active = siblings.filter(sibling => sibling.board);\n intakeBoards[sourceId] = binding.board;\n scopes.push({ projectId: sourceId, ...bindingLabelSlice(binding, active) });\n owned.set(sourceId, { binding, siblings: active });\n }\n return {\n intakeBoards,\n scopes,\n takes(sourceId, labels) {\n const entry = owned.get(sourceId);\n return entry !== undefined && bindingTakesIssue(entry.binding, entry.siblings, labels);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,eAAsB,0BAA0B,EAC9C,QACA,OACA,kBACA,eAM4B;CAC5B,MAAM,WAAW,IAAI,IAAI,WAAW;CACpC,MAAM,2BAAW,IAAI,IAAmC;CACxD,KAAK,MAAM,WAAW,MAAM,OAAO,aAAa;EAAE;EAAO,eAAe;CAAO,CAAC,GAC9E,SAAS,IAAI,QAAQ,UAAU,CAAC,GAAI,SAAS,IAAI,QAAQ,QAAQ,KAAK,CAAC,GAAI,OAAO,CAAC;CAErF,MAAM,eAAuC,CAAC;CAC9C,MAAM,SAA4B,CAAC;CACnC,MAAM,wBAAQ,IAAI,IAA+E;CACjG,KAAK,MAAM,CAAC,UAAU,aAAa,UAAU;EAC3C,MAAM,UAAU,SAAS,MAAK,cAAa,UAAU,qBAAqB,gBAAgB;EAC1F,IAAI,CAAC,SAAS,SAAS,CAAC,SAAS,IAAI,QAAQ,GAAG;EAChD,MAAM,SAAS,SAAS,QAAO,YAAW,QAAQ,KAAK;EACvD,aAAa,YAAY,QAAQ;EACjC,OAAO,KAAK;GAAE,WAAW;GAAU,GAAG,kBAAkB,SAAS,MAAM;EAAE,CAAC;EAC1E,MAAM,IAAI,UAAU;GAAE;GAAS,UAAU;EAAO,CAAC;CACnD;CACA,OAAO;EACL;EACA;EACA,MAAM,UAAU,QAAQ;GACtB,MAAM,QAAQ,MAAM,IAAI,QAAQ;GAChC,OAAO,UAAU,KAAA,KAAa,kBAAkB,MAAM,SAAS,MAAM,UAAU,MAAM;EACvF;CACF;AACF"}
@@ -1,3 +1,4 @@
1
+ import type { WorkItemRow, WorkItemsStorage } from '../../storage/domains/work-items/base.js';
1
2
  /**
2
3
  * Org-wide ownership key for a Jira issue's Factory card. Keyed by the issue
3
4
  * reference the intake feed serves as `id` — the direct integration's stable
@@ -6,4 +7,15 @@
6
7
  * so a single live card holds the claim org-wide.
7
8
  */
8
9
  export declare function jiraClaimKey(issueRef: string): string;
10
+ /** Every card the org holds for one Jira issue: its claimant, plus cards filed before claims existed. */
11
+ export declare function jiraIssueCards(workItems: Pick<WorkItemsStorage, 'getByClaimKey' | 'listBySource'>, { orgId, issueRef }: {
12
+ orgId: string;
13
+ issueRef: string;
14
+ }): Promise<WorkItemRow[]>;
15
+ /** Whether `factoryProjectId` holds a card for the issue, live or finished. Without card storage nothing is filed. */
16
+ export declare function jiraIssueFiledIn(workItems: Pick<WorkItemsStorage, 'getByClaimKey' | 'listBySource'> | undefined, { orgId, factoryProjectId, issueRef }: {
17
+ orgId: string;
18
+ factoryProjectId: string;
19
+ issueRef: string;
20
+ }): Promise<boolean>;
9
21
  //# sourceMappingURL=claim.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/claim.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD"}
1
+ {"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/claim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AAE9F;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,yGAAyG;AACzG,wBAAsB,cAAc,CAClC,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,eAAe,GAAG,cAAc,CAAC,EACnE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACvD,OAAO,CAAC,WAAW,EAAE,CAAC,CAMxB;AAED,sHAAsH;AACtH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,eAAe,GAAG,cAAc,CAAC,GAAG,SAAS,EAC/E,EAAE,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACnG,OAAO,CAAC,OAAO,CAAC,CAIlB"}
@@ -9,6 +9,29 @@
9
9
  function jiraClaimKey(issueRef) {
10
10
  return `jira:issue:${issueRef}`;
11
11
  }
12
- export { jiraClaimKey };
12
+ /** Every card the org holds for one Jira issue: its claimant, plus cards filed before claims existed. */
13
+ async function jiraIssueCards(workItems, { orgId, issueRef }) {
14
+ const [claimant, legacy] = await Promise.all([workItems.getByClaimKey({
15
+ orgId,
16
+ claimKey: jiraClaimKey(issueRef)
17
+ }), workItems.listBySource({
18
+ orgId,
19
+ source: {
20
+ integrationId: "jira",
21
+ type: "issue",
22
+ externalId: issueRef
23
+ }
24
+ })]);
25
+ return claimant ? [claimant, ...legacy] : legacy;
26
+ }
27
+ /** Whether `factoryProjectId` holds a card for the issue, live or finished. Without card storage nothing is filed. */
28
+ async function jiraIssueFiledIn(workItems, { orgId, factoryProjectId, issueRef }) {
29
+ if (!workItems) return false;
30
+ return (await jiraIssueCards(workItems, {
31
+ orgId,
32
+ issueRef
33
+ })).some((card) => card.factoryProjectId === factoryProjectId);
34
+ }
35
+ export { jiraClaimKey, jiraIssueCards, jiraIssueFiledIn };
13
36
 
14
37
  //# sourceMappingURL=claim.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"claim.js","names":[],"sources":["../../../src/integrations/jira/claim.ts"],"sourcesContent":["/**\n * Org-wide ownership key for a Jira issue's Factory card. Keyed by the issue\n * reference the intake feed serves as `id` — the direct integration's stable\n * Jira issue id, or the Platform-encoded issue reference (connection + key +\n * project). Either way one key names one issue across every Factory project,\n * so a single live card holds the claim org-wide.\n */\nexport function jiraClaimKey(issueRef: string): string {\n return `jira:issue:${issueRef}`;\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,aAAa,UAA0B;CACrD,OAAO,cAAc;AACvB"}
1
+ {"version":3,"file":"claim.js","names":[],"sources":["../../../src/integrations/jira/claim.ts"],"sourcesContent":["import type { WorkItemRow, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\n\n/**\n * Org-wide ownership key for a Jira issue's Factory card. Keyed by the issue\n * reference the intake feed serves as `id` — the direct integration's stable\n * Jira issue id, or the Platform-encoded issue reference (connection + key +\n * project). Either way one key names one issue across every Factory project,\n * so a single live card holds the claim org-wide.\n */\nexport function jiraClaimKey(issueRef: string): string {\n return `jira:issue:${issueRef}`;\n}\n\n/** Every card the org holds for one Jira issue: its claimant, plus cards filed before claims existed. */\nexport async function jiraIssueCards(\n workItems: Pick<WorkItemsStorage, 'getByClaimKey' | 'listBySource'>,\n { orgId, issueRef }: { orgId: string; issueRef: string },\n): Promise<WorkItemRow[]> {\n const [claimant, legacy] = await Promise.all([\n workItems.getByClaimKey({ orgId, claimKey: jiraClaimKey(issueRef) }),\n workItems.listBySource({ orgId, source: { integrationId: 'jira', type: 'issue', externalId: issueRef } }),\n ]);\n return claimant ? [claimant, ...legacy] : legacy;\n}\n\n/** Whether `factoryProjectId` holds a card for the issue, live or finished. Without card storage nothing is filed. */\nexport async function jiraIssueFiledIn(\n workItems: Pick<WorkItemsStorage, 'getByClaimKey' | 'listBySource'> | undefined,\n { orgId, factoryProjectId, issueRef }: { orgId: string; factoryProjectId: string; issueRef: string },\n): Promise<boolean> {\n if (!workItems) return false;\n const cards = await jiraIssueCards(workItems, { orgId, issueRef });\n return cards.some(card => card.factoryProjectId === factoryProjectId);\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,aAAa,UAA0B;CACrD,OAAO,cAAc;AACvB;;AAGA,eAAsB,eACpB,WACA,EAAE,OAAO,YACe;CACxB,MAAM,CAAC,UAAU,UAAU,MAAM,QAAQ,IAAI,CAC3C,UAAU,cAAc;EAAE;EAAO,UAAU,aAAa,QAAQ;CAAE,CAAC,GACnE,UAAU,aAAa;EAAE;EAAO,QAAQ;GAAE,eAAe;GAAQ,MAAM;GAAS,YAAY;EAAS;CAAE,CAAC,CAC1G,CAAC;CACD,OAAO,WAAW,CAAC,UAAU,GAAG,MAAM,IAAI;AAC5C;;AAGA,eAAsB,iBACpB,WACA,EAAE,OAAO,kBAAkB,YACT;CAClB,IAAI,CAAC,WAAW,OAAO;CAEvB,QAAO,MADa,eAAe,WAAW;EAAE;EAAO;CAAS,CAAC,EAAA,CACpD,MAAK,SAAQ,KAAK,qBAAqB,gBAAgB;AACtE"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The JQL intake reads issues with, shared by the direct and Platform Jira
3
+ * integrations.
4
+ *
5
+ * Several Factory projects may bind the same Jira project, each to a disjoint
6
+ * slice of its issues chosen by label (see `IntakeStorage.setSharedBinding`).
7
+ * The slicing happens here, in the query Jira runs, so a Factory only ever
8
+ * fetches the issues its binding owns and no two Factories race to file the
9
+ * same issue.
10
+ */
11
+ /** One Jira project a Factory reads, narrowed to the slice its binding owns. */
12
+ export interface JiraIntakeScope {
13
+ projectId: string;
14
+ /** Labels the binding owns; `null` takes every issue no label binding claims. */
15
+ include: string[] | null;
16
+ /**
17
+ * Labels the issue must not carry: for a label binding, those owned by older
18
+ * label bindings on the project (oldest binding wins an issue both match);
19
+ * for an all-issues binding, those owned by every label binding.
20
+ */
21
+ exclude: string[];
22
+ }
23
+ /** Unfiltered scopes for plain project ids, the shape every caller used before label filters. */
24
+ export declare function unfilteredJiraScopes(projectIds: readonly string[]): JiraIntakeScope[];
25
+ /**
26
+ * Build the intake JQL for `scopes`, optionally narrowed to issues carrying one
27
+ * of `labels`. Returns `null` when `scopes` names no usable project, so callers
28
+ * skip the request instead of reading the whole site. `scopes` omitted reads
29
+ * every project.
30
+ */
31
+ export declare function buildIntakeJql(scopes?: readonly JiraIntakeScope[], labels?: readonly string[]): string | null;
32
+ //# sourceMappingURL=intake-jql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intake-jql.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/intake-jql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,gFAAgF;AAChF,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACzB;;;;OAIG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,iGAAiG;AACjG,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,eAAe,EAAE,CAErF;AAgBD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,eAAe,EAAE,EAAE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CA8B7G"}
@@ -0,0 +1,57 @@
1
+ // src/integrations/jira/intake-jql.ts
2
+ /** Unfiltered scopes for plain project ids, the shape every caller used before label filters. */
3
+ function unfilteredJiraScopes(projectIds) {
4
+ return projectIds.map((projectId) => ({
5
+ projectId,
6
+ include: null,
7
+ exclude: []
8
+ }));
9
+ }
10
+ /** Numeric ids pass bare, keys are quoted, and anything outside a safe charset is dropped. */
11
+ function safeProject(projectId) {
12
+ const id = projectId.trim();
13
+ if (!/^[A-Za-z0-9_]+$/.test(id)) return null;
14
+ return /^\d+$/.test(id) ? id : `"${id}"`;
15
+ }
16
+ /** Quote labels for JQL, stripping the characters that could break out of the string. */
17
+ function safeLabels(labels) {
18
+ return [...new Set(labels.map((label) => label.trim().replace(/["\\]/g, "")).filter(Boolean))].map((label) => `"${label}"`);
19
+ }
20
+ /**
21
+ * Build the intake JQL for `scopes`, optionally narrowed to issues carrying one
22
+ * of `labels`. Returns `null` when `scopes` names no usable project, so callers
23
+ * skip the request instead of reading the whole site. `scopes` omitted reads
24
+ * every project.
25
+ */
26
+ function buildIntakeJql(scopes, labels) {
27
+ const clauses = [];
28
+ if (scopes) {
29
+ const plain = [];
30
+ const filtered = [];
31
+ for (const scope of scopes) {
32
+ const project = safeProject(scope.projectId);
33
+ if (!project) continue;
34
+ const exclude = safeLabels(scope.exclude);
35
+ if (scope.include === null) {
36
+ if (exclude.length === 0) plain.push(project);
37
+ else filtered.push(`(project = ${project} AND (labels IS EMPTY OR labels NOT IN (${exclude.join(", ")})))`);
38
+ continue;
39
+ }
40
+ const include = safeLabels(scope.include);
41
+ if (include.length === 0) continue;
42
+ const older = exclude.length > 0 ? ` AND labels NOT IN (${exclude.join(", ")})` : "";
43
+ filtered.push(`(project = ${project} AND labels IN (${include.join(", ")})${older})`);
44
+ }
45
+ const uniquePlain = [...new Set(plain)];
46
+ const projectClauses = [...uniquePlain.length > 0 ? [`project IN (${uniquePlain.join(", ")})`] : [], ...filtered];
47
+ if (projectClauses.length === 0) return null;
48
+ clauses.push(projectClauses.length === 1 ? projectClauses[0] : `(${projectClauses.join(" OR ")})`);
49
+ }
50
+ clauses.push("statusCategory != Done");
51
+ const narrowed = safeLabels(labels ?? []);
52
+ if (narrowed.length > 0) clauses.push(`labels IN (${narrowed.join(", ")})`);
53
+ return `${clauses.join(" AND ")} ORDER BY updated DESC`;
54
+ }
55
+ export { buildIntakeJql, unfilteredJiraScopes };
56
+
57
+ //# sourceMappingURL=intake-jql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intake-jql.js","names":[],"sources":["../../../src/integrations/jira/intake-jql.ts"],"sourcesContent":["/**\n * The JQL intake reads issues with, shared by the direct and Platform Jira\n * integrations.\n *\n * Several Factory projects may bind the same Jira project, each to a disjoint\n * slice of its issues chosen by label (see `IntakeStorage.setSharedBinding`).\n * The slicing happens here, in the query Jira runs, so a Factory only ever\n * fetches the issues its binding owns and no two Factories race to file the\n * same issue.\n */\n\n/** One Jira project a Factory reads, narrowed to the slice its binding owns. */\nexport interface JiraIntakeScope {\n projectId: string;\n /** Labels the binding owns; `null` takes every issue no label binding claims. */\n include: string[] | null;\n /**\n * Labels the issue must not carry: for a label binding, those owned by older\n * label bindings on the project (oldest binding wins an issue both match);\n * for an all-issues binding, those owned by every label binding.\n */\n exclude: string[];\n}\n\n/** Unfiltered scopes for plain project ids, the shape every caller used before label filters. */\nexport function unfilteredJiraScopes(projectIds: readonly string[]): JiraIntakeScope[] {\n return projectIds.map(projectId => ({ projectId, include: null, exclude: [] }));\n}\n\n/** Numeric ids pass bare, keys are quoted, and anything outside a safe charset is dropped. */\nfunction safeProject(projectId: string): string | null {\n const id = projectId.trim();\n if (!/^[A-Za-z0-9_]+$/.test(id)) return null;\n return /^\\d+$/.test(id) ? id : `\"${id}\"`;\n}\n\n/** Quote labels for JQL, stripping the characters that could break out of the string. */\nfunction safeLabels(labels: readonly string[]): string[] {\n return [...new Set(labels.map(label => label.trim().replace(/[\"\\\\]/g, '')).filter(Boolean))].map(\n label => `\"${label}\"`,\n );\n}\n\n/**\n * Build the intake JQL for `scopes`, optionally narrowed to issues carrying one\n * of `labels`. Returns `null` when `scopes` names no usable project, so callers\n * skip the request instead of reading the whole site. `scopes` omitted reads\n * every project.\n */\nexport function buildIntakeJql(scopes?: readonly JiraIntakeScope[], labels?: readonly string[]): string | null {\n const clauses: string[] = [];\n if (scopes) {\n const plain: string[] = [];\n const filtered: string[] = [];\n for (const scope of scopes) {\n const project = safeProject(scope.projectId);\n if (!project) continue;\n const exclude = safeLabels(scope.exclude);\n if (scope.include === null) {\n if (exclude.length === 0) plain.push(project);\n // `labels NOT IN` drops unlabelled issues, which an all-issues binding must keep.\n else filtered.push(`(project = ${project} AND (labels IS EMPTY OR labels NOT IN (${exclude.join(', ')})))`);\n continue;\n }\n const include = safeLabels(scope.include);\n if (include.length === 0) continue;\n // The issue carries an owned label, so plain `NOT IN` cannot drop an unlabelled one here.\n const older = exclude.length > 0 ? ` AND labels NOT IN (${exclude.join(', ')})` : '';\n filtered.push(`(project = ${project} AND labels IN (${include.join(', ')})${older})`);\n }\n const uniquePlain = [...new Set(plain)];\n const projectClauses = [...(uniquePlain.length > 0 ? [`project IN (${uniquePlain.join(', ')})`] : []), ...filtered];\n if (projectClauses.length === 0) return null;\n clauses.push(projectClauses.length === 1 ? projectClauses[0]! : `(${projectClauses.join(' OR ')})`);\n }\n clauses.push('statusCategory != Done');\n const narrowed = safeLabels(labels ?? []);\n if (narrowed.length > 0) clauses.push(`labels IN (${narrowed.join(', ')})`);\n return `${clauses.join(' AND ')} ORDER BY updated DESC`;\n}\n"],"mappings":";;AAyBA,SAAgB,qBAAqB,YAAkD;CACrF,OAAO,WAAW,KAAI,eAAc;EAAE;EAAW,SAAS;EAAM,SAAS,CAAC;CAAE,EAAE;AAChF;;AAGA,SAAS,YAAY,WAAkC;CACrD,MAAM,KAAK,UAAU,KAAK;CAC1B,IAAI,CAAC,kBAAkB,KAAK,EAAE,GAAG,OAAO;CACxC,O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;CACpG;CACA,QAAQ,KAAK,wBAAwB;CACrC,MAAM,WAAW,WAAW,UAAU,CAAC,CAAC;CACxC,IAAI,SAAS,SAAS,GAAG,QAAQ,KAAK,cAAc,SAAS,KAAK,IAAI,EAAE,EAAE;CAC1E,OAAO,GAAG,QAAQ,KAAK,OAAO,EAAE;AAClC"}
@@ -24,6 +24,7 @@ import type { FactoryProjectsStorage } from '../../storage/domains/projects/base
24
24
  import type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../base.js';
25
25
  import { JiraApiClient } from './api.js';
26
26
  import type { JiraEventRules, JiraRuleOverrides } from './default-rules.js';
27
+ import type { JiraIntakeScope } from './intake-jql.js';
27
28
  /** Deployment-global Jira Cloud credentials. All credential fields are required. */
28
29
  export interface JiraIntegrationConfig {
29
30
  /** Site base URL, e.g. `https://acme.atlassian.net`, used for browser links. */
@@ -81,10 +82,10 @@ export declare class JiraIntegration implements FactoryIntegration {
81
82
  readonly intake: Intake;
82
83
  /**
83
84
  * One page of active issues (status category not Done), most recently
84
- * updated first, optionally filtered to projects and labels. The
85
- * capability cursor is Jira's opaque `nextPageToken` passed through.
85
+ * updated first, optionally narrowed to the given project scopes and labels.
86
+ * The capability cursor is Jira's opaque `nextPageToken` passed through.
86
87
  */
87
- listActiveIssues(cursor?: string, projectIds?: string[], labels?: string[]): Promise<{
88
+ listActiveIssues(cursor?: string, scopes?: JiraIntakeScope[], labels?: string[]): Promise<{
88
89
  issues: Array<IntakeIssue & {
89
90
  sourceId: string;
90
91
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AA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1F;IAED,+EAA+E;IAC/E,IAAI,QAAQ,IAAI,sBAAsB,CAKrC;IAED;;;OAGG;IACH,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED;;;;OAIG;IACG,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqB7D;IAED,oDAAoD;IACpD,WAAW,IAAI,IAAI,CAElB;IAED,0FAA0F;IAC1F,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,QAAQ,CAAC,MAAM,EAAE,MAAM,CASrB;IAiFF;;;;OAIG;IACG,gBAAgB,CACpB,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,eAAe,EAAE,EAC1B,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC;QAAE,MAAM,EAAE,KAAK,CAAC,WAAW,GAAG;YAAE,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAc3F;IA6GD;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,kBAAkB,GAAG,QAAQ,EAAE,CAQ1C;IAED;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,kBAAkB,GAAG,YAAY,EAAE,CAY/C;IAED;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE;QAAE,cAAc,EAAE,cAAc,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAEpF;IAED,sEAAsE;IACtE,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMrC;CACF"}
@@ -2,6 +2,7 @@ import { IssueReconcileWorker } from "../issue-reconcile-worker.js";
2
2
  import { adfToText } from "./adf.js";
3
3
  import { JiraApiClient, JiraApiError } from "./api.js";
4
4
  import { resolveJiraRules } from "./default-rules.js";
5
+ import { buildIntakeJql, unfilteredJiraScopes } from "./intake-jql.js";
5
6
  import { attachJiraRules } from "./rules.js";
6
7
  import { attachJiraIssueReconciler } from "./issue-reconciler.js";
7
8
  import { jiraReconciliationEnabled, jiraReconciliationInterval } from "./reconciliation-config.js";
@@ -130,6 +131,7 @@ var JiraIntegration = class {
130
131
  return this.#baseUrl;
131
132
  }
132
133
  intake = {
134
+ bindingLabelFilters: true,
133
135
  resolveIntakeDispatch: (input) => this.#resolveIntakeDispatch(input),
134
136
  listSources: () => this.#listSources(),
135
137
  listItems: (input) => this.#listItems(input),
@@ -173,7 +175,7 @@ var JiraIntegration = class {
173
175
  items: [],
174
176
  nextCursor: null
175
177
  };
176
- const page = await this.listActiveIssues(cursor, sourceIds);
178
+ const page = await this.listActiveIssues(cursor, unfilteredJiraScopes(sourceIds));
177
179
  return {
178
180
  items: page.issues.map((issue) => ({
179
181
  source: {
@@ -208,7 +210,7 @@ var JiraIntegration = class {
208
210
  };
209
211
  }
210
212
  async #listIssues(input) {
211
- const page = await this.listActiveIssues(input.cursor, input.sourceIds, input.labels);
213
+ const page = await this.listActiveIssues(input.cursor, input.sourceIds ? unfilteredJiraScopes(input.sourceIds) : void 0, input.labels);
212
214
  return {
213
215
  issues: page.issues,
214
216
  nextCursor: page.nextCursor
@@ -216,12 +218,17 @@ var JiraIntegration = class {
216
218
  }
217
219
  /**
218
220
  * One page of active issues (status category not Done), most recently
219
- * updated first, optionally filtered to projects and labels. The
220
- * capability cursor is Jira's opaque `nextPageToken` passed through.
221
+ * updated first, optionally narrowed to the given project scopes and labels.
222
+ * The capability cursor is Jira's opaque `nextPageToken` passed through.
221
223
  */
222
- async listActiveIssues(cursor, projectIds, labels) {
224
+ async listActiveIssues(cursor, scopes, labels) {
225
+ const jql = buildIntakeJql(scopes, labels);
226
+ if (jql === null) return {
227
+ issues: [],
228
+ nextCursor: null
229
+ };
223
230
  const page = await this.api.searchIssues({
224
- jql: buildIntakeJql(projectIds, labels),
231
+ jql,
225
232
  ...cursor ? { nextPageToken: cursor } : {}
226
233
  });
227
234
  return {
@@ -338,6 +345,7 @@ var JiraIntegration = class {
338
345
  jira: this,
339
346
  auth: ctx.auth,
340
347
  intake: ctx.storage.intake,
348
+ workItems: ctx.runtime?.workItems,
341
349
  ingestFactoryIssues: attachJiraRules(this, ctx)
342
350
  });
343
351
  }
@@ -383,21 +391,6 @@ function maskEmail(email) {
383
391
  if (at <= 0) return "***";
384
392
  return `${email[0]}***${email.slice(at)}`;
385
393
  }
386
- /**
387
- * Build the intake JQL. Source ids and labels come from stored org config /
388
- * request input, so both are sanitized before interpolation: numeric project
389
- * ids pass through bare, project keys are restricted to a safe charset, and
390
- * label quotes/backslashes are stripped.
391
- */
392
- function buildIntakeJql(projectIds, labels) {
393
- const clauses = [];
394
- const safeProjects = (projectIds ?? []).map((id) => id.trim()).filter((id) => /^[A-Za-z0-9_]+$/.test(id)).map((id) => /^\d+$/.test(id) ? id : `"${id}"`);
395
- if (safeProjects.length > 0) clauses.push(`project IN (${safeProjects.join(", ")})`);
396
- clauses.push("statusCategory != Done");
397
- const safeLabels = [...new Set((labels ?? []).map((label) => label.trim().replace(/["\\]/g, "")).filter(Boolean))];
398
- if (safeLabels.length > 0) clauses.push(`labels IN (${safeLabels.map((label) => `"${label}"`).join(", ")})`);
399
- return `${clauses.join(" AND ")} ORDER BY updated DESC`;
400
- }
401
394
  /** Whether the issue is already in the requested target state. */
402
395
  function currentStatusMatches(issue, target) {
403
396
  const status = issue.fields.status;
@@ -1 +1 @@
1
- {"version":3,"file":"integration.js","names":[],"sources":["../../../src/integrations/jira/integration.ts"],"sourcesContent":["/**\n * `JiraIntegration` — the self-contained Jira Cloud integration.\n *\n * Implements the system-wide `FactoryIntegration` contract\n * (`../base.ts`): the deploy entry reads the `JIRA_*` env vars ONCE,\n * constructs an instance with explicit credentials, and passes it to\n * `MastraFactory`. Everything Jira-flavored the system does — project/issue\n * reads for Intake and the agent's issue tools — flows through this\n * instance. No other module reads `JIRA_*` env vars.\n *\n * Unlike Linear, credentials are **deployment-global** (Basic auth with\n * `email:apiToken` from the environment): there is no OAuth flow, no state\n * signer, and no per-org connection storage. The `IntegrationConnection`\n * arguments required by the `Intake` contract are accepted but not consulted\n * — the instance's own credentials authenticate every call.\n */\n\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute } from '@mastra/core/server';\nimport type { MastraWorker } from '@mastra/core/worker';\n\nimport type { IntegrationConnection } from '../../capabilities/connection.js';\nimport type {\n CreateIntakeCommentInput,\n CreatedIntakeComment,\n GetIntakeIssueInput,\n Intake,\n IntakeIssue,\n IntakeIssueDetail,\n IntakeItemPage,\n IntakeSource,\n ListIntakeIssuesInput,\n ListIntakeItemsInput,\n ResolveIntakeDispatchInput,\n ResolvedIntakeDispatch,\n UpdateIntakeIssueInput,\n} from '../../capabilities/intake.js';\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';\nimport type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../base.js';\nimport { IssueReconcileWorker } from '../issue-reconcile-worker.js';\nimport { adfToText } from './adf.js';\nimport { buildJiraAgentTools } from './agent-tools.js';\nimport type { JiraComment, JiraIssue, JiraTransition } from './api.js';\nimport { JiraApiClient, JiraApiError } from './api.js';\nimport type { JiraEventRules, JiraRuleOverrides } from './default-rules.js';\nimport { resolveJiraRules } from './default-rules.js';\nimport { attachJiraIssueReconciler } from './issue-reconciler.js';\nimport { jiraReconciliationEnabled, jiraReconciliationInterval } from './reconciliation-config.js';\nimport { buildJiraRoutes } from './routes.js';\nimport { attachJiraRules } from './rules.js';\n\n/** Deployment-global Jira Cloud credentials. All credential fields are required. */\nexport interface JiraIntegrationConfig {\n /** Site base URL, e.g. `https://acme.atlassian.net`, used for browser links. */\n baseUrl: string;\n /** API base URL for scoped tokens. Defaults to `baseUrl`. */\n apiBaseUrl?: string;\n /** Atlassian account email the API token belongs to. */\n email: string;\n /** API token from id.atlassian.com → Security → API tokens. */\n apiToken: string;\n /** Per-event replacements; omitted events retain defaults, null disables. */\n rules?: JiraRuleOverrides;\n}\n\n/** Hard stop for comment pagination so a misbehaving `total` can't loop forever. */\nconst ISSUE_COMMENTS_MAX_PAGES = 20;\n\n/** Hard stop for project pagination so a misbehaving `isLast` can't loop forever. */\nconst PROJECT_SEARCH_MAX_PAGES = 50;\n\n/**\n * The `Intake` contract requires a connection argument, but Jira credentials\n * live on the integration instance — this inert placeholder is accepted and\n * ignored everywhere, and keeps the real API token out of resolved dispatches\n * and agent-tool calls.\n */\nexport const DEPLOYMENT_CONNECTION: IntegrationConnection = { type: 'oauth', accessToken: 'deployment-global' };\n\n/** Jira issue keys look like `ENG-42`. */\nconst ISSUE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]*-\\d+$/;\n\nconst UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nfunction normalizeSiteBaseUrl(baseUrl: string): string {\n let parsed: URL;\n try {\n parsed = new URL(baseUrl);\n } catch {\n throw new Error(`JiraIntegration baseUrl is not an absolute URL: \"${baseUrl}\".`);\n }\n if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {\n throw new Error(`JiraIntegration baseUrl must be an http(s) URL: \"${baseUrl}\".`);\n }\n return baseUrl.replace(/\\/+$/, '');\n}\n\n/**\n * Capability state types (`capabilities/intake.ts`) → Jira status-category\n * keys. `canceled` has no Jira category — it is resolved separately against\n * `done`-category transitions whose status name contains \"cancel\".\n */\nconst STATE_TYPE_TO_CATEGORY: Record<'unstarted' | 'started' | 'completed', string> = {\n unstarted: 'new',\n started: 'indeterminate',\n completed: 'done',\n};\n\n/** Jira status-category keys → capability state types. */\nfunction stateTypeFromCategory(key: string | undefined): string | null {\n switch (key) {\n case 'new':\n return 'unstarted';\n case 'indeterminate':\n return 'started';\n case 'done':\n return 'completed';\n default:\n return null;\n }\n}\n\nexport class JiraIntegration implements FactoryIntegration {\n /** Stable integration identifier (see `../base.ts`). */\n readonly id = 'jira';\n\n readonly #config: JiraIntegrationConfig;\n readonly #baseUrl: string;\n /** Typed REST client bound to the deployment credentials. */\n readonly api: JiraApiClient;\n\n /** Bound once by the factory via `initialize()` before any surface is used. */\n #projects: FactoryProjectsStorage | undefined;\n #auth: RouteAuth | undefined;\n readonly #orgIdByResourceId = new Map<string, string | null>();\n\n readonly #rules: JiraEventRules;\n\n get rules(): JiraEventRules {\n return this.#rules;\n }\n\n constructor(config: JiraIntegrationConfig) {\n this.#rules = resolveJiraRules(config.rules);\n this.#baseUrl = normalizeSiteBaseUrl(config.baseUrl);\n // JiraApiClient validates the credential group and normalizes the API URL.\n this.api = new JiraApiClient({ ...config, baseUrl: config.apiBaseUrl ?? config.baseUrl });\n this.#config = config;\n }\n\n /**\n * Bind the projects domain and the host auth seam. Jira has no per-org\n * connection rows, so the generic storage handle is unused — credentials\n * are deployment-global constructor config.\n */\n initialize({ projects, auth }: { projects: FactoryProjectsStorage; auth: RouteAuth }): void {\n this.#projects = projects;\n this.#auth = auth;\n }\n\n /** Factory projects domain — maps a session's resourceId to its owning org. */\n get projects(): FactoryProjectsStorage {\n if (!this.#projects) {\n throw new Error('JiraIntegration is not initialized — the factory binds storage during prepare().');\n }\n return this.#projects;\n }\n\n /**\n * Whether the host runs with web auth enabled. Intake selections are\n * org-owned, so every Jira surface is inert without a tenant auth seam.\n */\n get authEnabled(): boolean {\n return this.#auth?.enabled() ?? false;\n }\n\n /**\n * Map a session's resourceId (the factory project id) to its owning org.\n * Same caching semantics as the Linear integration: definitive misses are\n * cached, transient database failures are not.\n */\n async resolveOrgId(resourceId: string): Promise<string | null> {\n const cached = this.#orgIdByResourceId.get(resourceId);\n if (cached !== undefined) return cached;\n // Non-UUID resource ids (local/dev resources) would make the uuid column\n // comparison throw — they're definitively \"not a project\", so cache that.\n if (!UUID_PATTERN.test(resourceId)) {\n this.#orgIdByResourceId.set(resourceId, null);\n return null;\n }\n let orgId: string | null;\n try {\n await this.projects.ensureReady();\n const project = await this.projects.getById({ id: resourceId });\n orgId = project?.orgId ?? null;\n } catch {\n // Transient database failure: skip the tools for this request but don't\n // cache the miss, so the next request retries the lookup.\n return null;\n }\n this.#orgIdByResourceId.set(resourceId, orgId);\n return orgId;\n }\n\n /** Test hook: clear the org cache between specs. */\n clearCaches(): void {\n this.#orgIdByResourceId.clear();\n }\n\n /** Normalized site base URL (no trailing slash) — `/browse/<key>` links hang off this. */\n get baseUrl(): string {\n return this.#baseUrl;\n }\n\n readonly intake: Intake = {\n resolveIntakeDispatch: input => this.#resolveIntakeDispatch(input),\n listSources: () => this.#listSources(),\n listItems: input => this.#listItems(input),\n listIssues: input => this.#listIssues(input),\n getIssue: input => this.#getIssue(input),\n createComment: input => this.#createComment(input),\n updateIssue: input => this.#updateIssue(input),\n };\n\n /**\n * Background-dispatch context. Credentials are deployment-global, so the\n * returned connection is a formality the Jira intake methods ignore; the\n * issue key is stored directly as the work item's `externalId` (mirroring\n * Linear, which stores the issue UUID).\n */\n async #resolveIntakeDispatch({ externalSource }: ResolveIntakeDispatchInput): Promise<ResolvedIntakeDispatch | null> {\n if (externalSource.type !== 'issue') return null;\n return {\n // Inert placeholder, never the real token: the Jira intake methods read\n // credentials from the client, and the resolved dispatch travels through\n // generic reconciler/dispatcher code that must stay secret-free.\n connection: DEPLOYMENT_CONNECTION,\n issueId: externalSource.externalId,\n };\n }\n\n /** All the site's projects (Settings intake-source picker), following `isLast` paging. */\n async #listSources(): Promise<IntakeSource[]> {\n const sources: IntakeSource[] = [];\n let startAt = 0;\n for (let pageCount = 0; pageCount < PROJECT_SEARCH_MAX_PAGES; pageCount++) {\n const page = await this.api.listProjects({ startAt });\n for (const project of page.values) {\n sources.push({\n id: project.id,\n name: project.name,\n type: 'project',\n metadata: { key: project.key },\n });\n }\n if (page.isLast || page.values.length === 0) break;\n startAt += page.values.length;\n }\n return sources;\n }\n\n async #listItems({ sourceIds, cursor }: ListIntakeItemsInput): Promise<IntakeItemPage> {\n if (sourceIds.length === 0) return { items: [], nextCursor: null };\n const page = await this.listActiveIssues(cursor, sourceIds);\n return {\n items: page.issues.map(issue => ({\n source: { type: 'issue', externalId: issue.identifier, url: issue.url },\n sourceId: issue.sourceId,\n title: `${issue.identifier}: ${issue.title}`,\n status: issue.state ?? undefined,\n labels: issue.labels,\n assignee: issue.assignee,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n metadata: {\n identifier: issue.identifier,\n issueRef: issue.identifier,\n state: issue.state,\n stateType: issue.stateType,\n priority: issue.priority,\n project: issue.source,\n assignee: issue.assignee,\n assignees: issue.assignees ?? [],\n creator: issue.author,\n author: issue.author,\n labels: issue.labels,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n },\n })),\n nextCursor: page.nextCursor,\n };\n }\n\n async #listIssues(input: ListIntakeIssuesInput): Promise<{ issues: IntakeIssue[]; nextCursor: string | null }> {\n const page = await this.listActiveIssues(input.cursor, input.sourceIds, input.labels);\n return { issues: page.issues, nextCursor: page.nextCursor };\n }\n\n /**\n * One page of active issues (status category not Done), most recently\n * updated first, optionally filtered to projects and labels. The\n * capability cursor is Jira's opaque `nextPageToken` passed through.\n */\n async listActiveIssues(\n cursor?: string,\n projectIds?: string[],\n labels?: string[],\n ): Promise<{ issues: Array<IntakeIssue & { sourceId: string }>; nextCursor: string | null }> {\n const page = await this.api.searchIssues({\n jql: buildIntakeJql(projectIds, labels),\n ...(cursor ? { nextPageToken: cursor } : {}),\n });\n return {\n issues: page.issues.map(issue => ({\n ...this.#toIntakeIssue(issue),\n sourceId: issue.fields.project?.id ?? '',\n })),\n nextCursor: page.nextPageToken ?? null,\n };\n }\n\n async #getIssue({ issueId }: GetIntakeIssueInput): Promise<IntakeIssueDetail | null> {\n let issue: JiraIssue;\n try {\n issue = await this.api.getIssue(issueId);\n } catch (err) {\n if (err instanceof JiraApiError && err.status === 404) return null;\n throw err;\n }\n const { comments, total } = await this.#listAllComments(issue.key);\n return {\n ...this.#toIntakeIssue(issue),\n commentCount: total,\n description: issue.fields.description ? adfToText(issue.fields.description) || null : null,\n comments: comments.map(comment => ({\n author: comment.author?.displayName ?? null,\n body: adfToText(comment.body),\n createdAt: comment.created,\n })),\n };\n }\n\n /** Every comment on the issue, oldest first, bounded by {@link ISSUE_COMMENTS_MAX_PAGES}. */\n async #listAllComments(keyOrId: string): Promise<{ comments: JiraComment[]; total: number }> {\n const comments: JiraComment[] = [];\n let total = 0;\n for (let page = 0; page < ISSUE_COMMENTS_MAX_PAGES; page++) {\n const result = await this.api.listComments(keyOrId, { startAt: comments.length });\n comments.push(...result.comments);\n total = result.total;\n if (result.comments.length === 0 || comments.length >= total) break;\n }\n return { comments, total };\n }\n\n async #createComment({ issueId, body }: CreateIntakeCommentInput): Promise<CreatedIntakeComment | null> {\n // The browse URL needs the issue key; resolve it when the caller passed a\n // numeric id instead.\n let key = issueId;\n if (!ISSUE_KEY_PATTERN.test(issueId)) {\n try {\n key = (await this.api.getIssue(issueId)).key;\n } catch (err) {\n if (err instanceof JiraApiError && err.status === 404) return null;\n throw err;\n }\n }\n let comment;\n try {\n comment = await this.api.createComment(key, body);\n } catch (err) {\n if (err instanceof JiraApiError && err.status === 404) return null;\n throw err;\n }\n return {\n id: comment.id,\n url: `${this.baseUrl}/browse/${key}?focusedCommentId=${comment.id}`,\n };\n }\n\n /**\n * Move an issue to a target state by applying a workflow transition. Jira\n * only exposes transitions that are currently legal, so a policy miss (no\n * transition reaches the target) returns `null` per the `Intake` contract —\n * infrastructure errors (network, auth) still throw.\n */\n async #updateIssue(input: UpdateIntakeIssueInput): Promise<IntakeIssue | null> {\n let issue: JiraIssue;\n try {\n issue = await this.api.getIssue(input.issueId);\n } catch (err) {\n if (err instanceof JiraApiError && err.status === 404) return null;\n throw err;\n }\n if (currentStatusMatches(issue, input.state)) {\n return this.#toIntakeIssue(issue);\n }\n const transitions = await this.api.listTransitions(issue.key);\n const transition = resolveTransition(transitions, input.state);\n if (!transition) return null;\n await this.api.applyTransition(issue.key, transition.id);\n const fresh = await this.api.getIssue(issue.key);\n return this.#toIntakeIssue(fresh);\n }\n\n #toIntakeIssue(issue: JiraIssue): IntakeIssue {\n const { fields } = issue;\n return {\n id: issue.id,\n identifier: issue.key,\n title: fields.summary ?? issue.key,\n url: `${this.baseUrl}/browse/${issue.key}`,\n author: fields.reporter?.displayName ?? null,\n state: fields.status?.name ?? null,\n stateType: stateTypeFromCategory(fields.status?.statusCategory?.key),\n priority: fields.priority?.name ?? null,\n assignee: fields.assignee?.displayName ?? null,\n source: fields.project?.key ?? null,\n sourceId: fields.project?.id ?? null,\n labels: fields.labels ?? [],\n commentCount: null,\n createdAt: fields.created ?? '',\n updatedAt: fields.updated ?? '',\n };\n }\n\n // ── FactoryIntegration surface ───────────────────────────────────────────\n\n /**\n * The integration's HTTP surface: `/web/jira/*` Mastra `apiRoutes` (status,\n * projects + issues for Intake). No OAuth routes — credentials are\n * deployment-global. Handlers operate on this instance.\n */\n routes(ctx: IntegrationContext): ApiRoute[] {\n return buildJiraRoutes({\n jira: this,\n auth: ctx.auth,\n intake: ctx.storage.intake,\n ingestFactoryIssues: attachJiraRules(this, ctx),\n });\n }\n\n /**\n * Background reconciliation, matching the Platform integration: keeps filed\n * Jira cards' metadata fresh and replays close events through the rules\n * ingress. Registered only when reconciliation is enabled.\n */\n workers(ctx: IntegrationContext): MastraWorker[] {\n if (!jiraReconciliationEnabled()) return [];\n const reconcile = attachJiraIssueReconciler(this, ctx);\n if (!reconcile) return [];\n const intervalMs = jiraReconciliationInterval();\n return [\n new IssueReconcileWorker({\n integrationId: this.id,\n reconcile,\n ...(intervalMs ? { intervalMs } : {}),\n }),\n ];\n }\n\n /**\n * Org-scoped agent tools: the read-only issue-detail tool for sessions whose\n * resource is a factory project (Jira credentials are deployment-global,\n * so no per-org connection gates apply). v1 exposes no mutating Jira tools.\n */\n async agentTools(args: { requestContext: RequestContext }): Promise<IntegrationTools> {\n return buildJiraAgentTools({ requestContext: args.requestContext, jira: this });\n }\n\n /** Non-secret config snapshot for system diagnostics/startup logs. */\n diagnostics(): Record<string, unknown> {\n return {\n configured: true,\n site: new URL(this.baseUrl).host,\n email: maskEmail(this.#config.email),\n };\n }\n}\n\n/** `ops@acme.test` → `o***@acme.test` — enough to identify, never the value. */\nfunction maskEmail(email: string): string {\n const at = email.indexOf('@');\n if (at <= 0) return '***';\n return `${email[0]}***${email.slice(at)}`;\n}\n\n/**\n * Build the intake JQL. Source ids and labels come from stored org config /\n * request input, so both are sanitized before interpolation: numeric project\n * ids pass through bare, project keys are restricted to a safe charset, and\n * label quotes/backslashes are stripped.\n */\nfunction buildIntakeJql(projectIds?: string[], labels?: string[]): string {\n const clauses: string[] = [];\n const safeProjects = (projectIds ?? [])\n .map(id => id.trim())\n .filter(id => /^[A-Za-z0-9_]+$/.test(id))\n .map(id => (/^\\d+$/.test(id) ? id : `\"${id}\"`));\n if (safeProjects.length > 0) {\n clauses.push(`project IN (${safeProjects.join(', ')})`);\n }\n clauses.push('statusCategory != Done');\n const safeLabels = [...new Set((labels ?? []).map(label => label.trim().replace(/[\"\\\\]/g, '')).filter(Boolean))];\n if (safeLabels.length > 0) {\n clauses.push(`labels IN (${safeLabels.map(label => `\"${label}\"`).join(', ')})`);\n }\n return `${clauses.join(' AND ')} ORDER BY updated DESC`;\n}\n\n/** Whether the issue is already in the requested target state. */\nfunction currentStatusMatches(issue: JiraIssue, target: UpdateIntakeIssueInput['state']): boolean {\n const status = issue.fields.status;\n if (!status) return false;\n if (target.kind === 'byName') {\n return status.name.toLowerCase() === target.name.toLowerCase();\n }\n if (target.stateType === 'canceled') {\n return status.statusCategory?.key === 'done' && /cancel/i.test(status.name);\n }\n return status.statusCategory?.key === STATE_TYPE_TO_CATEGORY[target.stateType];\n}\n\n/** Resolve the target state against the issue's currently-legal transitions. */\nfunction resolveTransition(\n transitions: JiraTransition[],\n target: UpdateIntakeIssueInput['state'],\n): JiraTransition | null {\n if (target.kind === 'byName') {\n const wanted = target.name.toLowerCase();\n return transitions.find(transition => transition.to?.name.toLowerCase() === wanted) ?? null;\n }\n if (target.stateType === 'canceled') {\n return (\n transitions.find(\n transition => transition.to?.statusCategory?.key === 'done' && /cancel/i.test(transition.to.name),\n ) ?? null\n );\n }\n const category = STATE_TYPE_TO_CATEGORY[target.stateType];\n return transitions.find(transition => transition.to?.statusCategory?.key === category) ?? null;\n}\n"],"mappings":";;;;;;;;;;;AAmEA,MAAM,2BAA2B;;AAGjC,MAAM,2BAA2B;;;;;;;AAQjC,MAAa,wBAA+C;CAAE,MAAM;CAAS,aAAa;AAAoB;;AAG9G,MAAM,oBAAoB;AAE1B,MAAM,eAAe;AAErB,SAAS,qBAAqB,SAAyB;CACrD,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,OAAO;CAC1B,QAAQ;EACN,MAAM,IAAI,MAAM,oDAAoD,QAAQ,GAAG;CACjF;CACA,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,SACtD,MAAM,IAAI,MAAM,oDAAoD,QAAQ,GAAG;CAEjF,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AACnC;;;;;;AAOA,MAAM,yBAAgF;CACpF,WAAW;CACX,SAAS;CACT,WAAW;AACb;;AAGA,SAAS,sBAAsB,KAAwC;CACrE,QAAQ,KAAR;EACE,KAAK,OACH,OAAO;EACT,KAAK,iBACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAEA,IAAa,kBAAb,MAA2D;;CAEzD,KAAc;CAEd;CACA;;CAEA;;CAGA;CACA;CACA,qCAA8B,IAAI,IAA2B;CAE7D;CAEA,IAAI,QAAwB;EAC1B,OAAO,KAAK;CACd;CAEA,YAAY,QAA+B;EACzC,KAAK,SAAS,iBAAiB,OAAO,KAAK;EAC3C,KAAK,WAAW,qBAAqB,OAAO,OAAO;EAEnD,KAAK,MAAM,IAAI,cAAc;GAAE,GAAG;GAAQ,SAAS,OAAO,cAAc,OAAO;EAAQ,CAAC;EACxF,KAAK,UAAU;CACjB;;;;;;CAOA,WAAW,EAAE,UAAU,QAAqE;EAC1F,KAA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;CAC/C,OAAO,YAAY,MAAK,eAAc,WAAW,IAAI,gBAAgB,QAAQ,QAAQ,KAAK;AAC5F"}
1
+ {"version":3,"file":"integration.js","names":[],"sources":["../../../src/integrations/jira/integration.ts"],"sourcesContent":["/**\n * `JiraIntegration` — the self-contained Jira Cloud integration.\n *\n * Implements the system-wide `FactoryIntegration` contract\n * (`../base.ts`): the deploy entry reads the `JIRA_*` env vars ONCE,\n * constructs an instance with explicit credentials, and passes it to\n * `MastraFactory`. Everything Jira-flavored the system does — project/issue\n * reads for Intake and the agent's issue tools — flows through this\n * instance. No other module reads `JIRA_*` env vars.\n *\n * Unlike Linear, credentials are **deployment-global** (Basic auth with\n * `email:apiToken` from the environment): there is no OAuth flow, no state\n * signer, and no per-org connection storage. The `IntegrationConnection`\n * arguments required by the `Intake` contract are accepted but not consulted\n * — the instance's own credentials authenticate every call.\n */\n\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute } from '@mastra/core/server';\nimport type { MastraWorker } from '@mastra/core/worker';\n\nimport type { IntegrationConnection } from '../../capabilities/connection.js';\nimport type {\n CreateIntakeCommentInput,\n CreatedIntakeComment,\n GetIntakeIssueInput,\n Intake,\n IntakeIssue,\n IntakeIssueDetail,\n IntakeItemPage,\n IntakeSource,\n ListIntakeIssuesInput,\n ListIntakeItemsInput,\n ResolveIntakeDispatchInput,\n ResolvedIntakeDispatch,\n UpdateIntakeIssueInput,\n} from '../../capabilities/intake.js';\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';\nimport type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../base.js';\nimport { IssueReconcileWorker } from '../issue-reconcile-worker.js';\nimport { adfToText } from './adf.js';\nimport { buildJiraAgentTools } from './agent-tools.js';\nimport type { JiraComment, JiraIssue, JiraTransition } from './api.js';\nimport { JiraApiClient, JiraApiError } from './api.js';\nimport type { JiraEventRules, JiraRuleOverrides } from './default-rules.js';\nimport { resolveJiraRules } from './default-rules.js';\nimport { buildIntakeJql, unfilteredJiraScopes } from './intake-jql.js';\nimport type { JiraIntakeScope } from './intake-jql.js';\nimport { attachJiraIssueReconciler } from './issue-reconciler.js';\nimport { jiraReconciliationEnabled, jiraReconciliationInterval } from './reconciliation-config.js';\nimport { buildJiraRoutes } from './routes.js';\nimport { attachJiraRules } from './rules.js';\n\n/** Deployment-global Jira Cloud credentials. All credential fields are required. */\nexport interface JiraIntegrationConfig {\n /** Site base URL, e.g. `https://acme.atlassian.net`, used for browser links. */\n baseUrl: string;\n /** API base URL for scoped tokens. Defaults to `baseUrl`. */\n apiBaseUrl?: string;\n /** Atlassian account email the API token belongs to. */\n email: string;\n /** API token from id.atlassian.com → Security → API tokens. */\n apiToken: string;\n /** Per-event replacements; omitted events retain defaults, null disables. */\n rules?: JiraRuleOverrides;\n}\n\n/** Hard stop for comment pagination so a misbehaving `total` can't loop forever. */\nconst ISSUE_COMMENTS_MAX_PAGES = 20;\n\n/** Hard stop for project pagination so a misbehaving `isLast` can't loop forever. */\nconst PROJECT_SEARCH_MAX_PAGES = 50;\n\n/**\n * The `Intake` contract requires a connection argument, but Jira credentials\n * live on the integration instance — this inert placeholder is accepted and\n * ignored everywhere, and keeps the real API token out of resolved dispatches\n * and agent-tool calls.\n */\nexport const DEPLOYMENT_CONNECTION: IntegrationConnection = { type: 'oauth', accessToken: 'deployment-global' };\n\n/** Jira issue keys look like `ENG-42`. */\nconst ISSUE_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_]*-\\d+$/;\n\nconst UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nfunction normalizeSiteBaseUrl(baseUrl: string): string {\n let parsed: URL;\n try {\n parsed = new URL(baseUrl);\n } catch {\n throw new Error(`JiraIntegration baseUrl is not an absolute URL: \"${baseUrl}\".`);\n }\n if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {\n throw new Error(`JiraIntegration baseUrl must be an http(s) URL: \"${baseUrl}\".`);\n }\n return baseUrl.replace(/\\/+$/, '');\n}\n\n/**\n * Capability state types (`capabilities/intake.ts`) → Jira status-category\n * keys. `canceled` has no Jira category — it is resolved separately against\n * `done`-category transitions whose status name contains \"cancel\".\n */\nconst STATE_TYPE_TO_CATEGORY: Record<'unstarted' | 'started' | 'completed', string> = {\n unstarted: 'new',\n started: 'indeterminate',\n completed: 'done',\n};\n\n/** Jira status-category keys → capability state types. */\nfunction stateTypeFromCategory(key: string | undefined): string | null {\n switch (key) {\n case 'new':\n return 'unstarted';\n case 'indeterminate':\n return 'started';\n case 'done':\n return 'completed';\n default:\n return null;\n }\n}\n\nexport class JiraIntegration implements FactoryIntegration {\n /** Stable integration identifier (see `../base.ts`). */\n readonly id = 'jira';\n\n readonly #config: JiraIntegrationConfig;\n readonly #baseUrl: string;\n /** Typed REST client bound to the deployment credentials. */\n readonly api: JiraApiClient;\n\n /** Bound once by the factory via `initialize()` before any surface is used. */\n #projects: FactoryProjectsStorage | undefined;\n #auth: RouteAuth | undefined;\n readonly #orgIdByResourceId = new Map<string, string | null>();\n\n readonly #rules: JiraEventRules;\n\n get rules(): JiraEventRules {\n return this.#rules;\n }\n\n constructor(config: JiraIntegrationConfig) {\n this.#rules = resolveJiraRules(config.rules);\n this.#baseUrl = normalizeSiteBaseUrl(config.baseUrl);\n // JiraApiClient validates the credential group and normalizes the API URL.\n this.api = new JiraApiClient({ ...config, baseUrl: config.apiBaseUrl ?? config.baseUrl });\n this.#config = config;\n }\n\n /**\n * Bind the projects domain and the host auth seam. Jira has no per-org\n * connection rows, so the generic storage handle is unused — credentials\n * are deployment-global constructor config.\n */\n initialize({ projects, auth }: { projects: FactoryProjectsStorage; auth: RouteAuth }): void {\n this.#projects = projects;\n this.#auth = auth;\n }\n\n /** Factory projects domain — maps a session's resourceId to its owning org. */\n get projects(): FactoryProjectsStorage {\n if (!this.#projects) {\n throw new Error('JiraIntegration is not initialized — the factory binds storage during prepare().');\n }\n return this.#projects;\n }\n\n /**\n * Whether the host runs with web auth enabled. Intake selections are\n * org-owned, so every Jira surface is inert without a tenant auth seam.\n */\n get authEnabled(): boolean {\n return this.#auth?.enabled() ?? false;\n }\n\n /**\n * Map a session's resourceId (the factory project id) to its owning org.\n * Same caching semantics as the Linear integration: definitive misses are\n * cached, transient database failures are not.\n */\n async resolveOrgId(resourceId: string): Promise<string | null> {\n const cached = this.#orgIdByResourceId.get(resourceId);\n if (cached !== undefined) return cached;\n // Non-UUID resource ids (local/dev resources) would make the uuid column\n // comparison throw — they're definitively \"not a project\", so cache that.\n if (!UUID_PATTERN.test(resourceId)) {\n this.#orgIdByResourceId.set(resourceId, null);\n return null;\n }\n let orgId: string | null;\n try {\n await this.projects.ensureReady();\n const project = await this.projects.getById({ id: resourceId });\n orgId = project?.orgId ?? null;\n } catch {\n // Transient database failure: skip the tools for this request but don't\n // cache the miss, so the next request retries the lookup.\n return null;\n }\n this.#orgIdByResourceId.set(resourceId, orgId);\n return orgId;\n }\n\n /** Test hook: clear the org cache between specs. */\n clearCaches(): void {\n this.#orgIdByResourceId.clear();\n }\n\n /** Normalized site base URL (no trailing slash) — `/browse/<key>` links hang off this. */\n get baseUrl(): string {\n return this.#baseUrl;\n }\n\n readonly intake: Intake = {\n bindingLabelFilters: true,\n resolveIntakeDispatch: input => this.#resolveIntakeDispatch(input),\n listSources: () => this.#listSources(),\n listItems: input => this.#listItems(input),\n listIssues: input => this.#listIssues(input),\n getIssue: input => this.#getIssue(input),\n createComment: input => this.#createComment(input),\n updateIssue: input => this.#updateIssue(input),\n };\n\n /**\n * Background-dispatch context. Credentials are deployment-global, so the\n * returned connection is a formality the Jira intake methods ignore; the\n * issue key is stored directly as the work item's `externalId` (mirroring\n * Linear, which stores the issue UUID).\n */\n async #resolveIntakeDispatch({ externalSource }: ResolveIntakeDispatchInput): Promise<ResolvedIntakeDispatch | null> {\n if (externalSource.type !== 'issue') return null;\n return {\n // Inert placeholder, never the real token: the Jira intake methods read\n // credentials from the client, and the resolved dispatch travels through\n // generic reconciler/dispatcher code that must stay secret-free.\n connection: DEPLOYMENT_CONNECTION,\n issueId: externalSource.externalId,\n };\n }\n\n /** All the site's projects (Settings intake-source picker), following `isLast` paging. */\n async #listSources(): Promise<IntakeSource[]> {\n const sources: IntakeSource[] = [];\n let startAt = 0;\n for (let pageCount = 0; pageCount < PROJECT_SEARCH_MAX_PAGES; pageCount++) {\n const page = await this.api.listProjects({ startAt });\n for (const project of page.values) {\n sources.push({\n id: project.id,\n name: project.name,\n type: 'project',\n metadata: { key: project.key },\n });\n }\n if (page.isLast || page.values.length === 0) break;\n startAt += page.values.length;\n }\n return sources;\n }\n\n async #listItems({ sourceIds, cursor }: ListIntakeItemsInput): Promise<IntakeItemPage> {\n if (sourceIds.length === 0) return { items: [], nextCursor: null };\n const page = await this.listActiveIssues(cursor, unfilteredJiraScopes(sourceIds));\n return {\n items: page.issues.map(issue => ({\n source: { type: 'issue', externalId: issue.identifier, url: issue.url },\n sourceId: issue.sourceId,\n title: `${issue.identifier}: ${issue.title}`,\n status: issue.state ?? undefined,\n labels: issue.labels,\n assignee: issue.assignee,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n metadata: {\n identifier: issue.identifier,\n issueRef: issue.identifier,\n state: issue.state,\n stateType: issue.stateType,\n priority: issue.priority,\n project: issue.source,\n assignee: issue.assignee,\n assignees: issue.assignees ?? [],\n creator: issue.author,\n author: issue.author,\n labels: issue.labels,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n },\n })),\n nextCursor: page.nextCursor,\n };\n }\n\n async #listIssues(input: ListIntakeIssuesInput): Promise<{ issues: IntakeIssue[]; nextCursor: string | null }> {\n const page = await this.listActiveIssues(\n input.cursor,\n input.sourceIds ? unfilteredJiraScopes(input.sourceIds) : undefined,\n input.labels,\n );\n return { issues: page.issues, nextCursor: page.nextCursor };\n }\n\n /**\n * One page of active issues (status category not Done), most recently\n * updated first, optionally narrowed to the given project scopes and labels.\n * The capability cursor is Jira's opaque `nextPageToken` passed through.\n */\n async listActiveIssues(\n cursor?: string,\n scopes?: JiraIntakeScope[],\n labels?: string[],\n ): Promise<{ issues: Array<IntakeIssue & { sourceId: string }>; nextCursor: string | null }> {\n const jql = buildIntakeJql(scopes, labels);\n if (jql === null) return { issues: [], nextCursor: null };\n const page = await this.api.searchIssues({\n jql,\n ...(cursor ? { nextPageToken: cursor } : {}),\n });\n return {\n issues: page.issues.map(issue => ({\n ...this.#toIntakeIssue(issue),\n sourceId: issue.fields.project?.id ?? '',\n })),\n nextCursor: page.nextPageToken ?? null,\n };\n }\n\n async #getIssue({ issueId }: GetIntakeIssueInput): Promise<IntakeIssueDetail | null> {\n let issue: JiraIssue;\n try {\n issue = await this.api.getIssue(issueId);\n } catch (err) {\n if (err instanceof JiraApiError && err.status === 404) return null;\n throw err;\n }\n const { comments, total } = await this.#listAllComments(issue.key);\n return {\n ...this.#toIntakeIssue(issue),\n commentCount: total,\n description: issue.fields.description ? adfToText(issue.fields.description) || null : null,\n comments: comments.map(comment => ({\n author: comment.author?.displayName ?? null,\n body: adfToText(comment.body),\n createdAt: comment.created,\n })),\n };\n }\n\n /** Every comment on the issue, oldest first, bounded by {@link ISSUE_COMMENTS_MAX_PAGES}. */\n async #listAllComments(keyOrId: string): Promise<{ comments: JiraComment[]; total: number }> {\n const comments: JiraComment[] = [];\n let total = 0;\n for (let page = 0; page < ISSUE_COMMENTS_MAX_PAGES; page++) {\n const result = await this.api.listComments(keyOrId, { startAt: comments.length });\n comments.push(...result.comments);\n total = result.total;\n if (result.comments.length === 0 || comments.length >= total) break;\n }\n return { comments, total };\n }\n\n async #createComment({ issueId, body }: CreateIntakeCommentInput): Promise<CreatedIntakeComment | null> {\n // The browse URL needs the issue key; resolve it when the caller passed a\n // numeric id instead.\n let key = issueId;\n if (!ISSUE_KEY_PATTERN.test(issueId)) {\n try {\n key = (await this.api.getIssue(issueId)).key;\n } catch (err) {\n if (err instanceof JiraApiError && err.status === 404) return null;\n throw err;\n }\n }\n let comment;\n try {\n comment = await this.api.createComment(key, body);\n } catch (err) {\n if (err instanceof JiraApiError && err.status === 404) return null;\n throw err;\n }\n return {\n id: comment.id,\n url: `${this.baseUrl}/browse/${key}?focusedCommentId=${comment.id}`,\n };\n }\n\n /**\n * Move an issue to a target state by applying a workflow transition. Jira\n * only exposes transitions that are currently legal, so a policy miss (no\n * transition reaches the target) returns `null` per the `Intake` contract —\n * infrastructure errors (network, auth) still throw.\n */\n async #updateIssue(input: UpdateIntakeIssueInput): Promise<IntakeIssue | null> {\n let issue: JiraIssue;\n try {\n issue = await this.api.getIssue(input.issueId);\n } catch (err) {\n if (err instanceof JiraApiError && err.status === 404) return null;\n throw err;\n }\n if (currentStatusMatches(issue, input.state)) {\n return this.#toIntakeIssue(issue);\n }\n const transitions = await this.api.listTransitions(issue.key);\n const transition = resolveTransition(transitions, input.state);\n if (!transition) return null;\n await this.api.applyTransition(issue.key, transition.id);\n const fresh = await this.api.getIssue(issue.key);\n return this.#toIntakeIssue(fresh);\n }\n\n #toIntakeIssue(issue: JiraIssue): IntakeIssue {\n const { fields } = issue;\n return {\n id: issue.id,\n identifier: issue.key,\n title: fields.summary ?? issue.key,\n url: `${this.baseUrl}/browse/${issue.key}`,\n author: fields.reporter?.displayName ?? null,\n state: fields.status?.name ?? null,\n stateType: stateTypeFromCategory(fields.status?.statusCategory?.key),\n priority: fields.priority?.name ?? null,\n assignee: fields.assignee?.displayName ?? null,\n source: fields.project?.key ?? null,\n sourceId: fields.project?.id ?? null,\n labels: fields.labels ?? [],\n commentCount: null,\n createdAt: fields.created ?? '',\n updatedAt: fields.updated ?? '',\n };\n }\n\n // ── FactoryIntegration surface ───────────────────────────────────────────\n\n /**\n * The integration's HTTP surface: `/web/jira/*` Mastra `apiRoutes` (status,\n * projects + issues for Intake). No OAuth routes — credentials are\n * deployment-global. Handlers operate on this instance.\n */\n routes(ctx: IntegrationContext): ApiRoute[] {\n return buildJiraRoutes({\n jira: this,\n auth: ctx.auth,\n intake: ctx.storage.intake,\n workItems: ctx.runtime?.workItems,\n ingestFactoryIssues: attachJiraRules(this, ctx),\n });\n }\n\n /**\n * Background reconciliation, matching the Platform integration: keeps filed\n * Jira cards' metadata fresh and replays close events through the rules\n * ingress. Registered only when reconciliation is enabled.\n */\n workers(ctx: IntegrationContext): MastraWorker[] {\n if (!jiraReconciliationEnabled()) return [];\n const reconcile = attachJiraIssueReconciler(this, ctx);\n if (!reconcile) return [];\n const intervalMs = jiraReconciliationInterval();\n return [\n new IssueReconcileWorker({\n integrationId: this.id,\n reconcile,\n ...(intervalMs ? { intervalMs } : {}),\n }),\n ];\n }\n\n /**\n * Org-scoped agent tools: the read-only issue-detail tool for sessions whose\n * resource is a factory project (Jira credentials are deployment-global,\n * so no per-org connection gates apply). v1 exposes no mutating Jira tools.\n */\n async agentTools(args: { requestContext: RequestContext }): Promise<IntegrationTools> {\n return buildJiraAgentTools({ requestContext: args.requestContext, jira: this });\n }\n\n /** Non-secret config snapshot for system diagnostics/startup logs. */\n diagnostics(): Record<string, unknown> {\n return {\n configured: true,\n site: new URL(this.baseUrl).host,\n email: maskEmail(this.#config.email),\n };\n }\n}\n\n/** `ops@acme.test` → `o***@acme.test` — enough to identify, never the value. */\nfunction maskEmail(email: string): string {\n const at = email.indexOf('@');\n if (at <= 0) return '***';\n return `${email[0]}***${email.slice(at)}`;\n}\n\n/** Whether the issue is already in the requested target state. */\nfunction currentStatusMatches(issue: JiraIssue, target: UpdateIntakeIssueInput['state']): boolean {\n const status = issue.fields.status;\n if (!status) return false;\n if (target.kind === 'byName') {\n return status.name.toLowerCase() === target.name.toLowerCase();\n }\n if (target.stateType === 'canceled') {\n return status.statusCategory?.key === 'done' && /cancel/i.test(status.name);\n }\n return status.statusCategory?.key === STATE_TYPE_TO_CATEGORY[target.stateType];\n}\n\n/** Resolve the target state against the issue's currently-legal transitions. */\nfunction resolveTransition(\n transitions: JiraTransition[],\n target: UpdateIntakeIssueInput['state'],\n): JiraTransition | null {\n if (target.kind === 'byName') {\n const wanted = target.name.toLowerCase();\n return transitions.find(transition => transition.to?.name.toLowerCase() === wanted) ?? null;\n }\n if (target.stateType === 'canceled') {\n return (\n transitions.find(\n transition => transition.to?.statusCategory?.key === 'done' && /cancel/i.test(transition.to.name),\n ) ?? null\n );\n }\n const category = STATE_TYPE_TO_CATEGORY[target.stateType];\n return transitions.find(transition => transition.to?.statusCategory?.key === category) ?? null;\n}\n"],"mappings":";;;;;;;;;;;;AAqEA,MAAM,2BAA2B;;AAGjC,MAAM,2BAA2B;;;;;;;AAQjC,MAAa,wBAA+C;CAAE,MAAM;CAAS,aAAa;AAAoB;;AAG9G,MAAM,oBAAoB;AAE1B,MAAM,eAAe;AAErB,SAAS,qBAAqB,SAAyB;CACrD,IAAI;CACJ,IAAI;EACF,SAAS,IAAI,IAAI,OAAO;CAC1B,QAAQ;EACN,MAAM,IAAI,MAAM,oDAAoD,QAAQ,GAAG;CACjF;CACA,IAAI,OAAO,aAAa,YAAY,OAAO,aAAa,SACtD,MAAM,IAAI,MAAM,oDAAoD,QAAQ,GAAG;CAEjF,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AACnC;;;;;;AAOA,MAAM,yBAAgF;CACpF,WAAW;CACX,SAAS;CACT,WAAW;AACb;;AAGA,SAAS,sBAAsB,KAAwC;CACrE,QAAQ,KAAR;EACE,KAAK,OACH,OAAO;EACT,KAAK,iBACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,SACE,OAAO;CACX;AACF;AAEA,IAAa,kBAAb,MAA2D;;CAEzD,KAAc;CAEd;CACA;;CAEA;;CAGA;CACA;CACA,qCAA8B,IAAI,IAA2B;CAE7D;CAEA,IAAI,QAAwB;EAC1B,OAAO,KAAK;CACd;CAEA,YAAY,QAA+B;EACzC,KAAK,SAAS,iBAAiB,OAAO,KAAK;EAC3C,KAAK,WAAW,qBAAqB,OAAO,OAAO;EAEnD,KAAK,MAAM,IAAI,cAAc;GAAE,GAAG;GAA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SAAS,UAAU,OAAuB;CACxC,MAAM,KAAK,MAAM,QAAQ,GAAG;CAC5B,IAAI,MAAM,GAAG,OAAO;CACpB,OAAO,GAAG,MAAM,GAAG,KAAK,MAAM,MAAM,EAAE;AACxC;;AAGA,SAAS,qBAAqB,OAAkB,QAAkD;CAChG,MAAM,SAAS,MAAM,OAAO;CAC5B,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI,OAAO,SAAS,UAClB,OAAO,OAAO,KAAK,YAAY,MAAM,OAAO,KAAK,YAAY;CAE/D,IAAI,OAAO,cAAc,YACvB,OAAO,OAAO,gBAAgB,QAAQ,UAAU,UAAU,KAAK,OAAO,IAAI;CAE5E,OAAO,OAAO,gBAAgB,QAAQ,uBAAuB,OAAO;AACtE;;AAGA,SAAS,kBACP,aACA,QACuB;CACvB,IAAI,OAAO,SAAS,UAAU;EAC5B,MAAM,SAAS,OAAO,KAAK,YAAY;EACvC,OAAO,YAAY,MAAK,eAAc,WAAW,IAAI,KAAK,YAAY,MAAM,MAAM,KAAK;CACzF;CACA,IAAI,OAAO,cAAc,YACvB,OACE,YAAY,MACV,eAAc,WAAW,IAAI,gBAAgB,QAAQ,UAAU,UAAU,KAAK,WAAW,GAAG,IAAI,CAClG,KAAK;CAGT,MAAM,WAAW,uBAAuB,OAAO;CAC/C,OAAO,YAAY,MAAK,eAAc,WAAW,IAAI,gBAAgB,QAAQ,QAAQ,KAAK;AAC5F"}
@@ -15,6 +15,7 @@
15
15
  import type { ApiRoute } from '@mastra/core/server';
16
16
  import type { RouteAuth } from '../../routes/route.js';
17
17
  import type { IntakeStorage } from '../../storage/domains/intake/base.js';
18
+ import type { WorkItemsStorage } from '../../storage/domains/work-items/base.js';
18
19
  import type { JiraIntegration } from './integration.js';
19
20
  import type { JiraRulesIngress } from './rules.js';
20
21
  /**
@@ -45,6 +46,8 @@ export interface MountJiraRoutesOptions {
45
46
  * the same automatic intake Linear has.
46
47
  */
47
48
  ingestFactoryIssues?: (input: JiraRulesIngress) => Promise<unknown>;
49
+ /** Filed cards, so a Factory keeps reading issues it filed after a label filter moves them to another slice. */
50
+ workItems?: Pick<WorkItemsStorage, 'getByClaimKey' | 'listBySource'>;
48
51
  }
49
52
  /**
50
53
  * Build the Jira routes as Mastra `apiRoutes`. When the feature is disabled,
@@ -1 +1 @@
1
- {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAG1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAYnD;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,OAAO,CAAC;IACxB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,2FAA2F;IAC3F,IAAI,EAAE,SAAS,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACrE;AAsFD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,QAAQ,EAAE,CA4N3E"}
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,QAAQ,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