@mastra/factory 0.30.0 → 0.31.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -10
- package/dist/factory.d.ts +12 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +72 -31
- package/dist/factory.js.map +1 -1
- package/dist/integrations/gitlab/api.d.ts +3 -2
- package/dist/integrations/gitlab/api.d.ts.map +1 -1
- package/dist/integrations/gitlab/api.js +12 -9
- package/dist/integrations/gitlab/api.js.map +1 -1
- package/dist/integrations/issue-reconcile-worker.d.ts +5 -0
- package/dist/integrations/issue-reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/issue-reconcile-worker.js +17 -1
- package/dist/integrations/issue-reconcile-worker.js.map +1 -1
- package/dist/integrations/platform/connect/routes.d.ts +22 -13
- package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
- package/dist/integrations/platform/connect/routes.js +63 -64
- package/dist/integrations/platform/connect/routes.js.map +1 -1
- package/dist/integrations/platform/foundation/connect-binding.d.ts +125 -0
- package/dist/integrations/platform/foundation/connect-binding.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/connect-binding.js +252 -0
- package/dist/integrations/platform/foundation/connect-binding.js.map +1 -0
- package/dist/integrations/platform/foundation/connect-event-poller.d.ts +49 -0
- package/dist/integrations/platform/foundation/connect-event-poller.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/connect-event-poller.js +304 -0
- package/dist/integrations/platform/foundation/connect-event-poller.js.map +1 -0
- package/dist/integrations/platform/foundation/connect-events.d.ts +31 -0
- package/dist/integrations/platform/foundation/connect-events.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/connect-events.js +7 -0
- package/dist/integrations/platform/foundation/connect-events.js.map +1 -0
- package/dist/integrations/platform/foundation/index.d.ts +10 -0
- package/dist/integrations/platform/foundation/index.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/index.js +6 -0
- package/dist/integrations/platform/foundation/intake.d.ts +39 -0
- package/dist/integrations/platform/foundation/intake.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/intake.js +45 -0
- package/dist/integrations/platform/foundation/intake.js.map +1 -0
- package/dist/integrations/platform/foundation/integration.d.ts +84 -0
- package/dist/integrations/platform/foundation/integration.d.ts.map +1 -0
- package/dist/integrations/platform/foundation/integration.js +107 -0
- package/dist/integrations/platform/foundation/integration.js.map +1 -0
- package/dist/integrations/platform/github/event-worker.d.ts +2 -2
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +4 -8
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +3 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +131 -70
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/gitlab/connect-events.d.ts +22 -0
- package/dist/integrations/platform/gitlab/connect-events.d.ts.map +1 -0
- package/dist/integrations/platform/gitlab/connect-events.js +49 -0
- package/dist/integrations/platform/gitlab/connect-events.js.map +1 -0
- package/dist/integrations/platform/gitlab/integration.d.ts +24 -15
- package/dist/integrations/platform/gitlab/integration.d.ts.map +1 -1
- package/dist/integrations/platform/gitlab/integration.js +61 -26
- package/dist/integrations/platform/gitlab/integration.js.map +1 -1
- package/dist/integrations/platform/incidentio/intake.d.ts +33 -0
- package/dist/integrations/platform/incidentio/intake.d.ts.map +1 -0
- package/dist/integrations/platform/incidentio/intake.js +271 -0
- package/dist/integrations/platform/incidentio/intake.js.map +1 -0
- package/dist/integrations/platform/incidentio/integration.d.ts +11 -23
- package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -1
- package/dist/integrations/platform/incidentio/integration.js +27 -297
- package/dist/integrations/platform/incidentio/integration.js.map +1 -1
- package/dist/integrations/platform/jira/intake.d.ts +60 -0
- package/dist/integrations/platform/jira/intake.d.ts.map +1 -0
- package/dist/integrations/platform/jira/intake.js +445 -0
- package/dist/integrations/platform/jira/intake.js.map +1 -0
- package/dist/integrations/platform/jira/integration.d.ts +13 -37
- package/dist/integrations/platform/jira/integration.d.ts.map +1 -1
- package/dist/integrations/platform/jira/integration.js +29 -468
- package/dist/integrations/platform/jira/integration.js.map +1 -1
- package/dist/integrations/platform/linear/event-worker.d.ts +2 -2
- package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/linear/event-worker.js +5 -9
- package/dist/integrations/platform/linear/event-worker.js.map +1 -1
- package/dist/integrations/platform/linear/integration.d.ts +3 -1
- package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
- package/dist/integrations/platform/linear/integration.js +9 -9
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/dist/integrations/platform/logging.d.ts +6 -0
- package/dist/integrations/platform/logging.d.ts.map +1 -0
- package/dist/integrations/platform/logging.js +25 -0
- package/dist/integrations/platform/logging.js.map +1 -0
- package/dist/integrations/platform/platform-connect.d.ts +38 -0
- package/dist/integrations/platform/platform-connect.d.ts.map +1 -0
- package/dist/integrations/platform/platform-connect.js +109 -0
- package/dist/integrations/platform/platform-connect.js.map +1 -0
- package/dist/integrations/platform/vanta/integration.d.ts +12 -18
- package/dist/integrations/platform/vanta/integration.d.ts.map +1 -1
- package/dist/integrations/platform/vanta/integration.js +38 -38
- package/dist/integrations/platform/vanta/integration.js.map +1 -1
- package/dist/memory-embedder.d.ts +11 -0
- package/dist/memory-embedder.d.ts.map +1 -0
- package/dist/memory-embedder.js +19 -0
- package/dist/memory-embedder.js.map +1 -0
- package/dist/metrics/config.d.ts +1 -1
- package/dist/metrics/config.d.ts.map +1 -1
- package/dist/metrics/config.js +1 -0
- package/dist/metrics/config.js.map +1 -1
- package/dist/metrics/index.js +2 -2
- package/dist/metrics/index.js.map +1 -1
- package/dist/metrics/sandbox.d.ts +3 -3
- package/dist/metrics/sandbox.js +13 -13
- package/dist/metrics/sandbox.js.map +1 -1
- package/dist/metrics/session.d.ts +28 -0
- package/dist/metrics/session.d.ts.map +1 -0
- package/dist/metrics/session.js +76 -0
- package/dist/metrics/session.js.map +1 -0
- package/dist/routes/source-control-sessions.d.ts +5 -0
- package/dist/routes/source-control-sessions.d.ts.map +1 -1
- package/dist/routes/source-control-sessions.js +65 -7
- package/dist/routes/source-control-sessions.js.map +1 -1
- package/dist/routes/surface.d.ts +5 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +1 -0
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts +29 -1
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +156 -23
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/public-failure-reason.js +1 -1
- package/dist/rules/public-failure-reason.js.map +1 -1
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +33 -9
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +2 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +4 -2
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/work-item-branch.d.ts +7 -1
- package/dist/work-item-branch.d.ts.map +1 -1
- package/dist/work-item-branch.js +9 -1
- package/dist/work-item-branch.js.map +1 -1
- package/dist/work-items/card-facts.d.ts.map +1 -1
- package/dist/work-items/card-facts.js +2 -2
- package/dist/work-items/card-facts.js.map +1 -1
- package/package.json +8 -8
- package/dist/integrations/platform/api-client.d.ts +0 -34
- package/dist/integrations/platform/api-client.d.ts.map +0 -1
- package/dist/integrations/platform/api-client.js +0 -186
- package/dist/integrations/platform/api-client.js.map +0 -1
- package/dist/integrations/platform/gitlab/event-worker.d.ts +0 -64
- package/dist/integrations/platform/gitlab/event-worker.d.ts.map +0 -1
- package/dist/integrations/platform/gitlab/event-worker.js +0 -304
- package/dist/integrations/platform/gitlab/event-worker.js.map +0 -1
|
@@ -2,7 +2,7 @@ import type { ExternalWorkItemSource } from './storage/domains/work-items/base.j
|
|
|
2
2
|
/**
|
|
3
3
|
* Where a card came from, in the vocabulary branch naming reads. Server rows
|
|
4
4
|
* map their `externalSource` into this with {@link workItemBranchSource}; the
|
|
5
|
-
* board's
|
|
5
|
+
* board reads a card's source with {@link workItemBoardSource}.
|
|
6
6
|
*/
|
|
7
7
|
export type WorkItemBranchSource = 'github-issue' | 'github-pr' | 'gitlab-issue' | 'gitlab-pr' | 'linear-issue' | 'jira-issue' | 'incidentio-follow-up' | 'github-dependabot-alert' | 'vanta-vulnerability' | 'detail-finding' | 'slack-thread' | 'manual';
|
|
8
8
|
export interface WorkItemBranchInput {
|
|
@@ -12,6 +12,12 @@ export interface WorkItemBranchInput {
|
|
|
12
12
|
}
|
|
13
13
|
/** Map a stored item's provenance onto the source vocabulary branch naming reads. */
|
|
14
14
|
export declare function workItemBranchSource(externalSource: ExternalWorkItemSource | null | undefined): WorkItemBranchSource;
|
|
15
|
+
/**
|
|
16
|
+
* The source a board shows a card under and filters it by. The board's source filter and the
|
|
17
|
+
* board UI both read it from here, so a card can't show one source and be filtered as another.
|
|
18
|
+
* Branch naming reads a Slack thread as a plain work item; on the board it is its own source.
|
|
19
|
+
*/
|
|
20
|
+
export declare function workItemBoardSource(externalSource: ExternalWorkItemSource | null | undefined): WorkItemBranchSource;
|
|
15
21
|
/** The provider number a GitHub card carries — the `#12` its runs and thread titles name it by. */
|
|
16
22
|
export declare function workItemNumber(item: Pick<WorkItemBranchInput, 'source' | 'metadata'>): number | undefined;
|
|
17
23
|
/** How a card names its thread: a Linear title already opens with its identifier, a GitHub card gets its number here. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-item-branch.d.ts","sourceRoot":"","sources":["../src/work-item-branch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAEnF;;;;GAIG;AACH,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,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,UAAU,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACzE,MAAM,CAKR;AAgBD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CA+BhE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAM9G;AAED,+FAA+F;AAC/F,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG7E;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI9E;AAED,gFAAgF;AAChF,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI/E;AAED,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAC1C,eAAO,MAAM,0BAA0B,kBAAkC,CAAC;AAE1E,eAAO,MAAM,2BAA2B,WAAW,CAAC;AAEpD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,uFAAuF;AACvF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAUvD"}
|
package/dist/work-item-branch.js
CHANGED
|
@@ -12,6 +12,14 @@ function workItemBranchSource(externalSource) {
|
|
|
12
12
|
if (externalSource.type === "dependabot-alert") return "github-dependabot-alert";
|
|
13
13
|
return externalSource.type === "pull-request" ? "github-pr" : "github-issue";
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The source a board shows a card under and filters it by. The board's source filter and the
|
|
17
|
+
* board UI both read it from here, so a card can't show one source and be filtered as another.
|
|
18
|
+
* Branch naming reads a Slack thread as a plain work item; on the board it is its own source.
|
|
19
|
+
*/
|
|
20
|
+
function workItemBoardSource(externalSource) {
|
|
21
|
+
return externalSource?.integrationId === "slack" ? "slack-thread" : workItemBranchSource(externalSource);
|
|
22
|
+
}
|
|
15
23
|
function branchNumber(metadata, key) {
|
|
16
24
|
const value = metadata[key] ?? metadata.number;
|
|
17
25
|
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
|
|
@@ -113,6 +121,6 @@ function isPersonSessionBranch(branch) {
|
|
|
113
121
|
function isSafeBranchName(value) {
|
|
114
122
|
return /^[A-Za-z0-9][A-Za-z0-9._/@+-]*$/.test(value) && !value.includes("..") && !value.includes("//") && !value.includes("@{") && !value.endsWith(".") && !value.endsWith("/") && !value.endsWith(".lock");
|
|
115
123
|
}
|
|
116
|
-
export { SLACK_SESSION_BRANCH_PREFIX, USER_BRANCH_PREFIX, USER_SESSION_BRANCH_PREFIX, isPersonSessionBranch, isSafeBranchName, legacyGithubWorkItemBranch, mergeRequestNumberFromBranch, pullRequestBranch, pullRequestNumberFromBranch, workItemBranch, workItemBranchSource, workItemNumber, workItemThreadTitle };
|
|
124
|
+
export { SLACK_SESSION_BRANCH_PREFIX, USER_BRANCH_PREFIX, USER_SESSION_BRANCH_PREFIX, isPersonSessionBranch, isSafeBranchName, legacyGithubWorkItemBranch, mergeRequestNumberFromBranch, pullRequestBranch, pullRequestNumberFromBranch, workItemBoardSource, workItemBranch, workItemBranchSource, workItemNumber, workItemThreadTitle };
|
|
117
125
|
|
|
118
126
|
//# sourceMappingURL=work-item-branch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"work-item-branch.js","names":[],"sources":["../src/work-item-branch.ts"],"sourcesContent":["import type { ExternalWorkItemSource } from './storage/domains/work-items/base.js';\n\n/**\n * Where a card came from, in the vocabulary branch naming reads. Server rows\n * map their `externalSource` into this with {@link workItemBranchSource}; the\n * board's own `WorkItem['source']` is already this union.\n */\nexport type WorkItemBranchSource =\n | 'github-issue'\n | 'github-pr'\n | 'gitlab-issue'\n | 'gitlab-pr'\n | 'linear-issue'\n | 'jira-issue'\n | 'incidentio-follow-up'\n | 'github-dependabot-alert'\n | 'vanta-vulnerability'\n | 'detail-finding'\n | 'slack-thread'\n | 'manual';\n\nexport interface WorkItemBranchInput {\n id: string;\n source: WorkItemBranchSource;\n metadata?: Record<string, unknown> | null;\n}\n\n/** Map a stored item's provenance onto the source vocabulary branch naming reads. */\nexport function workItemBranchSource(externalSource: ExternalWorkItemSource | null | undefined): WorkItemBranchSource {\n if (!externalSource) return 'manual';\n if (externalSource.integrationId === 'linear') return 'linear-issue';\n if (externalSource.integrationId === 'gitlab') {\n return externalSource.type === 'pull-request' ? 'gitlab-pr' : 'gitlab-issue';\n }\n if (externalSource.integrationId === 'jira') return 'jira-issue';\n if (externalSource.integrationId === 'incidentio') return 'incidentio-follow-up';\n // Only GitHub, GitLab, Linear, Jira, and incident.io carry provider identities; anything\n // else (a Slack thread, say) is a plain work item rather than a mislabeled GitHub issue.\n if (externalSource.integrationId === 'vanta') return 'vanta-vulnerability';\n if (externalSource.integrationId === 'detail') return 'detail-finding';\n if (externalSource.integrationId !== 'github') return 'manual';\n if (externalSource.type === 'dependabot-alert') return 'github-dependabot-alert';\n return externalSource.type === 'pull-request' ? 'github-pr' : 'github-issue';\n}\n\nfunction branchNumber(metadata: Record<string, unknown>, key: string): number | undefined {\n const value = metadata[key] ?? metadata.number;\n return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined;\n}\n\n/** The provider number a GitHub card carries — the `#12` its runs and thread titles name it by. */\nexport function workItemNumber(item: Pick<WorkItemBranchInput, 'source' | 'metadata'>): number | undefined {\n const metadata = item.metadata ?? {};\n if (item.source === 'github-issue') return branchNumber(metadata, 'githubIssueNumber');\n if (item.source === 'github-pr') return branchNumber(metadata, 'githubPullRequestNumber');\n if (item.source === 'gitlab-issue') return branchNumber(metadata, 'gitlabIssueIid');\n if (item.source === 'gitlab-pr') return branchNumber(metadata, 'gitlabMergeRequestIid');\n return undefined;\n}\n\n/** How a card names its thread: a Linear title already opens with its identifier, a GitHub card gets its number here. */\nexport function workItemThreadTitle(\n item: Pick<WorkItemBranchInput, 'source' | 'metadata'> & { title: string },\n): string {\n const number = workItemNumber(item);\n if (number === undefined) return item.title;\n const kind = item.source === 'github-pr' ? 'PR' : item.source === 'gitlab-pr' ? 'MR' : 'Issue';\n return `${kind} #${number}: ${item.title}`;\n}\n\n/**\n * The last twelve alphanumerics of a work item id: the per-item suffix that keeps\n * provider numbers from colliding across the repositories of one factory. Issue\n * #13 exists in every repository, and a factory's sessions are unique per\n * user and branch across all of its repositories, so a branch named by the\n * number alone can only be held once per factory.\n */\nfunction itemSuffix(id: string): string {\n return id\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '')\n .slice(-12);\n}\n\n/**\n * The git branch an item's runs and sessions share, one grammar for both sides\n * of the wire: the dispatcher names autonomous run branches with it and the\n * board opens card sessions on it, so both converge on one checkout per item.\n * Provider numbers are only unique within a repository, so GitHub and GitLab\n * branches carry the item suffix as well. Cards without a provider identity\n * (manual, Slack) and cards whose metadata lost their identifier fall back to\n * the id-derived branch.\n */\nexport function workItemBranch(item: WorkItemBranchInput): string {\n const metadata = item.metadata ?? {};\n const providerNumber = workItemNumber(item);\n if (providerNumber !== undefined && (item.source === 'github-issue' || item.source === 'github-pr')) {\n const suffix = itemSuffix(item.id);\n const kind = item.source === 'github-issue' ? 'issue' : 'pr';\n return suffix ? `factory/${kind}-${providerNumber}-${suffix}` : `factory/${kind}-${providerNumber}`;\n }\n if (\n (item.source === 'linear-issue' || item.source === 'jira-issue' || item.source === 'incidentio-follow-up') &&\n typeof metadata.identifier === 'string'\n ) {\n const identifier = metadata.identifier.trim();\n if (identifier) {\n const provider = item.source === 'linear-issue' ? 'linear' : item.source === 'jira-issue' ? 'jira' : 'incidentio';\n return `factory/${provider}-${identifier.toLowerCase()}`;\n }\n }\n if (item.source === 'gitlab-pr' && providerNumber !== undefined) {\n const uniqueSuffix = itemSuffix(item.id);\n if (uniqueSuffix) return `factory/gitlab-mr-${providerNumber}-${uniqueSuffix}`;\n }\n if (item.source === 'gitlab-issue' && typeof metadata.identifier === 'string') {\n const identifier = metadata.identifier\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, '-');\n const uniqueSuffix = itemSuffix(item.id);\n if (identifier && uniqueSuffix) return `factory/gitlab-${identifier.slice(0, 60)}-${uniqueSuffix}`;\n }\n return `factory/item-${item.id}`;\n}\n\n/**\n * The branch a card's pull or merge request is reviewed on. A PR's own card gets\n * the same name {@link workItemBranch} gives it; an issue card reviewing a PR\n * attached to it gets a branch apart from its builder's issue branch, so the\n * reviewer and the builder never share a checkout.\n */\nexport function pullRequestBranch(input: { id: string; provider: 'github' | 'gitlab'; number: number }): string {\n const suffix = itemSuffix(input.id);\n if (input.provider === 'gitlab') {\n return suffix ? `factory/gitlab-mr-${input.number}-${suffix}` : `factory/item-${input.id}-mr-${input.number}`;\n }\n return suffix ? `factory/pr-${input.number}-${suffix}` : `factory/pr-${input.number}`;\n}\n\n/** The pre-suffix GitHub branch, for reusing sessions opened before card names were unique. */\nexport function legacyGithubWorkItemBranch(branch: string): string | undefined {\n const match = /^(factory\\/(?:issue|pr)-[1-9]\\d*)-[a-z0-9]{1,12}$/.exec(branch);\n return match?.[1];\n}\n\n/**\n * The pull request a `factory/pr-<number>-<item suffix>` branch was named after, the\n * inverse of {@link workItemBranch}. Branches from before the suffix (`factory/pr-<number>`)\n * still parse so existing checkouts can resolve their PR.\n */\nexport function pullRequestNumberFromBranch(branch: string): number | undefined {\n const match = /^factory\\/pr-([1-9]\\d*)(?:-[a-z0-9]{1,12})?$/.exec(branch);\n const number = match ? Number(match[1]) : undefined;\n return number !== undefined && Number.isSafeInteger(number) ? number : undefined;\n}\n\n/** The GitLab MR IID encoded in Factory's collision-resistant review branch. */\nexport function mergeRequestNumberFromBranch(branch: string): number | undefined {\n const match = /^factory\\/gitlab-mr-([1-9]\\d*)-[a-z0-9]{1,12}$/.exec(branch);\n const number = match ? Number(match[1]) : undefined;\n return number !== undefined && Number.isSafeInteger(number) ? number : undefined;\n}\n\nexport const USER_BRANCH_PREFIX = 'user/';\nexport const USER_SESSION_BRANCH_PREFIX = `${USER_BRANCH_PREFIX}session-`;\n// Slack thread sessions live on `slack/<thread>` branches (integrations/slack/slack.ts threadBranch).\nexport const SLACK_SESSION_BRANCH_PREFIX = 'slack/';\n\nexport function isPersonSessionBranch(branch: string): boolean {\n return branch.startsWith(USER_BRANCH_PREFIX) || branch.startsWith(SLACK_SESSION_BRANCH_PREFIX);\n}\n\n/** Whether a provider-reported branch name is safe to show an agent or pass to git. */\nexport function isSafeBranchName(value: string): boolean {\n return (\n /^[A-Za-z0-9][A-Za-z0-9._/@+-]*$/.test(value) &&\n !value.includes('..') &&\n !value.includes('//') &&\n !value.includes('@{') &&\n !value.endsWith('.') &&\n !value.endsWith('/') &&\n !value.endsWith('.lock')\n );\n}\n"],"mappings":";;AA4BA,SAAgB,qBAAqB,gBAAiF;CACpH,IAAI,CAAC,gBAAgB,OAAO;CAC5B,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,kBAAkB,UACnC,OAAO,eAAe,SAAS,iBAAiB,cAAc;CAEhE,IAAI,eAAe,kBAAkB,QAAQ,OAAO;CACpD,IAAI,eAAe,kBAAkB,cAAc,OAAO;CAG1D,IAAI,eAAe,kBAAkB,SAAS,OAAO;CACrD,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,SAAS,oBAAoB,OAAO;CACvD,OAAO,eAAe,SAAS,iBAAiB,cAAc;AAChE;AAEA,SAAS,aAAa,UAAmC,KAAiC;CACxF,MAAM,QAAQ,SAAS,QAAQ,SAAS;CACxC,OAAO,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK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MAAa,8BAA8B;AAE3C,SAAgB,sBAAsB,QAAyB;CAC7D,OAAO,OAAO,WAAA,OAA6B,KAAK,OAAO,WAAA,QAAsC;AAC/F;;AAGA,SAAgB,iBAAiB,OAAwB;CACvD,OACE,kCAAkC,KAAK,KAAK,KAC5C,CAAC,MAAM,SAAS,IAAI,KACpB,CAAC,MAAM,SAAS,IAAI,KACpB,CAAC,MAAM,SAAS,IAAI,KACpB,CAAC,MAAM,SAAS,GAAG,KACnB,CAAC,MAAM,SAAS,GAAG,KACnB,CAAC,MAAM,SAAS,OAAO;AAE3B"}
|
|
1
|
+
{"version":3,"file":"work-item-branch.js","names":[],"sources":["../src/work-item-branch.ts"],"sourcesContent":["import type { ExternalWorkItemSource } from './storage/domains/work-items/base.js';\n\n/**\n * Where a card came from, in the vocabulary branch naming reads. Server rows\n * map their `externalSource` into this with {@link workItemBranchSource}; the\n * board reads a card's source with {@link workItemBoardSource}.\n */\nexport type WorkItemBranchSource =\n | 'github-issue'\n | 'github-pr'\n | 'gitlab-issue'\n | 'gitlab-pr'\n | 'linear-issue'\n | 'jira-issue'\n | 'incidentio-follow-up'\n | 'github-dependabot-alert'\n | 'vanta-vulnerability'\n | 'detail-finding'\n | 'slack-thread'\n | 'manual';\n\nexport interface WorkItemBranchInput {\n id: string;\n source: WorkItemBranchSource;\n metadata?: Record<string, unknown> | null;\n}\n\n/** Map a stored item's provenance onto the source vocabulary branch naming reads. */\nexport function workItemBranchSource(externalSource: ExternalWorkItemSource | null | undefined): WorkItemBranchSource {\n if (!externalSource) return 'manual';\n if (externalSource.integrationId === 'linear') return 'linear-issue';\n if (externalSource.integrationId === 'gitlab') {\n return externalSource.type === 'pull-request' ? 'gitlab-pr' : 'gitlab-issue';\n }\n if (externalSource.integrationId === 'jira') return 'jira-issue';\n if (externalSource.integrationId === 'incidentio') return 'incidentio-follow-up';\n // Only GitHub, GitLab, Linear, Jira, and incident.io carry provider identities; anything\n // else (a Slack thread, say) is a plain work item rather than a mislabeled GitHub issue.\n if (externalSource.integrationId === 'vanta') return 'vanta-vulnerability';\n if (externalSource.integrationId === 'detail') return 'detail-finding';\n if (externalSource.integrationId !== 'github') return 'manual';\n if (externalSource.type === 'dependabot-alert') return 'github-dependabot-alert';\n return externalSource.type === 'pull-request' ? 'github-pr' : 'github-issue';\n}\n\n/**\n * The source a board shows a card under and filters it by. The board's source filter and the\n * board UI both read it from here, so a card can't show one source and be filtered as another.\n * Branch naming reads a Slack thread as a plain work item; on the board it is its own source.\n */\nexport function workItemBoardSource(externalSource: ExternalWorkItemSource | null | undefined): WorkItemBranchSource {\n return externalSource?.integrationId === 'slack' ? 'slack-thread' : workItemBranchSource(externalSource);\n}\n\nfunction branchNumber(metadata: Record<string, unknown>, key: string): number | undefined {\n const value = metadata[key] ?? metadata.number;\n return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined;\n}\n\n/** The provider number a GitHub card carries — the `#12` its runs and thread titles name it by. */\nexport function workItemNumber(item: Pick<WorkItemBranchInput, 'source' | 'metadata'>): number | undefined {\n const metadata = item.metadata ?? {};\n if (item.source === 'github-issue') return branchNumber(metadata, 'githubIssueNumber');\n if (item.source === 'github-pr') return branchNumber(metadata, 'githubPullRequestNumber');\n if (item.source === 'gitlab-issue') return branchNumber(metadata, 'gitlabIssueIid');\n if (item.source === 'gitlab-pr') return branchNumber(metadata, 'gitlabMergeRequestIid');\n return undefined;\n}\n\n/** How a card names its thread: a Linear title already opens with its identifier, a GitHub card gets its number here. */\nexport function workItemThreadTitle(\n item: Pick<WorkItemBranchInput, 'source' | 'metadata'> & { title: string },\n): string {\n const number = workItemNumber(item);\n if (number === undefined) return item.title;\n const kind = item.source === 'github-pr' ? 'PR' : item.source === 'gitlab-pr' ? 'MR' : 'Issue';\n return `${kind} #${number}: ${item.title}`;\n}\n\n/**\n * The last twelve alphanumerics of a work item id: the per-item suffix that keeps\n * provider numbers from colliding across the repositories of one factory. Issue\n * #13 exists in every repository, and a factory's sessions are unique per\n * user and branch across all of its repositories, so a branch named by the\n * number alone can only be held once per factory.\n */\nfunction itemSuffix(id: string): string {\n return id\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, '')\n .slice(-12);\n}\n\n/**\n * The git branch an item's runs and sessions share, one grammar for both sides\n * of the wire: the dispatcher names autonomous run branches with it and the\n * board opens card sessions on it, so both converge on one checkout per item.\n * Provider numbers are only unique within a repository, so GitHub and GitLab\n * branches carry the item suffix as well. Cards without a provider identity\n * (manual, Slack) and cards whose metadata lost their identifier fall back to\n * the id-derived branch.\n */\nexport function workItemBranch(item: WorkItemBranchInput): string {\n const metadata = item.metadata ?? {};\n const providerNumber = workItemNumber(item);\n if (providerNumber !== undefined && (item.source === 'github-issue' || item.source === 'github-pr')) {\n const suffix = itemSuffix(item.id);\n const kind = item.source === 'github-issue' ? 'issue' : 'pr';\n return suffix ? `factory/${kind}-${providerNumber}-${suffix}` : `factory/${kind}-${providerNumber}`;\n }\n if (\n (item.source === 'linear-issue' || item.source === 'jira-issue' || item.source === 'incidentio-follow-up') &&\n typeof metadata.identifier === 'string'\n ) {\n const identifier = metadata.identifier.trim();\n if (identifier) {\n const provider = item.source === 'linear-issue' ? 'linear' : item.source === 'jira-issue' ? 'jira' : 'incidentio';\n return `factory/${provider}-${identifier.toLowerCase()}`;\n }\n }\n if (item.source === 'gitlab-pr' && providerNumber !== undefined) {\n const uniqueSuffix = itemSuffix(item.id);\n if (uniqueSuffix) return `factory/gitlab-mr-${providerNumber}-${uniqueSuffix}`;\n }\n if (item.source === 'gitlab-issue' && typeof metadata.identifier === 'string') {\n const identifier = metadata.identifier\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9._-]+/g, '-');\n const uniqueSuffix = itemSuffix(item.id);\n if (identifier && uniqueSuffix) return `factory/gitlab-${identifier.slice(0, 60)}-${uniqueSuffix}`;\n }\n return `factory/item-${item.id}`;\n}\n\n/**\n * The branch a card's pull or merge request is reviewed on. A PR's own card gets\n * the same name {@link workItemBranch} gives it; an issue card reviewing a PR\n * attached to it gets a branch apart from its builder's issue branch, so the\n * reviewer and the builder never share a checkout.\n */\nexport function pullRequestBranch(input: { id: string; provider: 'github' | 'gitlab'; number: number }): string {\n const suffix = itemSuffix(input.id);\n if (input.provider === 'gitlab') {\n return suffix ? `factory/gitlab-mr-${input.number}-${suffix}` : `factory/item-${input.id}-mr-${input.number}`;\n }\n return suffix ? `factory/pr-${input.number}-${suffix}` : `factory/pr-${input.number}`;\n}\n\n/** The pre-suffix GitHub branch, for reusing sessions opened before card names were unique. */\nexport function legacyGithubWorkItemBranch(branch: string): string | undefined {\n const match = /^(factory\\/(?:issue|pr)-[1-9]\\d*)-[a-z0-9]{1,12}$/.exec(branch);\n return match?.[1];\n}\n\n/**\n * The pull request a `factory/pr-<number>-<item suffix>` branch was named after, the\n * inverse of {@link workItemBranch}. Branches from before the suffix (`factory/pr-<number>`)\n * still parse so existing checkouts can resolve their PR.\n */\nexport function pullRequestNumberFromBranch(branch: string): number | undefined {\n const match = /^factory\\/pr-([1-9]\\d*)(?:-[a-z0-9]{1,12})?$/.exec(branch);\n const number = match ? Number(match[1]) : undefined;\n return number !== undefined && Number.isSafeInteger(number) ? number : undefined;\n}\n\n/** The GitLab MR IID encoded in Factory's collision-resistant review branch. */\nexport function mergeRequestNumberFromBranch(branch: string): number | undefined {\n const match = /^factory\\/gitlab-mr-([1-9]\\d*)-[a-z0-9]{1,12}$/.exec(branch);\n const number = match ? Number(match[1]) : undefined;\n return number !== undefined && Number.isSafeInteger(number) ? number : undefined;\n}\n\nexport const USER_BRANCH_PREFIX = 'user/';\nexport const USER_SESSION_BRANCH_PREFIX = `${USER_BRANCH_PREFIX}session-`;\n// Slack thread sessions live on `slack/<thread>` branches (integrations/slack/slack.ts threadBranch).\nexport const SLACK_SESSION_BRANCH_PREFIX = 'slack/';\n\nexport function isPersonSessionBranch(branch: string): boolean {\n return branch.startsWith(USER_BRANCH_PREFIX) || branch.startsWith(SLACK_SESSION_BRANCH_PREFIX);\n}\n\n/** Whether a provider-reported branch name is safe to show an agent or pass to git. */\nexport function isSafeBranchName(value: string): boolean {\n return (\n /^[A-Za-z0-9][A-Za-z0-9._/@+-]*$/.test(value) &&\n !value.includes('..') &&\n !value.includes('//') &&\n !value.includes('@{') &&\n !value.endsWith('.') &&\n !value.endsWith('/') &&\n !value.endsWith('.lock')\n );\n}\n"],"mappings":";;AA4BA,SAAgB,qBAAqB,gBAAiF;CACpH,IAAI,CAAC,gBAAgB,OAAO;CAC5B,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,kBAAkB,UACnC,OAAO,eAAe,SAAS,iBAAiB,cAAc;CAEhE,IAAI,eAAe,kBAAkB,QAAQ,OAAO;CACpD,IAAI,eAAe,kBAAkB,cAAc,OAAO;CAG1D,IAAI,eAAe,kBAAkB,SAAS,OAAO;CACrD,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,kBAAkB,UAAU,OAAO;CACtD,IAAI,eAAe,SAAS,oBAAoB,OAAO;CACvD,OAAO,eAAe,SAAS,iBAAiB,cAAc;AAChE;;;;;;AAOA,SAAgB,oBAAoB,gBAAiF;CACnH,OAAO,gBAAgB,kBAAkB,UAAU,iBAAiB,qBAAqB,cAAc;AACzG;AAEA,SAAS,aAAa,UAAmC,KAAiC;CACxF,MAAM,QAAQ,SAAS,QAAQ,SAAS;CACxC,OAAO,OAAO,UAAU,YAAY,OAAO,UAAU,KAAK,KAAK,QAAQ,IAAI,QAAQ,KAAA;AACrF;;AAGA,SAAgB,eAAe,MAA4E;CACzG,MAAM,WAAW,KAAK,YAAY,CAAC;CACnC,IAAI,KAAK,WAAW,gBAAgB,OAAO,aAAa,UAAU,mBAAmB;CACrF,IAAI,KAAK,WAAW,aAAa,OAAO,aAAa,UAAU,yBAAyB;CACxF,IAAI,KAAK,WAAW,gBAAgB,OAAO,aAAa,UAAU,gBAAgB;CAClF,IAAI,KAAK,WAAW,aAAa,OAAO,aAAa,UAAU,uBAAuB;AAExF;;AAGA,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AAO;AAE3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card-facts.d.ts","sourceRoot":"","sources":["../../src/work-items/card-facts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"card-facts.d.ts","sourceRoot":"","sources":["../../src/work-items/card-facts.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAC;AAIlE,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,6DAA6D;AAC7D,MAAM,WAAW,SAAU,SAAQ,WAAW;IAC5C,cAAc,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5B,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC,kBAAkB,EAAE,cAAc,EAAE,CAAC,CAAC;IACrD,kGAAkG;IAClG,SAAS,EAAE,cAAc,CAAC;IAC1B,mFAAmF;IACnF,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,8FAA8F;IAC9F,MAAM,EAAE,cAAc,CAAC;CACxB;AAKD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASpF;AAgBD,0EAA0E;AAC1E,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CA2B/C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hasPullRequest } from "../boards/semantics.js";
|
|
2
2
|
import { isHumanActorId } from "../storage/domains/audit/actors.js";
|
|
3
|
-
import {
|
|
3
|
+
import { workItemBoardSource } from "../work-item-branch.js";
|
|
4
4
|
import { metadataLabels } from "./card-labels.js";
|
|
5
5
|
import { factoryParticipantId, providerPeople } from "./card-people.js";
|
|
6
6
|
import { cardSearch } from "./card-search.js";
|
|
@@ -40,7 +40,7 @@ function humanActorIds(card) {
|
|
|
40
40
|
function cardFacts(card) {
|
|
41
41
|
let facts = factsByCard.get(card);
|
|
42
42
|
if (facts) return facts;
|
|
43
|
-
const source =
|
|
43
|
+
const source = workItemBoardSource(card.externalSource);
|
|
44
44
|
const metadata = sourceMetadata(card);
|
|
45
45
|
const people = providerPeople({
|
|
46
46
|
source,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card-facts.js","names":[],"sources":["../../src/work-items/card-facts.ts"],"sourcesContent":["import { hasPullRequest } from '../boards/semantics.js';\nimport { isHumanActorId } from '../storage/domains/audit/actors.js';\nimport type { Card } from '../storage/domains/work-items/base.js';\nimport {
|
|
1
|
+
{"version":3,"file":"card-facts.js","names":[],"sources":["../../src/work-items/card-facts.ts"],"sourcesContent":["import { hasPullRequest } from '../boards/semantics.js';\nimport { isHumanActorId } from '../storage/domains/audit/actors.js';\nimport type { Card } from '../storage/domains/work-items/base.js';\nimport { workItemBoardSource } from '../work-item-branch.js';\nimport { metadataLabels } from './card-labels.js';\nimport { factoryParticipantId, providerPeople } from './card-people.js';\nimport type { BoardRelations, ProviderPerson, ProviderPersonRole } from './card-people.js';\nimport { cardSearch } from './card-search.js';\nimport type { SourceFacts } from './card-source-filters.js';\nimport type { SearchableCard } from './search-terms.js';\n\n/** What a board view's search and filters read of a card. */\nexport interface CardFacts extends SourceFacts {\n hasPullRequest: boolean;\n labels: ReadonlySet<string>;\n /** The people the card's source names. */\n people: Record<ProviderPersonRole, ProviderPerson[]>;\n /** Participant ids by role: the source's people, and the Factory users who worked on the card. */\n relations: BoardRelations;\n /** The Factory users who created the card, moved it or started a session on it. */\n humanActorIds: readonly string[];\n /** What a search reads of the card, lowercased, so a search lowercases only its own words. */\n search: SearchableCard;\n}\n\n// A card object never changes: `listShared` gives a changed card a new object.\nconst factsByCard = new WeakMap<Card, CardFacts>();\n\n/**\n * What the card's source says of it. A card no provider filed has no source: its facts are its\n * work item's with the card's own on top, as clients read them.\n */\nexport function sourceMetadata({ workItem, metadata }: Card): Record<string, unknown> {\n if (workItem.provider === 'factory') return { ...workItem.metadata, ...metadata };\n return {\n ...workItem.metadata,\n labels: workItem.labels,\n author: workItem.author,\n state: workItem.state,\n identifier: workItem.key,\n };\n}\n\nfunction humanActorIds(card: Card): string[] {\n const ids = new Set<string>();\n const add = (actorId: string | undefined) => {\n if (isHumanActorId(actorId)) ids.add(actorId);\n };\n add(card.createdBy);\n for (const entry of card.stageHistory) {\n add(entry.by);\n add(entry.exitedBy);\n }\n for (const session of Object.values(card.sessions)) add(session.startedBy);\n return [...ids];\n}\n\n/** The card's facts, computed once for every view that reads the card. */\nexport function cardFacts(card: Card): CardFacts {\n let facts = factsByCard.get(card);\n if (facts) return facts;\n const source = workItemBoardSource(card.externalSource);\n const metadata = sourceMetadata(card);\n const people = providerPeople({ source, metadata });\n const actorIds = humanActorIds(card);\n const authored = new Set(people.authored.map(person => person.id));\n // A card filed by hand has no source to name its author: the person who filed it is.\n if (source === 'manual' && isHumanActorId(card.createdBy)) authored.add(factoryParticipantId(card.createdBy));\n facts = {\n source,\n metadata,\n hasPullRequest: hasPullRequest({ source, workItem: card.workItem }),\n labels: new Set(metadataLabels(metadata)),\n people,\n relations: {\n worked: new Set(actorIds.map(factoryParticipantId)),\n authored,\n assigned: new Set(people.assigned.map(person => person.id)),\n 'review-requested': new Set(people['review-requested'].map(person => person.id)),\n },\n humanActorIds: actorIds,\n search: cardSearch(card),\n };\n factsByCard.set(card, facts);\n return facts;\n}\n"],"mappings":";;;;;;;AA0BA,MAAM,8BAAc,IAAI,QAAyB;;;;;AAMjD,SAAgB,eAAe,EAAE,UAAU,YAA2C;CACpF,IAAI,SAAS,aAAa,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AAC,KAAI,WAAU,OAAO,EAAE,CAAC;EACjF;EACA,eAAe;EACf,QAAQ,WAAW,IAAI;CACzB;CACA,YAAY,IAAI,MAAM,KAAK;CAC3B,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/factory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0-alpha.0",
|
|
4
4
|
"description": "Mastra Software Factory module: the server core behind the Mastra Software Factory — storage domains, integrations, and surfaces for agent-powered software delivery",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -60,10 +60,10 @@
|
|
|
60
60
|
"zod": "^4.6.7",
|
|
61
61
|
"@mastra/auth-studio": "1.4.1",
|
|
62
62
|
"@mastra/auth-workos": "1.6.9",
|
|
63
|
-
"@mastra/code-sdk": "1.
|
|
64
|
-
"@mastra/connect": "1.
|
|
65
|
-
"@mastra/core": "1.85.0",
|
|
66
|
-
"@mastra/mcp": "2.10.0",
|
|
63
|
+
"@mastra/code-sdk": "1.21.0-alpha.0",
|
|
64
|
+
"@mastra/connect": "1.5.0-alpha.0",
|
|
65
|
+
"@mastra/core": "1.85.1-alpha.0",
|
|
66
|
+
"@mastra/mcp": "2.10.1-alpha.0",
|
|
67
67
|
"@mastra/platform-workspace": "1.13.1",
|
|
68
68
|
"@mastra/slack": "1.9.0"
|
|
69
69
|
},
|
|
@@ -77,10 +77,10 @@
|
|
|
77
77
|
"@internal/lint": "0.0.151",
|
|
78
78
|
"@internal/types-builder": "0.0.126",
|
|
79
79
|
"@internal/workspace": "0.0.23",
|
|
80
|
-
"@mastra/deployer": "1.85.0",
|
|
80
|
+
"@mastra/deployer": "1.85.1-alpha.0",
|
|
81
81
|
"@mastra/libsql": "1.31.1",
|
|
82
|
-
"@mastra/pg": "1.37.0",
|
|
83
|
-
"@mastra/server": "1.85.0"
|
|
82
|
+
"@mastra/pg": "1.37.1-alpha.0",
|
|
83
|
+
"@mastra/server": "1.85.1-alpha.0"
|
|
84
84
|
},
|
|
85
85
|
"engines": {
|
|
86
86
|
"node": ">=22.19.0"
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export interface PlatformApiClientConfig {
|
|
2
|
-
baseUrl: string;
|
|
3
|
-
accessToken: string;
|
|
4
|
-
/**
|
|
5
|
-
* Mastra project this deployment belongs to. Sent as `x-mastra-project-id`
|
|
6
|
-
* so the platform can attribute proxied provider activity to the project;
|
|
7
|
-
* the platform strips the header before forwarding anything upstream.
|
|
8
|
-
*/
|
|
9
|
-
projectId?: string;
|
|
10
|
-
fetchImpl?: typeof fetch;
|
|
11
|
-
}
|
|
12
|
-
export declare function platformApiClientConfigFromEnv(): PlatformApiClientConfig;
|
|
13
|
-
export declare class PlatformApiError extends Error {
|
|
14
|
-
readonly status: number;
|
|
15
|
-
readonly retryAfterSeconds: number | null;
|
|
16
|
-
constructor(message: string, status: number, retryAfterSeconds?: number | null);
|
|
17
|
-
}
|
|
18
|
-
export declare class PlatformApiClient {
|
|
19
|
-
#private;
|
|
20
|
-
constructor(config: PlatformApiClientConfig);
|
|
21
|
-
request<T>(method: string, path: string, body?: unknown, options?: {
|
|
22
|
-
signal?: AbortSignal;
|
|
23
|
-
actingUserId?: string;
|
|
24
|
-
}): Promise<T>;
|
|
25
|
-
requestRedirect(method: string, path: string, options?: {
|
|
26
|
-
signal?: AbortSignal;
|
|
27
|
-
}): Promise<string>;
|
|
28
|
-
}
|
|
29
|
-
export declare function logPlatformInfo(message: string, fields?: Record<string, unknown>): void;
|
|
30
|
-
/** Startup detail that `mastra factory dev` hides unless run with `--debug`. */
|
|
31
|
-
export declare function logPlatformBootInfo(message: string, fields?: Record<string, unknown>): void;
|
|
32
|
-
export declare function logPlatformWarn(message: string, fields?: Record<string, unknown>): void;
|
|
33
|
-
export declare function logPlatformError(message: string, fields?: Record<string, unknown>): void;
|
|
34
|
-
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -1 +0,0 @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,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAE3F;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAEvF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAExF"}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { bootDiagnosticsEnabled } from "../../timing.js";
|
|
2
|
-
// src/integrations/platform/api-client.ts
|
|
3
|
-
const DEFAULT_INTEGRATIONS_URL = "https://integrations.mastra.ai";
|
|
4
|
-
const REGIONAL_INTEGRATIONS_URLS = {
|
|
5
|
-
us: "https://integrations.us.mastra.ai",
|
|
6
|
-
eu: "https://integrations.eu.mastra.ai"
|
|
7
|
-
};
|
|
8
|
-
function platformApiClientConfigFromEnv() {
|
|
9
|
-
const integrationsApiUrl = process.env.MASTRA_INTEGRATIONS_API_URL?.trim() || resolveIntegrationsUrl();
|
|
10
|
-
const accessToken = process.env.MASTRA_PLATFORM_ACCESS_TOKEN?.trim() || process.env.MASTRA_PLATFORM_SECRET_KEY?.trim();
|
|
11
|
-
if (!accessToken) throw new Error("Platform integration: missing required environment variable MASTRA_PLATFORM_ACCESS_TOKEN (or MASTRA_PLATFORM_SECRET_KEY).");
|
|
12
|
-
const projectId = process.env.MASTRA_PROJECT_ID?.trim();
|
|
13
|
-
return {
|
|
14
|
-
baseUrl: normalizeIntegrationsApiUrl(integrationsApiUrl),
|
|
15
|
-
accessToken,
|
|
16
|
-
...projectId ? { projectId } : {}
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Resolves the integrations API base URL from `MASTRA_PLATFORM_REGION`
|
|
21
|
-
* (case-insensitive `us` or `eu`), falling back to the global default.
|
|
22
|
-
* Unknown region values fall through to the global default.
|
|
23
|
-
*/
|
|
24
|
-
function resolveIntegrationsUrl() {
|
|
25
|
-
const region = process.env.MASTRA_PLATFORM_REGION?.trim().toLowerCase();
|
|
26
|
-
if (region === "us" || region === "eu") return REGIONAL_INTEGRATIONS_URLS[region];
|
|
27
|
-
return DEFAULT_INTEGRATIONS_URL;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Normalizes an integrations API URL to a bare origin. Callers pass fully
|
|
31
|
-
* versioned paths (`/v1/server/...`, `/v2/...`), so a trailing `/v1` — as in
|
|
32
|
-
* legacy platform API URLs like `https://platform.mastra.ai/v1` — is stripped
|
|
33
|
-
* to avoid duplicated version segments.
|
|
34
|
-
*/
|
|
35
|
-
function normalizeIntegrationsApiUrl(integrationsApiUrl) {
|
|
36
|
-
return integrationsApiUrl.replace(/\/+$/, "").replace(/\/v1$/, "");
|
|
37
|
-
}
|
|
38
|
-
var PlatformApiError = class extends Error {
|
|
39
|
-
status;
|
|
40
|
-
retryAfterSeconds;
|
|
41
|
-
constructor(message, status, retryAfterSeconds = null) {
|
|
42
|
-
super(message);
|
|
43
|
-
this.name = "PlatformApiError";
|
|
44
|
-
this.status = status;
|
|
45
|
-
this.retryAfterSeconds = retryAfterSeconds;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var PlatformApiClient = class {
|
|
49
|
-
#baseUrl;
|
|
50
|
-
#accessToken;
|
|
51
|
-
#projectId;
|
|
52
|
-
#fetch;
|
|
53
|
-
constructor(config) {
|
|
54
|
-
const missing = ["baseUrl", "accessToken"].filter((field) => !config[field]);
|
|
55
|
-
if (missing.length > 0) throw new Error(`Platform integration: missing required config field(s): ${missing.join(", ")}.`);
|
|
56
|
-
this.#baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
57
|
-
this.#accessToken = config.accessToken;
|
|
58
|
-
this.#projectId = config.projectId?.trim() || null;
|
|
59
|
-
this.#fetch = config.fetchImpl ?? globalThis.fetch;
|
|
60
|
-
}
|
|
61
|
-
async request(method, path, body, options) {
|
|
62
|
-
const response = await this.#send(method, path, body, options);
|
|
63
|
-
if (!response.ok) {
|
|
64
|
-
const message = redact(await extractError(response), this.#accessToken);
|
|
65
|
-
const retryAfterSeconds = parseRetryAfter(response.headers.get("retry-after"));
|
|
66
|
-
logPlatformError("Platform API request failed", {
|
|
67
|
-
method,
|
|
68
|
-
path,
|
|
69
|
-
status: response.status,
|
|
70
|
-
retryAfterSeconds,
|
|
71
|
-
message
|
|
72
|
-
});
|
|
73
|
-
throw new PlatformApiError(message, response.status, retryAfterSeconds);
|
|
74
|
-
}
|
|
75
|
-
if (response.status === 204) return void 0;
|
|
76
|
-
return await response.json();
|
|
77
|
-
}
|
|
78
|
-
async requestRedirect(method, path, options) {
|
|
79
|
-
const response = await this.#send(method, path, void 0, options, "manual");
|
|
80
|
-
if (response.status >= 300 && response.status < 400) {
|
|
81
|
-
const location = response.headers.get("location");
|
|
82
|
-
if (location) return location;
|
|
83
|
-
}
|
|
84
|
-
if (!response.ok) {
|
|
85
|
-
const message = redact(await extractError(response), this.#accessToken);
|
|
86
|
-
const retryAfterSeconds = parseRetryAfter(response.headers.get("retry-after"));
|
|
87
|
-
logPlatformError("Platform API redirect request failed", {
|
|
88
|
-
method,
|
|
89
|
-
path,
|
|
90
|
-
status: response.status,
|
|
91
|
-
retryAfterSeconds,
|
|
92
|
-
message
|
|
93
|
-
});
|
|
94
|
-
throw new PlatformApiError(message, response.status, retryAfterSeconds);
|
|
95
|
-
}
|
|
96
|
-
logPlatformError("Platform API request did not return a redirect", {
|
|
97
|
-
method,
|
|
98
|
-
path,
|
|
99
|
-
status: response.status
|
|
100
|
-
});
|
|
101
|
-
throw new PlatformApiError("Platform API request did not return a redirect.", response.status);
|
|
102
|
-
}
|
|
103
|
-
async #send(method, path, body, options, redirect) {
|
|
104
|
-
const headers = {
|
|
105
|
-
accept: "application/json",
|
|
106
|
-
authorization: `Bearer ${this.#accessToken}`
|
|
107
|
-
};
|
|
108
|
-
if (this.#projectId) headers["x-mastra-project-id"] = this.#projectId;
|
|
109
|
-
if (options?.actingUserId) headers["x-acting-user-id"] = options.actingUserId;
|
|
110
|
-
const timeoutSignal = AbortSignal.timeout(15e3);
|
|
111
|
-
const init = {
|
|
112
|
-
method,
|
|
113
|
-
headers,
|
|
114
|
-
redirect,
|
|
115
|
-
signal: options?.signal ? AbortSignal.any([options.signal, timeoutSignal]) : timeoutSignal
|
|
116
|
-
};
|
|
117
|
-
if (body !== void 0) {
|
|
118
|
-
headers["content-type"] = "application/json";
|
|
119
|
-
init.body = JSON.stringify(body);
|
|
120
|
-
}
|
|
121
|
-
try {
|
|
122
|
-
return await this.#fetch(`${this.#baseUrl}${path}`, init);
|
|
123
|
-
} catch (error) {
|
|
124
|
-
if (error instanceof Error && error.message.includes(this.#accessToken)) {
|
|
125
|
-
const redacted = new Error(redact(error.message, this.#accessToken));
|
|
126
|
-
redacted.name = error.name;
|
|
127
|
-
logPlatformError("Platform API transport error", {
|
|
128
|
-
method,
|
|
129
|
-
path,
|
|
130
|
-
name: redacted.name,
|
|
131
|
-
message: redacted.message
|
|
132
|
-
});
|
|
133
|
-
throw redacted;
|
|
134
|
-
}
|
|
135
|
-
logPlatformError("Platform API transport error", {
|
|
136
|
-
method,
|
|
137
|
-
path,
|
|
138
|
-
name: error instanceof Error ? error.name : void 0,
|
|
139
|
-
message: error instanceof Error ? error.message : String(error)
|
|
140
|
-
});
|
|
141
|
-
throw error;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
async function extractError(response) {
|
|
146
|
-
try {
|
|
147
|
-
const data = await response.clone().json();
|
|
148
|
-
for (const field of [
|
|
149
|
-
"detail",
|
|
150
|
-
"error",
|
|
151
|
-
"title"
|
|
152
|
-
]) if (typeof data[field] === "string" && data[field]) return data[field];
|
|
153
|
-
} catch {}
|
|
154
|
-
return `Platform API request failed (${response.status})`;
|
|
155
|
-
}
|
|
156
|
-
function redact(message, accessToken) {
|
|
157
|
-
return message.split(accessToken).join("[REDACTED]");
|
|
158
|
-
}
|
|
159
|
-
function logPlatformInfo(message, fields) {
|
|
160
|
-
writePlatformLog("info", message, fields);
|
|
161
|
-
}
|
|
162
|
-
/** Startup detail that `mastra factory dev` hides unless run with `--debug`. */
|
|
163
|
-
function logPlatformBootInfo(message, fields) {
|
|
164
|
-
if (bootDiagnosticsEnabled) writePlatformLog("info", message, fields);
|
|
165
|
-
}
|
|
166
|
-
function logPlatformWarn(message, fields) {
|
|
167
|
-
writePlatformLog("warn", message, fields);
|
|
168
|
-
}
|
|
169
|
-
function logPlatformError(message, fields) {
|
|
170
|
-
writePlatformLog("error", message, fields);
|
|
171
|
-
}
|
|
172
|
-
function writePlatformLog(level, message, fields) {
|
|
173
|
-
const metadata = fields ? ` ${JSON.stringify(stripUndefined(fields))}` : "";
|
|
174
|
-
process.stderr.write(`[Mastra Factory] ${level.toUpperCase()} ${message}${metadata}\n`);
|
|
175
|
-
}
|
|
176
|
-
function stripUndefined(fields) {
|
|
177
|
-
return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== void 0));
|
|
178
|
-
}
|
|
179
|
-
function parseRetryAfter(value) {
|
|
180
|
-
if (!value) return null;
|
|
181
|
-
const seconds = Number.parseInt(value, 10);
|
|
182
|
-
return Number.isSafeInteger(seconds) && seconds >= 0 ? seconds : null;
|
|
183
|
-
}
|
|
184
|
-
export { PlatformApiClient, PlatformApiError, logPlatformBootInfo, logPlatformError, logPlatformInfo, logPlatformWarn, platformApiClientConfigFromEnv };
|
|
185
|
-
|
|
186
|
-
//# sourceMappingURL=api-client.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-client.js","names":[],"sources":["../../../src/integrations/platform/api-client.ts"],"sourcesContent":["import { bootDiagnosticsEnabled } from '../../timing.js';\n\nexport interface PlatformApiClientConfig {\n baseUrl: string;\n accessToken: string;\n /**\n * Mastra project this deployment belongs to. Sent as `x-mastra-project-id`\n * so the platform can attribute proxied provider activity to the project;\n * the platform strips the header before forwarding anything upstream.\n */\n projectId?: string;\n fetchImpl?: typeof fetch;\n}\n\nconst DEFAULT_INTEGRATIONS_URL = 'https://integrations.mastra.ai';\nconst REGIONAL_INTEGRATIONS_URLS: Record<'us' | 'eu', string> = {\n us: 'https://integrations.us.mastra.ai',\n eu: 'https://integrations.eu.mastra.ai',\n};\n\nexport function platformApiClientConfigFromEnv(): PlatformApiClientConfig {\n // MASTRA_INTEGRATIONS_API_URL is the dedicated override for the\n // integrations service and takes precedence over MASTRA_PLATFORM_REGION.\n // MASTRA_SHARED_API_URL is deliberately not consulted: it configures the\n // shared platform API, and integrations routing is independent of it.\n const integrationsApiUrl = process.env.MASTRA_INTEGRATIONS_API_URL?.trim() || resolveIntegrationsUrl();\n // MASTRA_PLATFORM_ACCESS_TOKEN is the credential Mastra Platform injects\n // into deployed projects; MASTRA_PLATFORM_SECRET_KEY is the org secret key\n // written by project scaffolding. The platform API accepts both forms.\n const accessToken =\n process.env.MASTRA_PLATFORM_ACCESS_TOKEN?.trim() || process.env.MASTRA_PLATFORM_SECRET_KEY?.trim();\n if (!accessToken) {\n throw new Error(\n 'Platform integration: missing required environment variable MASTRA_PLATFORM_ACCESS_TOKEN (or MASTRA_PLATFORM_SECRET_KEY).',\n );\n }\n const projectId = process.env.MASTRA_PROJECT_ID?.trim();\n return {\n baseUrl: normalizeIntegrationsApiUrl(integrationsApiUrl),\n accessToken,\n ...(projectId ? { projectId } : {}),\n };\n}\n\n/**\n * Resolves the integrations API base URL from `MASTRA_PLATFORM_REGION`\n * (case-insensitive `us` or `eu`), falling back to the global default.\n * Unknown region values fall through to the global default.\n */\nfunction resolveIntegrationsUrl(): string {\n const region = process.env.MASTRA_PLATFORM_REGION?.trim().toLowerCase();\n if (region === 'us' || region === 'eu') return REGIONAL_INTEGRATIONS_URLS[region];\n return DEFAULT_INTEGRATIONS_URL;\n}\n\n/**\n * Normalizes an integrations API URL to a bare origin. Callers pass fully\n * versioned paths (`/v1/server/...`, `/v2/...`), so a trailing `/v1` — as in\n * legacy platform API URLs like `https://platform.mastra.ai/v1` — is stripped\n * to avoid duplicated version segments.\n */\nfunction normalizeIntegrationsApiUrl(integrationsApiUrl: string): string {\n return integrationsApiUrl.replace(/\\/+$/, '').replace(/\\/v1$/, '');\n}\n\nexport class PlatformApiError extends Error {\n readonly status: number;\n readonly retryAfterSeconds: number | null;\n\n constructor(message: string, status: number, retryAfterSeconds: number | null = null) {\n super(message);\n this.name = 'PlatformApiError';\n this.status = status;\n this.retryAfterSeconds = retryAfterSeconds;\n }\n}\n\nexport class PlatformApiClient {\n readonly #baseUrl: string;\n readonly #accessToken: string;\n readonly #projectId: string | null;\n readonly #fetch: typeof fetch;\n\n constructor(config: PlatformApiClientConfig) {\n const missing = ['baseUrl', 'accessToken'].filter(field => !config[field as keyof PlatformApiClientConfig]);\n if (missing.length > 0) {\n throw new Error(`Platform integration: missing required config field(s): ${missing.join(', ')}.`);\n }\n this.#baseUrl = config.baseUrl.replace(/\\/+$/, '');\n this.#accessToken = config.accessToken;\n this.#projectId = config.projectId?.trim() || null;\n this.#fetch = config.fetchImpl ?? globalThis.fetch;\n }\n\n async request<T>(\n method: string,\n path: string,\n body?: unknown,\n options?: { signal?: AbortSignal; actingUserId?: string },\n ): Promise<T> {\n const response = await this.#send(method, path, body, options);\n if (!response.ok) {\n const message = redact(await extractError(response), this.#accessToken);\n const retryAfterSeconds = parseRetryAfter(response.headers.get('retry-after'));\n logPlatformError('Platform API request failed', {\n method,\n path,\n status: response.status,\n retryAfterSeconds,\n message,\n });\n throw new PlatformApiError(message, response.status, retryAfterSeconds);\n }\n if (response.status === 204) return undefined as T;\n return (await response.json()) as T;\n }\n\n async requestRedirect(method: string, path: string, options?: { signal?: AbortSignal }): Promise<string> {\n const response = await this.#send(method, path, undefined, options, 'manual');\n if (response.status >= 300 && response.status < 400) {\n const location = response.headers.get('location');\n if (location) return location;\n }\n if (!response.ok) {\n const message = redact(await extractError(response), this.#accessToken);\n const retryAfterSeconds = parseRetryAfter(response.headers.get('retry-after'));\n logPlatformError('Platform API redirect request failed', {\n method,\n path,\n status: response.status,\n retryAfterSeconds,\n message,\n });\n throw new PlatformApiError(message, response.status, retryAfterSeconds);\n }\n logPlatformError('Platform API request did not return a redirect', { method, path, status: response.status });\n throw new PlatformApiError('Platform API request did not return a redirect.', response.status);\n }\n\n async #send(\n method: string,\n path: string,\n body?: unknown,\n options?: { signal?: AbortSignal; actingUserId?: string },\n redirect?: RequestInit['redirect'],\n ): Promise<Response> {\n const headers: Record<string, string> = {\n accept: 'application/json',\n authorization: `Bearer ${this.#accessToken}`,\n };\n // Project attribution for proxied provider calls. Org-scoped machine\n // tokens carry no project claim, so without this header the platform\n // records proxy activity with no project.\n if (this.#projectId) {\n headers['x-mastra-project-id'] = this.#projectId;\n }\n // Acting end-user for platform GitHub writes: the platform resolves this\n // user's GitHub OAuth connection (org-scoped) so issues/PRs are authored\n // by the human instead of the App bot. Ignored by older platforms.\n if (options?.actingUserId) {\n headers['x-acting-user-id'] = options.actingUserId;\n }\n const timeoutSignal = AbortSignal.timeout(15_000);\n const init: RequestInit = {\n method,\n headers,\n redirect,\n signal: options?.signal ? AbortSignal.any([options.signal, timeoutSignal]) : timeoutSignal,\n };\n if (body !== undefined) {\n headers['content-type'] = 'application/json';\n init.body = JSON.stringify(body);\n }\n\n try {\n return await this.#fetch(`${this.#baseUrl}${path}`, init);\n } catch (error) {\n if (error instanceof Error && error.message.includes(this.#accessToken)) {\n const redacted = new Error(redact(error.message, this.#accessToken));\n redacted.name = error.name;\n logPlatformError('Platform API transport error', {\n method,\n path,\n name: redacted.name,\n message: redacted.message,\n });\n throw redacted;\n }\n logPlatformError('Platform API transport error', {\n method,\n path,\n name: error instanceof Error ? error.name : undefined,\n message: error instanceof Error ? error.message : String(error),\n });\n throw error;\n }\n }\n}\n\nasync function extractError(response: Response): Promise<string> {\n try {\n const data = (await response.clone().json()) as Record<string, unknown>;\n for (const field of ['detail', 'error', 'title']) {\n if (typeof data[field] === 'string' && data[field]) return data[field];\n }\n } catch {\n // Fall through to the status-based message.\n }\n return `Platform API request failed (${response.status})`;\n}\n\nfunction redact(message: string, accessToken: string): string {\n return message.split(accessToken).join('[REDACTED]');\n}\n\nexport function logPlatformInfo(message: string, fields?: Record<string, unknown>): void {\n writePlatformLog('info', message, fields);\n}\n\n/** Startup detail that `mastra factory dev` hides unless run with `--debug`. */\nexport function logPlatformBootInfo(message: string, fields?: Record<string, unknown>): void {\n if (bootDiagnosticsEnabled) writePlatformLog('info', message, fields);\n}\n\nexport function logPlatformWarn(message: string, fields?: Record<string, unknown>): void {\n writePlatformLog('warn', message, fields);\n}\n\nexport function logPlatformError(message: string, fields?: Record<string, unknown>): void {\n writePlatformLog('error', message, fields);\n}\n\nfunction writePlatformLog(level: 'info' | 'warn' | 'error', message: string, fields?: Record<string, unknown>): void {\n const metadata = fields ? ` ${JSON.stringify(stripUndefined(fields))}` : '';\n process.stderr.write(`[Mastra Factory] ${level.toUpperCase()} ${message}${metadata}\\n`);\n}\n\nfunction stripUndefined(fields: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(Object.entries(fields).filter(([, value]) => value !== undefined));\n}\n\nfunction parseRetryAfter(value: string | null): number | null {\n if (!value) return null;\n const seconds = Number.parseInt(value, 10);\n return Number.isSafeInteger(seconds) && seconds >= 0 ? seconds : null;\n}\n"],"mappings":";;AAcA,MAAM,2BAA2B;AACjC,MAAM,6BAA0D;CAC9D,IAAI;CACJ,IAAI;AACN;AAEA,SAAgB,iCAA0D;CAKxE,MAAM,qBAAqB,QAAQ,IAAI,6BAA6B,KAAK,KAAK,uBAAuB;CAIrG,MAAM,cACJ,QAAQ,IAAI,8BAA8B,KAAK,KAAK,QAAQ,IAAI,4BAA4B,KAAK;CACnG,IAAI,CAAC,aACH,MAAM,IAAI,MACR,2HACF;CAEF,MAAM,YAAY,QAAQ,IAAI,mBAAmB,KAAK;CACtD,OAAO;EACL,SAAS,4BA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AAwC;CACnH,MAAM,WAAW,SAAS,IAAI,KAAK,UAAU,eAAe,MAAM,CAAC,MAAM;CACzE,QAAQ,OAAO,MAAM,oBAAoB,MAAM,YAAY,EAAE,GAAG,UAAU,SAAS,GAAG;AACxF;AAEA,SAAS,eAAe,QAA0D;CAChF,OAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CAAC;AAC7F;AAEA,SAAS,gBAAgB,OAAqC;CAC5D,IAAI,CAAC,OAAO,OAAO;CACnB,MAAM,UAAU,OAAO,SAAS,OAAO,EAAE;CACzC,OAAO,OAAO,cAAc,OAAO,KAAK,WAAW,IAAI,UAAU;AACnE"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { MountedMastraCode } from '@mastra/code-sdk';
|
|
2
|
-
import { MastraWorker } from '@mastra/core/worker';
|
|
3
|
-
import type { WorkerDeps } from '@mastra/core/worker';
|
|
4
|
-
import type { IntegrationStorageHandle } from '../../../storage/domains/integrations/base.js';
|
|
5
|
-
import type { GitLabWebhookDispatchIntegration } from '../../gitlab/webhook-dispatch.js';
|
|
6
|
-
import { processGitLabWebhook } from '../../gitlab/webhook.js';
|
|
7
|
-
import type { ParsedGitLabWebhook } from '../../gitlab/webhook.js';
|
|
8
|
-
import type { PlatformApiClient } from '../api-client.js';
|
|
9
|
-
type PlatformGitLabEventWorkerSettings = {
|
|
10
|
-
version: 1;
|
|
11
|
-
connections: Record<string, {
|
|
12
|
-
afterEventId: string;
|
|
13
|
-
}>;
|
|
14
|
-
};
|
|
15
|
-
export type PlatformGitLabEventStorage = IntegrationStorageHandle<Record<string, unknown>, PlatformGitLabEventWorkerSettings, Record<string, unknown>>;
|
|
16
|
-
/** One row of the Platform integration event log. */
|
|
17
|
-
export interface IntegrationEventEntry {
|
|
18
|
-
id: string;
|
|
19
|
-
timestamp: number;
|
|
20
|
-
integrationId: string;
|
|
21
|
-
eventType: string;
|
|
22
|
-
sourceEventId: string | null;
|
|
23
|
-
payload: unknown;
|
|
24
|
-
}
|
|
25
|
-
export interface PlatformGitLabEventConnection {
|
|
26
|
-
id: string;
|
|
27
|
-
status: 'active' | 'needs_reauth';
|
|
28
|
-
}
|
|
29
|
-
export type PlatformGitLabEventDispatchIntegration = GitLabWebhookDispatchIntegration;
|
|
30
|
-
export interface PlatformGitLabEventWorkerConfig {
|
|
31
|
-
client: PlatformApiClient;
|
|
32
|
-
controller: MountedMastraCode['controller'];
|
|
33
|
-
gitlab: PlatformGitLabEventDispatchIntegration;
|
|
34
|
-
storage: PlatformGitLabEventStorage;
|
|
35
|
-
/** Platform connections to tail; only `active` ones are polled. */
|
|
36
|
-
listConnections: () => Promise<PlatformGitLabEventConnection[]>;
|
|
37
|
-
ingestFactoryEvent?: (event: ParsedGitLabWebhook) => Promise<unknown>;
|
|
38
|
-
intervalMs?: number;
|
|
39
|
-
now?: () => number;
|
|
40
|
-
process?: typeof processGitLabWebhook;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Tails the Platform event log for every active GitLab connection and feeds
|
|
44
|
-
* each stored webhook body through the same ingress the direct
|
|
45
|
-
* `/web/gitlab/webhook` route uses. A Platform-managed connection has no
|
|
46
|
-
* project webhook pointing at Factory, so this is how issue, note, merge
|
|
47
|
-
* request and push events reach the rules engine and subscribed sessions.
|
|
48
|
-
*
|
|
49
|
-
* One replica polls at a time (lease). Each connection keeps its own cursor,
|
|
50
|
-
* persisted only after a whole page has been processed, so a crash mid-page
|
|
51
|
-
* replays the page rather than losing it; replay handling in the rules ingress
|
|
52
|
-
* and the delivery-id dedupe keys make that safe.
|
|
53
|
-
*/
|
|
54
|
-
export declare class PlatformGitLabEventWorker extends MastraWorker {
|
|
55
|
-
#private;
|
|
56
|
-
readonly name = "platform-gitlab-events";
|
|
57
|
-
constructor(config: PlatformGitLabEventWorkerConfig);
|
|
58
|
-
init(deps: WorkerDeps): Promise<void>;
|
|
59
|
-
start(): Promise<void>;
|
|
60
|
-
stop(): Promise<void>;
|
|
61
|
-
get isRunning(): boolean;
|
|
62
|
-
}
|
|
63
|
-
export {};
|
|
64
|
-
//# sourceMappingURL=event-worker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-worker.d.ts","sourceRoot":"","sources":["../../../../src/integrations/platform/gitlab/event-worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAC9F,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,kCAAkC,CAAC;AACzF,OAAO,EAA0B,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACvF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAgB1D,KAAK,iCAAiC,GAAG;IACvC,OAAO,EAAE,CAAC,CAAC;IACX,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACvD,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,wBAAwB,CAC/D,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,iCAAiC,EACjC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACxB,CAAC;AAEF,qDAAqD;AACrD,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,E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