@mastra/factory 0.12.0-alpha.9 → 0.12.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.
Files changed (88) hide show
  1. package/README.md +35 -10
  2. package/dist/factory.d.ts +8 -0
  3. package/dist/factory.d.ts.map +1 -1
  4. package/dist/factory.js +4 -3
  5. package/dist/factory.js.map +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/integrations/github/acceptance-labels.d.ts +17 -0
  9. package/dist/integrations/github/acceptance-labels.d.ts.map +1 -0
  10. package/dist/integrations/github/acceptance-labels.js +55 -0
  11. package/dist/integrations/github/acceptance-labels.js.map +1 -0
  12. package/dist/integrations/github/integration.d.ts.map +1 -1
  13. package/dist/integrations/github/integration.js +47 -10
  14. package/dist/integrations/github/integration.js.map +1 -1
  15. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
  16. package/dist/integrations/github/reconcile-worker.js +2 -2
  17. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  18. package/dist/integrations/github/sandbox.d.ts +10 -13
  19. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  20. package/dist/integrations/github/sandbox.js +74 -65
  21. package/dist/integrations/github/sandbox.js.map +1 -1
  22. package/dist/integrations/github/settle-or-abort.d.ts +7 -0
  23. package/dist/integrations/github/settle-or-abort.d.ts.map +1 -0
  24. package/dist/integrations/github/settle-or-abort.js +25 -0
  25. package/dist/integrations/github/settle-or-abort.js.map +1 -0
  26. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  27. package/dist/integrations/platform/github/event-worker.js +3 -3
  28. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  29. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  30. package/dist/integrations/platform/github/integration.js +37 -5
  31. package/dist/integrations/platform/github/integration.js.map +1 -1
  32. package/dist/packages/_internals/workspace/dist/index.js +35 -0
  33. package/dist/packages/_internals/workspace/dist/index.js.map +1 -0
  34. package/dist/routes/config.d.ts.map +1 -1
  35. package/dist/routes/config.js +6 -0
  36. package/dist/routes/config.js.map +1 -1
  37. package/dist/routes/oauth.d.ts +3 -0
  38. package/dist/routes/oauth.d.ts.map +1 -1
  39. package/dist/routes/oauth.js +10 -2
  40. package/dist/routes/oauth.js.map +1 -1
  41. package/dist/routes/om-seed.d.ts +22 -0
  42. package/dist/routes/om-seed.d.ts.map +1 -0
  43. package/dist/routes/om-seed.js +40 -0
  44. package/dist/routes/om-seed.js.map +1 -0
  45. package/dist/routes/surface.d.ts +1 -1
  46. package/dist/routes/surface.d.ts.map +1 -1
  47. package/dist/routes/surface.js +4 -1
  48. package/dist/routes/surface.js.map +1 -1
  49. package/dist/routes/work-items.d.ts.map +1 -1
  50. package/dist/routes/work-items.js +7 -0
  51. package/dist/routes/work-items.js.map +1 -1
  52. package/dist/rules/defaults.d.ts.map +1 -1
  53. package/dist/rules/defaults.js +3 -0
  54. package/dist/rules/defaults.js.map +1 -1
  55. package/dist/rules/dispatcher.d.ts.map +1 -1
  56. package/dist/rules/dispatcher.js +16 -1
  57. package/dist/rules/dispatcher.js.map +1 -1
  58. package/dist/rules/tools.d.ts.map +1 -1
  59. package/dist/rules/tools.js +1 -23
  60. package/dist/rules/tools.js.map +1 -1
  61. package/dist/rules/transition-service.d.ts +12 -1
  62. package/dist/rules/transition-service.d.ts.map +1 -1
  63. package/dist/rules/transition-service.js +28 -3
  64. package/dist/rules/transition-service.js.map +1 -1
  65. package/dist/sandbox/session-sandbox.d.ts +22 -8
  66. package/dist/sandbox/session-sandbox.d.ts.map +1 -1
  67. package/dist/sandbox/session-sandbox.js +36 -37
  68. package/dist/sandbox/session-sandbox.js.map +1 -1
  69. package/dist/session/factory-session.js.map +1 -1
  70. package/dist/session/memory-settings-hydration.d.ts +3 -3
  71. package/dist/session/memory-settings-hydration.js +3 -3
  72. package/dist/session/memory-settings-hydration.js.map +1 -1
  73. package/dist/session/org-seed.d.ts +5 -5
  74. package/dist/session/org-seed.js +2 -2
  75. package/dist/session/org-seed.js.map +1 -1
  76. package/dist/storage/domains/work-items/base.d.ts +8 -0
  77. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  78. package/dist/storage/domains/work-items/base.js +10 -1
  79. package/dist/storage/domains/work-items/base.js.map +1 -1
  80. package/dist/workspace.d.ts +8 -0
  81. package/dist/workspace.d.ts.map +1 -1
  82. package/dist/workspace.js +21 -6
  83. package/dist/workspace.js.map +1 -1
  84. package/package.json +11 -10
  85. package/dist/session/checkpoint-capture.d.ts +0 -18
  86. package/dist/session/checkpoint-capture.d.ts.map +0 -1
  87. package/dist/session/checkpoint-capture.js +0 -27
  88. package/dist/session/checkpoint-capture.js.map +0 -1
@@ -5,6 +5,7 @@ import { attachGithubIssueReconciler } from "../../github/issue-reconciler.js";
5
5
  import { reconcileInterval, reconciliationEnabled } from "../../github/reconciliation-config.js";
6
6
  import { parseAuthorizedBotsEnv } from "../../github/webhook.js";
7
7
  import { buildGithubRoutes } from "../../github/routes.js";
8
+ import { settleOrAbort } from "../../github/settle-or-abort.js";
8
9
  import { PlatformApiClient, PlatformApiError, logPlatformInfo, logPlatformWarn, platformApiClientConfigFromEnv } from "../api-client.js";
9
10
  import { PlatformGithubEventWorker } from "./event-worker.js";
10
11
  import { registerApiRoute } from "@mastra/core/server";
@@ -31,6 +32,16 @@ const INSTALLATION_REPOS_CACHE_TTL_MS = 3e4;
31
32
  */
32
33
  const REPOSITORY_ACCESS_CACHE_TTL_MS = 5 * 6e4;
33
34
  /**
35
+ * How long a collaborator permission lookup may be reused. The reconcile
36
+ * sweep re-stamps every open card's author and the event tail gates every
37
+ * human-authored event on it, so one login can cost dozens of identical
38
+ * requests per cycle against the installation's REST budget. Revoked access
39
+ * reads as trusted for at most this long.
40
+ */
41
+ const COLLABORATOR_PERMISSION_CACHE_TTL_MS = 30 * 6e4;
42
+ /** Bound on the shared upstream lookup; callers race their own signal against it. */
43
+ const COLLABORATOR_PERMISSION_LOOKUP_TIMEOUT_MS = 1e4;
44
+ /**
34
45
  * Upper bound for both TTL caches. Entries expire lazily on re-access, so
35
46
  * without a hard cap keys that stop being queried would accumulate for the
36
47
  * integration's (long) lifetime. Insertion-order eviction — matches the
@@ -84,6 +95,10 @@ var PlatformGithubIntegration = class {
84
95
  #installationReposCache = /* @__PURE__ */ new Map();
85
96
  /** `orgId:repositoryId` → cached repository access (TTL-bounded). */
86
97
  #repositoryAccessCache = /* @__PURE__ */ new Map();
98
+ /** `owner/repo:login` → cached collaborator permission (TTL-bounded). */
99
+ #collaboratorPermissionCache = /* @__PURE__ */ new Map();
100
+ /** Same key → lookup already in flight, so overlapping callers share one request. */
101
+ #collaboratorPermissionInFlight = /* @__PURE__ */ new Map();
87
102
  intake = {
88
103
  resolveIntakeDispatch: (input) => this.#resolveIntakeDispatch(input),
89
104
  listSources: async ({ orgId, userId }) => {
@@ -668,11 +683,28 @@ var PlatformGithubIntegration = class {
668
683
  } catch {
669
684
  return;
670
685
  }
671
- try {
672
- return (await this.#client.request("GET", `${API_PREFIX}/github/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}/collaborators/${encodeURIComponent(username)}/permission`, void 0, { signal })).permission;
673
- } catch {
674
- return;
675
- }
686
+ const cacheKey = `${repository.owner}/${repository.repo}:${username.toLowerCase()}`;
687
+ const cached = this.#collaboratorPermissionCache.get(cacheKey);
688
+ if (cached && cached.expiresAt > Date.now()) return cached.permission;
689
+ this.#collaboratorPermissionCache.delete(cacheKey);
690
+ const inFlight = this.#collaboratorPermissionInFlight.get(cacheKey);
691
+ if (inFlight) return settleOrAbort(inFlight, signal, void 0);
692
+ const lookup = (async () => {
693
+ try {
694
+ const result = await this.#client.request("GET", `${API_PREFIX}/github/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}/collaborators/${encodeURIComponent(username)}/permission`, void 0, { signal: AbortSignal.timeout(COLLABORATOR_PERMISSION_LOOKUP_TIMEOUT_MS) });
695
+ setBounded(this.#collaboratorPermissionCache, cacheKey, {
696
+ permission: result.permission,
697
+ expiresAt: Date.now() + COLLABORATOR_PERMISSION_CACHE_TTL_MS
698
+ });
699
+ return result.permission;
700
+ } catch {
701
+ return;
702
+ } finally {
703
+ this.#collaboratorPermissionInFlight.delete(cacheKey);
704
+ }
705
+ })();
706
+ this.#collaboratorPermissionInFlight.set(cacheKey, lookup);
707
+ return settleOrAbort(lookup, signal, void 0);
676
708
  }
677
709
  async listInstallationRepos(installationId) {
678
710
  const cached = this.#installationReposCache.get(installationId);
@@ -1 +1 @@
1
- {"version":3,"file":"integration.js","names":["#client","#endpointHost","#slug","#pollingEnabled","#pollingIntervalMs","#pullRequestReconcileEnabled","#issueReconcileEnabled","#pullRequestReconcileIntervalMs","#issueReconcileIntervalMs","#installationReposCache","#repositoryAccessCache","#resolveIntakeDispatch","#listIssues","#listPullRequests","#getIssue","#createIssueComment","#updateIntakeIssue","#storage","#getPullRequest","#createPullRequest","#updatePullRequest","#mergePullRequest","#listComments","#createComment","#updateComment","#deleteComment","#listReviews","#getReview","#createReview","#updateReview","#submitReview","#dismissReview","#deletePendingReview","#listReviewComments","#createReviewComment","#updateReviewComment","#deleteReviewComment","#requestedReviewers","#integrationStorage","#statusRoute","#connectRoute","#connectUserRoute","#syncInstallations","#fetchUserConnection","#observeSelfAuthor"],"sources":["../../../../src/integrations/platform/github/integration.ts"],"sourcesContent":["import type { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { MastraWorker } from '@mastra/core/worker';\nimport type { Context } from 'hono';\n\nimport type { IntegrationConnection } from '../../../capabilities/connection.js';\nimport type {\n CreateIntakeCommentInput,\n Intake,\n IntakeIssue,\n IntakeIssueDetail,\n UpdateIntakeIssueInput,\n} from '../../../capabilities/intake.js';\nimport type {\n CreatePullRequestCommentInput,\n CreatePullRequestInput,\n CreateReviewCommentInput,\n CreateReviewInput,\n DeletePullRequestCommentInput,\n DismissReviewInput,\n ListPullRequestCommentsInput,\n ListPullRequestsInput,\n ListReviewCommentsInput,\n ListReviewsInput,\n MergePullRequestInput,\n PullRequest,\n PullRequestComment,\n PullRequestRef,\n RepositoryAccess,\n Review,\n ReviewComment,\n ReviewRef,\n SubmitReviewInput,\n UpdatePullRequestCommentInput,\n UpdatePullRequestInput,\n UpdateReviewInput,\n UpdateReviewersInput,\n VersionControl,\n} from '../../../capabilities/version-control.js';\nimport type { IntegrationStorageHandle } from '../../../storage/domains/integrations/base.js';\nimport type {\n SourceControlInstallation,\n SourceControlStorageHandle,\n} from '../../../storage/domains/source-control/base.js';\nimport type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../../base.js';\nimport { GithubAppIdentity } from '../../github/app-identity.js';\nimport type {\n GithubIntegration,\n GithubRepositoryPermission,\n GithubTriageCommentUpsertInput,\n GithubTriageCommentUpsertResult,\n RepoSummary,\n} from '../../github/integration.js';\nimport { attachGithubIssueReconciler } from '../../github/issue-reconciler.js';\nimport { reconcileInterval, reconciliationEnabled } from '../../github/reconciliation-config.js';\nimport { buildGithubRoutes } from '../../github/routes.js';\nimport { attachGithubReconciler, attachGithubRules } from '../../github/rules.js';\nimport type { ReconcileIssueState, ReconcilePullRequestState } from '../../github/rules.js';\nimport {\n createGithubSubscriptionTools,\n parseCreatedPullRequest,\n subscribeCurrentSessionToPullRequest,\n} from '../../github/session-subscriptions.js';\nimport type { GithubSubscriptionStorage } from '../../github/subscriptions.js';\nimport { parseAuthorizedBotsEnv } from '../../github/webhook.js';\nimport {\n logPlatformInfo,\n logPlatformWarn,\n PlatformApiClient,\n PlatformApiError,\n platformApiClientConfigFromEnv,\n} from '../api-client.js';\nimport { PlatformGithubEventWorker } from './event-worker.js';\nimport type { PlatformGithubEventStorage } from './event-worker.js';\n\ntype GithubActor = { login: string; avatarUrl: string | null; htmlUrl: string | null } | null;\n\ntype PlatformGithubInstallation = {\n installationId: number;\n accountLogin: string;\n accountType: string;\n suspendedAt: string | null;\n usable: boolean;\n};\n\ntype PlatformGithubUserConnection = {\n connected: boolean;\n githubUsername: string | null;\n reason?: 'token-invalid' | 'no-accessible-installation' | 'missing-permissions' | 'verification-unavailable' | null;\n};\n\ntype GithubIssue = {\n number: number;\n state: 'open' | 'closed';\n title: string;\n body: string | null;\n htmlUrl: string;\n labels: string[];\n assignees: string[];\n commentCount: number;\n user: GithubActor;\n createdAt: string;\n updatedAt: string;\n};\n\ntype GithubComment = {\n id: number;\n body: string;\n htmlUrl: string;\n user: GithubActor;\n createdAt: string;\n updatedAt: string;\n};\n\ntype GithubPullRequest = {\n number: number;\n title: string;\n body: string | null;\n state: 'open' | 'closed';\n htmlUrl: string;\n merged: boolean;\n mergeable: boolean | null;\n draft: boolean;\n head: { ref: string; sha: string };\n base: { ref: string; repo: { id: number; fullName: string } };\n user: GithubActor;\n assignees?: string[];\n requestedReviewers?: string[];\n labels?: string[];\n createdAt: string;\n updatedAt: string;\n};\n\ntype GithubReview = {\n id: number;\n htmlUrl: string | null;\n body: string | null;\n state: 'PENDING' | 'COMMENTED' | 'APPROVED' | 'CHANGES_REQUESTED' | 'DISMISSED';\n commitId: string | null;\n submittedAt: string | null;\n user: GithubActor;\n};\n\ntype GithubReviewComment = GithubComment & {\n path: string;\n line: number | null;\n side: 'LEFT' | 'RIGHT' | null;\n commitId: string;\n replyToId: number | null;\n};\n\nconst PAGE_SIZE = 30;\nconst API_PREFIX = '/v1/server';\n/**\n * Slug of the GitHub App this integration posts as. Platform credentials do not\n * carry their own identity, so Factory cannot otherwise recognise its own\n * writes — and failing to recognise them makes Factory wake itself. Override\n * with `MASTRA_PLATFORM_GITHUB_APP_SLUG` when pointing at a non-production App.\n */\nconst PLATFORM_GITHUB_APP_SLUG = 'mastra-platform';\n/**\n * How long an installation's repository listing may be reused. The repos\n * route and token minting both call it — often several times within one UI\n * interaction — and each call is a full Platform round trip.\n */\nconst INSTALLATION_REPOS_CACHE_TTL_MS = 30_000;\n/**\n * How long a minted repository-scoped token may be reused. GitHub\n * installation tokens live ~60 minutes; 5 minutes keeps a wide validity\n * margin while collapsing the per-session-materialization mint round trip.\n */\nconst REPOSITORY_ACCESS_CACHE_TTL_MS = 5 * 60_000;\n/**\n * Upper bound for both TTL caches. Entries expire lazily on re-access, so\n * without a hard cap keys that stop being queried would accumulate for the\n * integration's (long) lifetime. Insertion-order eviction — matches the\n * bounded verification cache in `@mastra/auth-studio`.\n */\nconst MAX_CACHE_ENTRIES = 1000;\n\nfunction setBounded<K, V>(cache: Map<K, V>, key: K, value: V): void {\n cache.delete(key);\n cache.set(key, value);\n if (cache.size > MAX_CACHE_ENTRIES) {\n const oldest = cache.keys().next().value;\n if (oldest !== undefined) cache.delete(oldest);\n }\n}\n\nconst REPOSITORY_TOKEN_PERMISSIONS = {\n contents: 'write',\n issues: 'write',\n pull_requests: 'write',\n} as const;\n\nfunction loose(c: unknown): Context {\n return c as Context;\n}\n\nfunction routeBaseUrl(ctx: IntegrationContext, requestUrl: string): string {\n return (ctx.baseUrl || new URL(requestUrl).origin).replace(/\\/+$/, '');\n}\n\nexport class PlatformGithubIntegration implements FactoryIntegration {\n readonly id = 'github';\n readonly #client: PlatformApiClient;\n readonly #endpointHost: string;\n readonly #slug: string | undefined;\n /**\n * Factory's own GitHub identity. Platform credentials do not carry the login\n * they post as, so this starts from the configured slug (usually absent on a\n * Platform deployment) and is corrected the first time Factory writes.\n */\n readonly identity: GithubAppIdentity;\n /**\n * Extra reviewer bot logins this deployment trusts for author-gated\n * notifications, merged over the built-in defaults.\n */\n readonly authorizedBots: readonly string[];\n readonly #pollingEnabled: boolean;\n readonly #pollingIntervalMs: number | undefined;\n readonly #pullRequestReconcileEnabled: boolean;\n readonly #issueReconcileEnabled: boolean;\n readonly #pullRequestReconcileIntervalMs: number | undefined;\n readonly #issueReconcileIntervalMs: number | undefined;\n #storage: SourceControlStorageHandle | undefined;\n #integrationStorage: GithubSubscriptionStorage | undefined;\n /** installationId → cached repository listing (TTL-bounded). */\n readonly #installationReposCache = new Map<number, { repos: RepoSummary[]; expiresAt: number }>();\n /** `orgId:repositoryId` → cached repository access (TTL-bounded). */\n readonly #repositoryAccessCache = new Map<string, { access: RepositoryAccess; expiresAt: number }>();\n\n readonly intake: Intake = {\n resolveIntakeDispatch: input => this.#resolveIntakeDispatch(input),\n listSources: async ({ orgId, userId }) => {\n const installations = await this.#client.request<{\n installations: Array<{\n installationId: number;\n accountLogin: string;\n accountType: string;\n suspendedAt: string | null;\n usable: boolean;\n }>;\n }>('GET', `${API_PREFIX}/github-app/installations`);\n const usable = installations.installations.filter(\n installation => installation.usable && !installation.suspendedAt,\n );\n const repositories = await Promise.all(\n usable.map(async installation => {\n const storedInstallation = await this.versionControl.registerInstallation({\n orgId,\n userId,\n installation: {\n externalId: String(installation.installationId),\n accountName: installation.accountLogin,\n accountType: installation.accountType,\n },\n });\n const result = await this.#client.request<{\n repositories: Array<{\n id: number;\n fullName: string;\n private: boolean;\n defaultBranch: string;\n htmlUrl: string;\n }>;\n }>('GET', `${API_PREFIX}/github-app/installations/${installation.installationId}/repositories`);\n await this.versionControl.registerRepositories({\n orgId,\n installationId: storedInstallation.id,\n repositories: result.repositories.map(repository => ({\n externalId: String(repository.id),\n slug: repository.fullName,\n defaultBranch: repository.defaultBranch,\n metadata: { private: repository.private, url: repository.htmlUrl },\n })),\n });\n return result.repositories.map(repository => ({ repository, installation }));\n }),\n );\n return repositories.flat().map(({ repository, installation }) => ({\n id: repository.fullName,\n name: repository.fullName,\n type: 'repository',\n metadata: {\n installationId: installation.installationId,\n accountLogin: installation.accountLogin,\n accountType: installation.accountType,\n repositoryId: repository.id,\n defaultBranch: repository.defaultBranch,\n private: repository.private,\n url: repository.htmlUrl,\n },\n }));\n },\n listItems: async ({ sourceIds, cursor }) => {\n const page = parsePositiveCursor(cursor);\n const pages = await Promise.all(\n sourceIds.map(async sourceId => {\n const connection = { type: 'app-installation' as const, installationId: 1 };\n const [issues, pullRequests] = await Promise.all([\n this.#listIssues(connection, sourceId, page),\n this.#listPullRequests({ connection, sourceId, includeDrafts: false, cursor: String(page) }),\n ]);\n return {\n items: [\n ...issues.issues.map(issue => ({\n source: { type: 'issue', externalId: `${sourceId}:${issue.id}`, url: issue.url },\n sourceId,\n title: 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: { repository: sourceId, number: Number(issue.id), author: issue.author },\n })),\n ...pullRequests.pullRequests.map(pullRequest => ({\n source: { type: 'pull-request', externalId: `${sourceId}:${pullRequest.id}`, url: pullRequest.url },\n sourceId,\n title: pullRequest.title,\n status: pullRequest.state,\n createdAt: pullRequest.createdAt,\n updatedAt: pullRequest.updatedAt,\n metadata: {\n repository: sourceId,\n number: Number(pullRequest.id),\n author: pullRequest.author,\n baseBranch: pullRequest.baseBranch,\n headBranch: pullRequest.headBranch,\n },\n })),\n ],\n hasNextPage: issues.nextCursor !== null || pullRequests.nextCursor !== null,\n };\n }),\n );\n return {\n items: pages.flatMap(result => result.items),\n nextCursor: pages.some(result => result.hasNextPage) ? String(page + 1) : null,\n };\n },\n listIssues: async input => {\n requireGithubConnection(input.connection);\n const sourceId = requireSingleSource(input.sourceIds, 'GitHub Intake requires exactly one repository source.');\n return this.#listIssues(input.connection, sourceId, parsePositiveCursor(input.cursor), input.labels);\n },\n getIssue: input => this.#getIssue(input.connection, input.sourceId, input.issueId),\n createComment: input => this.#createIssueComment(input),\n updateIssue: input => this.#updateIntakeIssue(input),\n };\n\n readonly versionControl: VersionControl = {\n initialize: ({ storage }) => {\n this.#storage = storage;\n },\n registerInstallation: ({ orgId, userId, installation }) =>\n this.storage.installations.upsert({\n orgId,\n connectedByUserId: userId,\n externalId: installation.externalId,\n accountName: installation.accountName,\n accountType: installation.accountType,\n providerMetadata: installation.metadata,\n }),\n registerRepositories: ({ orgId, installationId, repositories }) =>\n Promise.all(\n repositories.map(repository =>\n this.storage.repositories.upsert({\n orgId,\n input: {\n installationId,\n externalId: repository.externalId,\n slug: repository.slug,\n defaultBranch: repository.defaultBranch,\n providerMetadata: repository.metadata,\n },\n }),\n ),\n ),\n getRepositoryAccess: async ({ orgId, repositoryId }) => {\n // Every session materialization requests access; reuse a recent grant\n // instead of re-minting through the Platform each time. The TTL keeps\n // a wide margin under GitHub's ~60min installation-token lifetime.\n const cacheKey = `${orgId}:${repositoryId}`;\n const cached = this.#repositoryAccessCache.get(cacheKey);\n if (cached && cached.expiresAt > Date.now()) return cached.access;\n this.#repositoryAccessCache.delete(cacheKey);\n\n const repository = await this.storage.repositories.get({ orgId, id: repositoryId });\n if (!repository) throw new Error('Version-control repository not found.');\n const cloneUrl = `https://github.com/${repository.slug}.git`;\n const installation = await this.storage.installations.get({ orgId, id: repository.installationId });\n if (!installation) throw new Error('Version-control installation not found.');\n const installationId = parsePositiveInteger(installation.externalId);\n if (installationId === null) throw new Error('GitHub installation id is invalid.');\n const repositoryName = splitRepository(repository.slug).repo;\n\n try {\n const token = await this.#client.request<{ token: string }>(\n 'POST',\n `${API_PREFIX}/github-app/installations/${installationId}/token`,\n { repositories: [repositoryName], permissions: REPOSITORY_TOKEN_PERMISSIONS },\n );\n const access: RepositoryAccess = {\n cloneUrl,\n authorization: { scheme: 'bearer', token: token.token },\n };\n setBounded(this.#repositoryAccessCache, cacheKey, {\n access,\n expiresAt: Date.now() + REPOSITORY_ACCESS_CACHE_TTL_MS,\n });\n return access;\n } catch (err) {\n // Recover from stale installation: when a GitHub App is uninstalled and reinstalled,\n // GitHub assigns a new installation ID. Platform creates a new installation row,\n // and Factory's intake.listSources creates a new local installation row with the\n // new externalId. Try to find the new installation by accountName.\n if (!isDeadInstallation(err) || !installation.accountName) throw err;\n const installations = await this.storage.installations.list({ orgId });\n const newInstallation = installations.find(\n inst => inst.accountName === installation.accountName && inst.id !== installation.id,\n );\n if (!newInstallation) throw err;\n const newInstallationId = parsePositiveInteger(newInstallation.externalId);\n if (newInstallationId === null) throw err;\n\n // Persist the migration so we don't hit the recovery path on every call.\n await this.storage.repositories.migrateInstallation({\n orgId,\n id: repositoryId,\n newInstallationId: newInstallation.id,\n });\n\n const token = await this.#client.request<{ token: string }>(\n 'POST',\n `${API_PREFIX}/github-app/installations/${newInstallationId}/token`,\n { repositories: [repositoryName], permissions: REPOSITORY_TOKEN_PERMISSIONS },\n );\n const access: RepositoryAccess = {\n cloneUrl,\n authorization: { scheme: 'bearer', token: token.token },\n };\n setBounded(this.#repositoryAccessCache, cacheKey, {\n access,\n expiresAt: Date.now() + REPOSITORY_ACCESS_CACHE_TTL_MS,\n });\n return access;\n }\n },\n listPullRequests: input => this.#listPullRequests(input),\n getPullRequest: input => this.#getPullRequest(input),\n createPullRequest: input => this.#createPullRequest(input),\n updatePullRequest: input => this.#updatePullRequest(input),\n closePullRequest: input => this.#updatePullRequest({ ...input, state: 'closed' }),\n mergePullRequest: input => this.#mergePullRequest(input),\n listComments: input => this.#listComments(input),\n createComment: input => this.#createComment(input),\n updateComment: input => this.#updateComment(input),\n deleteComment: input => this.#deleteComment(input),\n listReviews: input => this.#listReviews(input),\n getReview: input => this.#getReview(input),\n createReview: input => this.#createReview(input),\n updateReview: input => this.#updateReview(input),\n submitReview: input => this.#submitReview(input),\n dismissReview: input => this.#dismissReview(input),\n deletePendingReview: input => this.#deletePendingReview(input),\n listReviewComments: input => this.#listReviewComments(input),\n createReviewComment: input => this.#createReviewComment(input),\n updateReviewComment: input => this.#updateReviewComment(input),\n deleteReviewComment: input => this.#deleteReviewComment(input),\n listRequestedReviewers: input => this.#requestedReviewers('GET', input),\n requestReviewers: input => this.#requestedReviewers('POST', input),\n removeRequestedReviewers: input => this.#requestedReviewers('DELETE', input),\n };\n\n constructor(\n options: {\n /** GitHub App slug used to recognize Factory's own webhook writes. */\n slug?: string;\n } = {},\n ) {\n const config = platformApiClientConfigFromEnv();\n this.#client = new PlatformApiClient(config);\n this.#endpointHost = new URL(config.baseUrl).host;\n this.#slug = options.slug;\n // Identity is deliberately NOT taken from `options.slug`. That slug names\n // the deployment's own self-hosted GitHub App, which is a different App\n // than the one this integration posts as — and on a Platform deployment it\n // is legitimately unset. Borrowing it is what left every self-loop guard\n // comparing against `undefined[bot]`. This integration *is* the Platform\n // App, so it names itself, with an override for non-production Apps.\n this.identity = new GithubAppIdentity(\n process.env.MASTRA_PLATFORM_GITHUB_APP_SLUG?.trim() || PLATFORM_GITHUB_APP_SLUG,\n );\n this.authorizedBots = parseAuthorizedBotsEnv(process.env.MASTRACODE_GITHUB_AUTHORIZED_BOTS) ?? [];\n this.#pollingEnabled = process.env.MASTRA_PLATFORM_GITHUB_POLLING_ENABLED?.trim().toLowerCase() !== 'false';\n this.#pollingIntervalMs = optionalPositiveIntegerEnv('MASTRA_PLATFORM_GITHUB_POLLING_INTERVAL_MS');\n const legacyReconcileEnabled = process.env.MASTRA_PLATFORM_GITHUB_RECONCILE_ENABLED;\n this.#pullRequestReconcileEnabled = reconciliationEnabled(\n process.env.MASTRACODE_PLATFORM_GITHUB_PR_RECONCILE_ENABLED,\n legacyReconcileEnabled,\n );\n this.#issueReconcileEnabled = reconciliationEnabled(\n process.env.MASTRACODE_PLATFORM_GITHUB_ISSUE_RECONCILE_ENABLED,\n legacyReconcileEnabled,\n );\n const legacyReconcileIntervalMs = reconcileInterval(process.env.MASTRACODE_PLATFORM_GITHUB_RECONCILE_INTERVAL_MS);\n this.#pullRequestReconcileIntervalMs =\n reconcileInterval(process.env.MASTRACODE_PLATFORM_GITHUB_PR_RECONCILE_INTERVAL_MS) ?? legacyReconcileIntervalMs;\n this.#issueReconcileIntervalMs =\n reconcileInterval(process.env.MASTRACODE_PLATFORM_GITHUB_ISSUE_RECONCILE_INTERVAL_MS) ?? legacyReconcileIntervalMs;\n }\n\n /** GitHub App slug when the deployment explicitly provides it. */\n get slug(): string | undefined {\n return this.#slug;\n }\n\n isFactoryCommentAuthor(login: string | null | undefined): boolean {\n return typeof login === 'string' && this.identity.matches(login);\n }\n\n get storage(): SourceControlStorageHandle {\n if (!this.#storage) throw new Error('PlatformGithubIntegration source-control storage has not been initialized.');\n return this.#storage;\n }\n\n get sourceControlStorage(): SourceControlStorageHandle {\n return this.storage;\n }\n\n get integrationStorage(): GithubSubscriptionStorage {\n if (!this.#integrationStorage) {\n throw new Error('PlatformGithubIntegration generic storage has not been initialized.');\n }\n return this.#integrationStorage;\n }\n\n /** Resolve a stored GitHub locator without scanning installations or repositories. */\n async #resolveIntakeDispatch({\n orgId,\n externalSource,\n }: {\n orgId: string;\n externalSource: { type: string; externalId: string };\n }): Promise<{ connection: IntegrationConnection; sourceId: string; issueId: string } | null> {\n const target = parseGithubExternalTarget(externalSource.externalId);\n if (!target) return null;\n const repository = target.repository.includes('/')\n ? target.repository\n : (await this.storage.repositories.findByExternalId({ orgId, externalId: target.repository }))?.slug;\n if (!repository) return null;\n return {\n connection: { type: 'app-installation', installationId: 1 },\n sourceId: repository,\n issueId: target.issueId,\n };\n }\n\n initialize({ storage }: { storage: IntegrationStorageHandle }): void {\n this.#integrationStorage = storage as unknown as GithubSubscriptionStorage;\n logPlatformInfo('Platform GitHub integration initialized', {\n endpointHost: this.#endpointHost,\n pollingEnabled: this.#pollingEnabled,\n pollingIntervalMs: this.#pollingIntervalMs,\n pullRequestReconcileEnabled: this.#pullRequestReconcileEnabled,\n issueReconcileEnabled: this.#issueReconcileEnabled,\n });\n }\n\n routes(ctx: IntegrationContext): ApiRoute[] {\n const ingestFactoryEvent = attachGithubRules(this, ctx);\n return [\n this.#statusRoute(ctx),\n this.#connectRoute(ctx),\n this.#connectUserRoute(ctx),\n ...buildGithubRoutes({\n auth: ctx.auth,\n sandbox: ctx.sandbox,\n storage: ctx.factoryStorage,\n github: this as unknown as GithubIntegration,\n stateSigner: ctx.stateSigner,\n baseUrl: ctx.baseUrl,\n controller: ctx.controller,\n memorySettings: ctx.storage.memorySettings,\n projects: ctx.storage.projects,\n emitAudit: ctx.hooks?.emitAudit,\n ingestFactoryEvent,\n ...(ctx.workItems ? { workItems: ctx.workItems } : {}),\n }).filter(\n route =>\n route.path !== '/web/github/status' &&\n route.path !== '/web/github/webhook' &&\n !route.path.startsWith('/auth/github/'),\n ),\n ];\n }\n\n #statusRoute(ctx: IntegrationContext): ApiRoute {\n return registerApiRoute('/web/github/status', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n await ctx.auth.ensureUser(loose(c));\n const tenant = ctx.auth.tenant(loose(c));\n if (!tenant) return c.json({ error: 'unauthorized', reason: 'auth_required' }, 401);\n if (!tenant.orgId) {\n return c.json({\n enabled: true,\n sandboxEnabled: !!ctx.sandbox,\n organizationRequired: true,\n connected: false,\n installations: [],\n userConnected: false,\n userGithubUsername: null,\n reason: 'organization_required',\n diagnostics: this.diagnostics(),\n });\n }\n\n const [installations, userConnection] = await Promise.all([\n this.#syncInstallations(tenant.orgId, tenant.userId),\n this.#fetchUserConnection(tenant.userId),\n ]);\n return c.json({\n enabled: true,\n sandboxEnabled: !!ctx.sandbox,\n connected: installations.length > 0,\n installations: installations.map(installation => ({\n installationId: Number(installation.externalId),\n accountLogin: installation.accountName,\n accountType: installation.accountType,\n })),\n userConnected: userConnection.connected,\n userGithubUsername: userConnection.githubUsername,\n reason: installations.length > 0 ? 'ready' : 'not_connected',\n diagnostics: this.diagnostics(),\n });\n },\n });\n }\n\n #connectRoute(ctx: IntegrationContext): ApiRoute {\n return registerApiRoute('/auth/github/connect', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n await ctx.auth.ensureUser(loose(c));\n const tenant = ctx.auth.tenant(loose(c));\n if (!tenant?.orgId) return c.json({ error: 'unauthorized' }, 401);\n\n const redirectTo = c.req.query('redirectTo') || c.req.query('return_to') || '/';\n const originator = routeBaseUrl(ctx, c.req.url);\n logPlatformInfo('Starting Platform GitHub connect flow', {\n orgId: tenant.orgId,\n redirectTo,\n originator,\n });\n const query = new URLSearchParams({\n action: 'install',\n redirectTo,\n originator,\n });\n const { url } = await this.#client.request<{ url: string }>(\n 'GET',\n `${API_PREFIX}/github-app/install-url?${query}`,\n );\n return c.redirect(url);\n },\n });\n }\n\n #connectUserRoute(ctx: IntegrationContext): ApiRoute {\n return registerApiRoute('/auth/github/connect-user', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n await ctx.auth.ensureUser(loose(c));\n const tenant = ctx.auth.tenant(loose(c));\n if (!tenant?.orgId) return c.json({ error: 'unauthorized' }, 401);\n\n const redirectTo = c.req.query('redirectTo') || c.req.query('return_to') || '/';\n const originator = routeBaseUrl(ctx, c.req.url);\n logPlatformInfo('Starting Platform GitHub user authorization flow', {\n orgId: tenant.orgId,\n redirectTo,\n originator,\n });\n const query = new URLSearchParams({\n userId: tenant.userId,\n redirectTo,\n originator,\n });\n const { url } = await this.#client.request<{ url: string }>(\n 'GET',\n `${API_PREFIX}/github-app/authenticate?${query}`,\n );\n return c.redirect(url);\n },\n });\n }\n\n /**\n * Personal GitHub connection status for the acting user. Returns\n * not-connected when the platform predates the user-connection endpoint.\n */\n async #fetchUserConnection(userId: string): Promise<PlatformGithubUserConnection> {\n try {\n const connection = await this.#client.request<PlatformGithubUserConnection>(\n 'GET',\n `${API_PREFIX}/github-app/user-connection?${new URLSearchParams({ userId })}`,\n );\n if (!connection.connected && connection.reason) {\n logPlatformWarn('Platform GitHub user connection verification failed', {\n userId,\n reason: connection.reason,\n });\n }\n return connection;\n } catch {\n return { connected: false, githubUsername: null };\n }\n }\n\n async #syncInstallations(orgId: string, userId: string): Promise<SourceControlInstallation[]> {\n const result = await this.#client.request<{ installations: PlatformGithubInstallation[] }>(\n 'GET',\n `${API_PREFIX}/github-app/installations`,\n );\n const usableInstallations = result.installations.filter(\n installation => installation.usable && !installation.suspendedAt,\n );\n return Promise.all(\n usableInstallations.map(installation =>\n this.versionControl.registerInstallation({\n orgId,\n userId,\n installation: {\n externalId: String(installation.installationId),\n accountName: installation.accountLogin,\n accountType: installation.accountType,\n },\n }),\n ),\n );\n }\n\n workers(ctx: IntegrationContext): MastraWorker[] {\n if (!this.#pollingEnabled && !this.#pullRequestReconcileEnabled && !this.#issueReconcileEnabled) return [];\n if (!ctx.controller) {\n throw new Error('Platform GitHub event polling requires the mounted Mastra Code controller.');\n }\n return [\n new PlatformGithubEventWorker({\n client: this.#client,\n controller: ctx.controller,\n github: this,\n storage: ctx.storage.generic as unknown as PlatformGithubEventStorage,\n ingestFactoryEvent: attachGithubRules(this, ctx),\n reconcileFactoryState: this.#pullRequestReconcileEnabled\n ? attachGithubReconciler(this, ctx, input => this.fetchPullRequestState(input))\n : undefined,\n reconcileIssuesFactoryState: this.#issueReconcileEnabled\n ? attachGithubIssueReconciler(this, ctx, input => this.fetchIssueState(input))\n : undefined,\n pollEventsEnabled: this.#pollingEnabled,\n intervalMs: this.#pollingIntervalMs,\n pullRequestReconcileIntervalMs: this.#pullRequestReconcileIntervalMs,\n issueReconcileIntervalMs: this.#issueReconcileIntervalMs,\n // Resolved lazily: workers are constructed before versionControl\n // storage is initialized, and the worker only reads these slices once\n // it is running.\n sourceControl: {\n projectRepositories: {\n listConfiguredExternalKeys: () => this.storage.projectRepositories.listConfiguredExternalKeys(),\n listByExternalRepository: args => this.storage.projectRepositories.listByExternalRepository(args),\n },\n repositories: {\n findByExternalId: args => this.storage.repositories.findByExternalId(args),\n },\n },\n }),\n ];\n }\n\n /**\n * Reads live PR state through the Platform GitHub proxy for the merge\n * reconciler. Returns undefined when the PR cannot be resolved (missing,\n * proxy error) so a sweep never fabricates a merge.\n */\n async fetchPullRequestState(input: {\n installationId: number;\n repository: string;\n number: number;\n }): Promise<ReconcilePullRequestState | undefined> {\n let repository: { owner: string; repo: string };\n try {\n repository = splitRepository(input.repository);\n } catch {\n return undefined;\n }\n try {\n const result = await this.#client.request<{\n title?: string;\n html_url?: string;\n state?: string;\n draft?: boolean;\n merged?: boolean;\n created_at?: string;\n user?: { login?: string } | null;\n assignees?: Array<{ login?: string }> | null;\n requested_reviewers?: Array<{ login?: string }> | null;\n labels?: Array<{ name?: string } | string> | null;\n merged_by?: { login?: string } | null;\n head?: { ref?: string };\n base?: { ref?: string };\n }>(\n 'GET',\n `${API_PREFIX}/github/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}/pulls/${input.number}`,\n );\n return {\n title: result.title ?? `PR ${input.number}`,\n url: result.html_url ?? `https://github.com/${input.repository}/pull/${input.number}`,\n state: result.state === 'closed' ? 'closed' : 'open',\n draft: result.draft === true,\n merged: result.merged === true,\n assignees: (result.assignees ?? []).flatMap(assignee => (assignee.login ? [assignee.login] : [])),\n requestedReviewers: (result.requested_reviewers ?? []).flatMap(reviewer =>\n reviewer.login ? [reviewer.login] : [],\n ),\n labels: (result.labels ?? []).flatMap(label =>\n typeof label === 'string' ? [label] : label.name ? [label.name] : [],\n ),\n headBranch: result.head?.ref ?? '',\n baseBranch: result.base?.ref ?? '',\n ...(result.user?.login ? { author: result.user.login } : {}),\n ...(result.created_at ? { createdAt: result.created_at } : {}),\n ...(result.merged_by?.login ? { mergedBy: result.merged_by.login } : {}),\n };\n } catch {\n return undefined;\n }\n }\n\n /**\n * Reads live issue state through the Platform GitHub proxy for the\n * reconciler. Returns undefined when the issue cannot be resolved (missing,\n * is actually a PR, proxy error) so a sweep never fabricates a close.\n */\n async fetchIssueState(input: {\n installationId: number;\n repository: string;\n number: number;\n }): Promise<ReconcileIssueState | undefined> {\n let repository: { owner: string; repo: string };\n try {\n repository = splitRepository(input.repository);\n } catch {\n return undefined;\n }\n try {\n const result = await this.#client.request<{\n title?: string;\n html_url?: string;\n state?: string;\n state_reason?: string | null;\n created_at?: string;\n updated_at?: string;\n user?: { login?: string } | null;\n assignees?: Array<{ login?: string }> | null;\n labels?: Array<{ name?: string } | string> | null;\n pull_request?: unknown;\n }>(\n 'GET',\n `${API_PREFIX}/github/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}/issues/${input.number}`,\n );\n if (result.pull_request) return undefined;\n return {\n title: result.title ?? `Issue ${input.number}`,\n url: result.html_url ?? `https://github.com/${input.repository}/issues/${input.number}`,\n state: result.state === 'closed' ? 'closed' : 'open',\n ...(result.state_reason ? { stateReason: result.state_reason } : {}),\n assignees: (result.assignees ?? []).flatMap(assignee => (assignee.login ? [assignee.login] : [])),\n labels: (result.labels ?? []).map(label => (typeof label === 'string' ? label : label.name)).filter((name): name is string => Boolean(name)),\n ...(result.user?.login ? { author: result.user.login } : {}),\n ...(result.created_at ? { createdAt: result.created_at } : {}),\n ...(result.updated_at ? { updatedAt: result.updated_at } : {}),\n };\n } catch {\n return undefined;\n }\n }\n\n async upsertFactoryTriageComment(input: GithubTriageCommentUpsertInput): Promise<GithubTriageCommentUpsertResult> {\n const comments: GithubComment[] = [];\n for (let page = 1; ; page += 1) {\n const query = new URLSearchParams({ page: String(page), per_page: String(PAGE_SIZE) });\n const result = await this.#client.request<{ comments: GithubComment[] }>(\n 'GET',\n `${repositoryPath(input.repository, `issues/${input.issueNumber}/comments`)}?${query}`,\n );\n comments.push(...result.comments);\n if (result.comments.length < PAGE_SIZE) break;\n }\n const existing = comments\n .filter(comment => comment.body.includes('<!-- mastra-factory-triage -->') && this.isFactoryCommentAuthor(comment.user?.login))\n .sort((left, right) => left.id - right.id)[0];\n if (existing) {\n const comment = await this.#client.request<GithubComment>(\n 'PATCH',\n repositoryPath(input.repository, `issues/comments/${existing.id}`),\n { body: input.body },\n );\n this.#observeSelfAuthor(comment, undefined);\n return { action: 'updated', commentId: String(comment.id), url: comment.htmlUrl };\n }\n const comment = await this.#client.request<GithubComment>(\n 'POST',\n repositoryPath(input.repository, `issues/${input.issueNumber}/comments`),\n { body: input.body },\n );\n this.#observeSelfAuthor(comment, undefined);\n return { action: 'created', commentId: String(comment.id), url: comment.htmlUrl };\n }\n\n sessionTools({ requestContext }: { requestContext: RequestContext }): IntegrationTools {\n return createGithubSubscriptionTools(requestContext, this as unknown as GithubIntegration);\n }\n\n async postToolObserver({\n toolContext,\n requestContext,\n }: Parameters<NonNullable<FactoryIntegration['postToolObserver']>>[0]): Promise<void> {\n const pullRequestUrl = parseCreatedPullRequest(toolContext);\n if (!pullRequestUrl || !requestContext) return;\n await subscribeCurrentSessionToPullRequest(\n requestContext,\n pullRequestUrl,\n 'auto-gh-pr-create',\n this as unknown as GithubIntegration,\n );\n }\n\n diagnostics(): Record<string, unknown> {\n return {\n mode: 'platform',\n endpointHost: this.#endpointHost,\n polling: {\n enabled: this.#pollingEnabled,\n ...(this.#pollingIntervalMs === undefined ? {} : { intervalMs: this.#pollingIntervalMs }),\n },\n reconcile: {\n pullRequests: {\n enabled: this.#pullRequestReconcileEnabled,\n ...(this.#pullRequestReconcileIntervalMs === undefined\n ? {}\n : { intervalMs: this.#pullRequestReconcileIntervalMs }),\n },\n issues: {\n enabled: this.#issueReconcileEnabled,\n ...(this.#issueReconcileIntervalMs === undefined ? {} : { intervalMs: this.#issueReconcileIntervalMs }),\n },\n },\n };\n }\n\n async getRepositoryCollaboratorPermission(\n _installationId: number,\n repoFullName: string,\n username: string,\n signal?: AbortSignal,\n ): Promise<GithubRepositoryPermission | undefined> {\n let repository: { owner: string; repo: string };\n try {\n repository = splitRepository(repoFullName);\n } catch {\n return undefined;\n }\n try {\n const result = await this.#client.request<{ permission: GithubRepositoryPermission }>(\n 'GET',\n `${API_PREFIX}/github/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}/collaborators/${encodeURIComponent(username)}/permission`,\n undefined,\n { signal },\n );\n return result.permission;\n } catch {\n return undefined;\n }\n }\n\n async listInstallationRepos(installationId: number): Promise<RepoSummary[]> {\n // Hot in two places — the repos route and token minting (which re-lists\n // only to validate the 1–10 repo rule). A short TTL collapses repeat\n // Platform round trips within one UI interaction.\n const cached = this.#installationReposCache.get(installationId);\n if (cached && cached.expiresAt > Date.now()) return cached.repos;\n this.#installationReposCache.delete(installationId);\n\n const result = await this.#client.request<{\n repositories: Array<{\n id: number;\n owner: string;\n name: string;\n fullName: string;\n private: boolean;\n defaultBranch: string;\n }>;\n }>('GET', `${API_PREFIX}/github-app/installations/${installationId}/repositories`);\n const repos = result.repositories.map(repository => ({ ...repository, installationId }));\n setBounded(this.#installationReposCache, installationId, {\n repos,\n expiresAt: Date.now() + INSTALLATION_REPOS_CACHE_TTL_MS,\n });\n return repos;\n }\n\n async mintInstallationToken(installationId: number): Promise<string> {\n const repositories = await this.listInstallationRepos(installationId);\n if (repositories.length === 0 || repositories.length > 10) {\n throw new Error('Platform GitHub token minting requires between one and ten installation repositories.');\n }\n const result = await this.#client.request<{ token: string }>(\n 'POST',\n `${API_PREFIX}/github-app/installations/${installationId}/token`,\n { repositories: repositories.map(repository => repository.name), permissions: REPOSITORY_TOKEN_PERMISSIONS },\n );\n return result.token;\n }\n\n async addIssueLabels(\n _installationId: number,\n sourceId: string,\n issueNumber: number,\n labels: string[],\n ): Promise<string[]> {\n const result = await this.#client.request<{ labels: string[] }>(\n 'POST',\n repositoryPath(sourceId, `issues/${issueNumber}/labels`),\n { labels },\n );\n return result.labels;\n }\n\n getInstallationOctokit(_installationId: number): ReturnType<GithubIntegration['getInstallationOctokit']> {\n return {\n pulls: {\n get: async ({ owner, repo, pull_number }: { owner: string; repo: string; pull_number: number }) => {\n const data = await this.#client.request<GithubPullRequest>(\n 'GET',\n repositoryPath(`${owner}/${repo}`, `pulls/${pull_number}`),\n );\n return { data: { base: { repo: { id: data.base.repo.id } } } };\n },\n },\n } as unknown as ReturnType<GithubIntegration['getInstallationOctokit']>;\n }\n\n async #listIssues(connection: IntegrationConnection, sourceId: string, page: number, labels?: string[]) {\n requireGithubConnection(connection);\n const path = repositoryPath(sourceId, 'issues');\n const query = new URLSearchParams({ state: 'open', page: String(page), per_page: String(PAGE_SIZE) });\n const normalizedLabels = normalizeLabels(labels);\n if (normalizedLabels.length > 0) query.set('label', normalizedLabels.join(','));\n const result = await this.#client.request<{ issues: GithubIssue[] }>('GET', `${path}?${query}`);\n return {\n issues: result.issues.map(issue => parseIntakeIssue(sourceId, issue)),\n nextCursor: result.issues.length > 0 ? String(page + 1) : null,\n };\n }\n\n async #getIssue(connection: IntegrationConnection, sourceId: string | undefined, issueId: string) {\n requireGithubConnection(connection);\n const repository = requireSource(sourceId, 'GitHub Intake requires a repository source.');\n const issueNumber = requirePositiveId(issueId, 'issue');\n try {\n const [issue, comments] = await Promise.all([\n this.#client.request<GithubIssue>('GET', repositoryPath(repository, `issues/${issueNumber}`)),\n this.#client.request<{ comments: GithubComment[] }>(\n 'GET',\n `${repositoryPath(repository, `issues/${issueNumber}/comments`)}?per_page=100`,\n ),\n ]);\n return parseIntakeIssueDetail(repository, issue, comments.comments);\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n async #updateIntakeIssue(input: UpdateIntakeIssueInput): Promise<IntakeIssue | null> {\n requireGithubConnection(input.connection);\n const repository = requireSource(input.sourceId, 'GitHub Intake requires a repository source.');\n const issueNumber = requirePositiveId(input.issueId, 'issue');\n if (input.state.kind === 'byName') {\n logPlatformWarn(`Platform GitHub: updateIssue byName is not supported (name=${input.state.name}); ignoring.`);\n return null;\n }\n const targetState: 'open' | 'closed' =\n input.state.stateType === 'unstarted' || input.state.stateType === 'started' ? 'open' : 'closed';\n const stateReason: 'completed' | 'not_planned' | null =\n targetState === 'closed' ? (input.state.stateType === 'canceled' ? 'not_planned' : 'completed') : null;\n // Reject PR targets: probe the pulls endpoint. A 200 means the number is a\n // pull request, not an issue. Factory does not close PRs via updateIssue —\n // PR merges/closes go through the version-control pipeline.\n try {\n await this.#client.request<GithubPullRequest>('GET', repositoryPath(repository, `pulls/${issueNumber}`));\n logPlatformWarn(`Platform GitHub: updateIssue rejected — target ${repository}#${issueNumber} is a pull request.`);\n return null;\n } catch (error) {\n if (!isNotFound(error)) throw error;\n // 404 on pulls means it's an issue (or nothing) — fall through to PATCH.\n }\n try {\n const issue = await this.#client.request<GithubIssue>(\n 'PATCH',\n repositoryPath(repository, `issues/${issueNumber}`),\n {\n state: targetState,\n ...(stateReason ? { state_reason: stateReason } : {}),\n },\n { actingUserId: input.actingUserId },\n );\n return parseIntakeIssue(repository, issue);\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n /**\n * Learn Factory's own login from a write it just made. Skipped when the write\n * was made on behalf of a user — that comment is authored by the human, and\n * recording it would teach Factory to mistake a person for itself.\n */\n #observeSelfAuthor(comment: GithubComment, actingUserId: string | undefined): void {\n if (actingUserId) return;\n this.identity.observeSelfAuthor(comment.user?.login);\n }\n\n async #createIssueComment(input: CreateIntakeCommentInput) {\n requireGithubConnection(input.connection);\n const repository = requireSource(input.sourceId, 'GitHub Intake requires a repository source.');\n const issueNumber = requirePositiveId(input.issueId, 'issue');\n try {\n const comment = await this.#client.request<GithubComment>(\n 'POST',\n repositoryPath(repository, `issues/${issueNumber}/comments`),\n { body: input.body },\n { actingUserId: input.actingUserId },\n );\n this.#observeSelfAuthor(comment, input.actingUserId);\n return { id: String(comment.id), url: comment.htmlUrl };\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n async #listPullRequests(input: ListPullRequestsInput) {\n requireGithubConnection(input.connection);\n const page = parsePositiveCursor(input.cursor);\n const query = new URLSearchParams({\n state: input.state ?? 'open',\n page: String(page),\n per_page: String(PAGE_SIZE),\n });\n const result = await this.#client.request<{ pullRequests: GithubPullRequest[] }>(\n 'GET',\n `${repositoryPath(input.sourceId, 'pulls')}?${query}`,\n );\n return {\n pullRequests: result.pullRequests\n .filter(pullRequest => input.includeDrafts !== false || !pullRequest.draft)\n .map(parsePullRequest),\n nextCursor: result.pullRequests.length === PAGE_SIZE ? String(page + 1) : null,\n };\n }\n\n async #getPullRequest(input: PullRequestRef) {\n try {\n return parsePullRequest(\n await this.#client.request<GithubPullRequest>('GET', pullRequestPath(input, input.pullRequestId)),\n );\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n async #createPullRequest(input: CreatePullRequestInput) {\n requireGithubConnection(input.connection);\n const result = await this.#client.request<GithubPullRequest>(\n 'POST',\n repositoryPath(input.sourceId, 'pulls'),\n {\n head: input.headBranch,\n base: input.baseBranch,\n title: input.title,\n body: input.body,\n draft: input.draft,\n },\n { actingUserId: input.actingUserId },\n );\n return parsePullRequest(result);\n }\n\n async #updatePullRequest(input: UpdatePullRequestInput) {\n const result = await this.#client.request<GithubPullRequest>(\n 'PATCH',\n pullRequestPath(input, input.pullRequestId),\n {\n title: input.title,\n body: input.body === null ? '' : input.body,\n base: input.baseBranch,\n state: input.state,\n },\n { actingUserId: input.actingUserId },\n );\n return parsePullRequest(result);\n }\n\n #mergePullRequest(input: MergePullRequestInput) {\n return this.#client.request<{ merged: boolean; message: string; sha: string | null }>(\n 'PUT',\n `${pullRequestPath(input, input.pullRequestId)}/merge`,\n { commitTitle: input.commitTitle, commitMessage: input.commitMessage, method: input.method },\n { actingUserId: input.actingUserId },\n );\n }\n\n async #listComments(input: ListPullRequestCommentsInput) {\n const page = parsePositiveCursor(input.cursor);\n const result = await this.#client.request<{ comments: GithubComment[] }>(\n 'GET',\n `${repositoryPath(input.sourceId, `issues/${requirePositiveId(input.pullRequestId, 'pull request')}/comments`)}?page=${page}&per_page=${PAGE_SIZE}`,\n );\n return {\n comments: result.comments.map(parseComment),\n nextCursor: result.comments.length === PAGE_SIZE ? String(page + 1) : null,\n };\n }\n\n async #createComment(input: CreatePullRequestCommentInput) {\n const comment = await this.#client.request<GithubComment>(\n 'POST',\n repositoryPath(input.sourceId, `issues/${requirePositiveId(input.pullRequestId, 'pull request')}/comments`),\n { body: input.body },\n { actingUserId: input.actingUserId },\n );\n this.#observeSelfAuthor(comment, input.actingUserId);\n return parseComment(comment);\n }\n\n async #updateComment(input: UpdatePullRequestCommentInput) {\n requireGithubConnection(input.connection);\n const comment = await this.#client.request<GithubComment>(\n 'PATCH',\n repositoryPath(input.sourceId, `issues/comments/${requirePositiveId(input.commentId, 'comment')}`),\n { body: input.body },\n { actingUserId: input.actingUserId },\n );\n return parseComment(comment);\n }\n\n async #deleteComment(input: DeletePullRequestCommentInput) {\n requireGithubConnection(input.connection);\n await this.#client.request<void>(\n 'DELETE',\n repositoryPath(input.sourceId, `issues/comments/${requirePositiveId(input.commentId, 'comment')}`),\n undefined,\n { actingUserId: input.actingUserId },\n );\n }\n\n async #listReviews(input: ListReviewsInput) {\n const page = parsePositiveCursor(input.cursor);\n const result = await this.#client.request<{ reviews: GithubReview[] }>(\n 'GET',\n `${pullRequestPath(input, input.pullRequestId)}/reviews?page=${page}&per_page=${PAGE_SIZE}`,\n );\n return {\n reviews: result.reviews.map(parseReview),\n nextCursor: result.reviews.length === PAGE_SIZE ? String(page + 1) : null,\n };\n }\n\n async #getReview(input: ReviewRef) {\n try {\n return parseReview(\n await this.#client.request<GithubReview>(\n 'GET',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}`,\n ),\n );\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n async #createReview(input: CreateReviewInput) {\n const review = await this.#client.request<GithubReview>(\n 'POST',\n `${pullRequestPath(input, input.pullRequestId)}/reviews`,\n { body: input.body, commitId: input.commitId, event: input.event ? reviewEvent(input.event) : undefined },\n { actingUserId: input.actingUserId },\n );\n return parseReview(review);\n }\n\n async #updateReview(input: UpdateReviewInput) {\n const review = await this.#client.request<GithubReview>(\n 'PUT',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}`,\n { body: input.body },\n { actingUserId: input.actingUserId },\n );\n return parseReview(review);\n }\n\n async #submitReview(input: SubmitReviewInput) {\n const review = await this.#client.request<GithubReview>(\n 'POST',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}/events`,\n { body: input.body, event: reviewEvent(input.event) },\n { actingUserId: input.actingUserId },\n );\n return parseReview(review);\n }\n\n async #dismissReview(input: DismissReviewInput) {\n const review = await this.#client.request<GithubReview>(\n 'PUT',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}/dismissals`,\n { message: input.message },\n { actingUserId: input.actingUserId },\n );\n return parseReview(review);\n }\n\n async #deletePendingReview(input: ReviewRef) {\n await this.#client.request<void>(\n 'DELETE',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}`,\n undefined,\n { actingUserId: input.actingUserId },\n );\n }\n\n async #listReviewComments(input: ListReviewCommentsInput) {\n const page = parsePositiveCursor(input.cursor);\n const result = await this.#client.request<{ comments: GithubReviewComment[] }>(\n 'GET',\n `${pullRequestPath(input, input.pullRequestId)}/comments?page=${page}&per_page=${PAGE_SIZE}`,\n );\n return {\n comments: result.comments.map(parseReviewComment),\n nextCursor: result.comments.length === PAGE_SIZE ? String(page + 1) : null,\n };\n }\n\n async #createReviewComment(input: CreateReviewCommentInput) {\n let body: Record<string, unknown>;\n if (input.replyToId !== undefined) {\n body = { body: input.body, replyToId: requirePositiveId(input.replyToId, 'review comment') };\n } else {\n if (!input.commitId || !input.path || input.line === undefined || !input.side) {\n throw new Error('A review comment requires commitId, path, line, and side unless it is a reply.');\n }\n body = {\n body: input.body,\n commitId: input.commitId,\n path: input.path,\n line: input.line,\n side: input.side.toUpperCase(),\n startLine: input.startLine,\n startSide: input.startSide?.toUpperCase(),\n };\n }\n return parseReviewComment(\n await this.#client.request<GithubReviewComment>(\n 'POST',\n `${pullRequestPath(input, input.pullRequestId)}/comments`,\n body,\n { actingUserId: input.actingUserId },\n ),\n );\n }\n\n async #updateReviewComment(input: UpdatePullRequestCommentInput) {\n requireGithubConnection(input.connection);\n return parseReviewComment(\n await this.#client.request<GithubReviewComment>(\n 'PATCH',\n repositoryPath(input.sourceId, `pulls/comments/${requirePositiveId(input.commentId, 'review comment')}`),\n { body: input.body },\n { actingUserId: input.actingUserId },\n ),\n );\n }\n\n async #deleteReviewComment(input: DeletePullRequestCommentInput) {\n requireGithubConnection(input.connection);\n await this.#client.request<void>(\n 'DELETE',\n repositoryPath(input.sourceId, `pulls/comments/${requirePositiveId(input.commentId, 'review comment')}`),\n undefined,\n { actingUserId: input.actingUserId },\n );\n }\n\n #requestedReviewers(method: 'GET' | 'POST' | 'DELETE', input: UpdateReviewersInput) {\n requireGithubConnection(input.connection);\n return this.#client.request<{ users: string[]; teams: string[] }>(\n method,\n `${pullRequestPath(input, input.pullRequestId)}/requested-reviewers`,\n method === 'GET' ? undefined : { users: input.users, teams: input.teams },\n method === 'GET' ? undefined : { actingUserId: input.actingUserId },\n );\n }\n}\n\nfunction repositoryPath(sourceId: string, suffix: string): string {\n const { owner, repo } = splitRepository(sourceId);\n return `${API_PREFIX}/github/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/${suffix}`;\n}\n\nfunction pullRequestPath(\n input: { connection: IntegrationConnection; sourceId: string },\n pullRequestId: string,\n): string {\n requireGithubConnection(input.connection);\n return repositoryPath(input.sourceId, `pulls/${requirePositiveId(pullRequestId, 'pull request')}`);\n}\n\nfunction splitRepository(sourceId: string): { owner: string; repo: string } {\n const slash = sourceId.indexOf('/');\n if (slash <= 0 || slash === sourceId.length - 1) {\n throw new Error('GitHub capabilities require an owner/repository source.');\n }\n return { owner: sourceId.slice(0, slash), repo: sourceId.slice(slash + 1) };\n}\n\nfunction parseIntakeIssue(sourceId: string, issue: GithubIssue): IntakeIssue {\n return {\n id: String(issue.number),\n identifier: `#${issue.number}`,\n title: issue.title,\n url: issue.htmlUrl,\n author: issue.user?.login ?? null,\n state: issue.state,\n stateType: issue.state,\n priority: null,\n assignee: issue.assignees[0] ?? null,\n assignees: issue.assignees,\n source: sourceId,\n labels: issue.labels,\n commentCount: issue.commentCount,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n };\n}\n\nfunction parseIntakeIssueDetail(sourceId: string, issue: GithubIssue, comments: GithubComment[]): IntakeIssueDetail {\n return {\n ...parseIntakeIssue(sourceId, issue),\n description: issue.body?.trim() ? issue.body : null,\n comments: comments.map(comment => ({\n author: comment.user?.login ?? null,\n body: comment.body,\n createdAt: comment.createdAt,\n })),\n };\n}\n\nfunction parsePullRequest(pullRequest: GithubPullRequest): PullRequest {\n return {\n id: String(pullRequest.number),\n title: pullRequest.title,\n url: pullRequest.htmlUrl,\n author: pullRequest.user?.login ?? null,\n assignees: pullRequest.assignees ?? [],\n requestedReviewers: pullRequest.requestedReviewers ?? [],\n labels: pullRequest.labels ?? [],\n body: pullRequest.body?.trim() ? pullRequest.body : null,\n state: pullRequest.state,\n draft: pullRequest.draft,\n merged: pullRequest.merged,\n mergeable: pullRequest.mergeable,\n baseBranch: pullRequest.base.ref,\n headBranch: pullRequest.head.ref,\n headSha: pullRequest.head.sha,\n createdAt: pullRequest.createdAt,\n updatedAt: pullRequest.updatedAt,\n };\n}\n\nfunction parseComment(comment: GithubComment): PullRequestComment {\n return {\n id: String(comment.id),\n url: comment.htmlUrl,\n author: comment.user?.login ?? null,\n body: comment.body,\n createdAt: comment.createdAt,\n updatedAt: comment.updatedAt,\n };\n}\n\nfunction parseReview(review: GithubReview): Review {\n const states: Record<GithubReview['state'], Review['state']> = {\n PENDING: 'pending',\n COMMENTED: 'commented',\n APPROVED: 'approved',\n CHANGES_REQUESTED: 'changes-requested',\n DISMISSED: 'dismissed',\n };\n return {\n id: String(review.id),\n url: review.htmlUrl,\n author: review.user?.login ?? null,\n body: review.body?.trim() ? review.body : null,\n state: states[review.state],\n commitId: review.commitId,\n submittedAt: review.submittedAt,\n };\n}\n\nfunction parseReviewComment(comment: GithubReviewComment): ReviewComment {\n return {\n ...parseComment(comment),\n path: comment.path,\n line: comment.line,\n side: comment.side?.toLowerCase() as 'left' | 'right' | null,\n commitId: comment.commitId,\n replyToId: comment.replyToId === null ? null : String(comment.replyToId),\n };\n}\n\nfunction requireGithubConnection(connection: IntegrationConnection): void {\n if (connection.type !== 'app-installation' && connection.type !== 'oauth') {\n throw new Error('GitHub capabilities require a GitHub connection.');\n }\n}\n\nfunction requireSingleSource(sourceIds: string[], message: string): string {\n if (sourceIds.length !== 1) throw new Error(message);\n return sourceIds[0]!;\n}\n\nfunction requireSource(sourceId: string | undefined, message: string): string {\n if (!sourceId) throw new Error(message);\n return sourceId;\n}\n\nfunction normalizeLabels(labels: string[] | undefined): string[] {\n return [...new Set((labels ?? []).map(label => label.trim()).filter(Boolean))];\n}\n\nfunction parsePositiveCursor(cursor: string | undefined): number {\n if (cursor === undefined) return 1;\n const parsed = parsePositiveInteger(cursor);\n if (parsed === null) throw new Error('GitHub cursor must be a positive page number.');\n return parsed;\n}\n\nfunction parsePositiveInteger(value: string): number | null {\n if (!/^\\d+$/.test(value)) return null;\n const parsed = Number(value);\n return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;\n}\n\nfunction parseGithubExternalTarget(externalId: string): { repository: string; issueId: string } | null {\n const match =\n externalId.match(/^(.+\\/.+):(\\d+)$/) ??\n externalId.match(/^github:(\\d+):(?:issue|pull-request):(\\d+)$/) ??\n externalId.match(/^(\\d+):(\\d+)$/);\n if (!match?.[1] || !match[2] || parsePositiveInteger(match[2]) === null) return null;\n return { repository: match[1], issueId: match[2] };\n}\n\nfunction optionalPositiveIntegerEnv(name: 'MASTRA_PLATFORM_GITHUB_POLLING_INTERVAL_MS'): number | undefined {\n const value = process.env[name]?.trim();\n if (!value) return undefined;\n const parsed = parsePositiveInteger(value);\n if (parsed === null) throw new Error(`${name} must be a positive integer.`);\n return parsed;\n}\n\nfunction requirePositiveId(value: string, resource: string): number {\n const parsed = parsePositiveInteger(value);\n if (parsed === null) throw new Error(`GitHub ${resource} id must be a positive integer.`);\n return parsed;\n}\n\nfunction reviewEvent(event: 'approve' | 'request-changes' | 'comment') {\n if (event === 'approve') return 'APPROVE' as const;\n if (event === 'request-changes') return 'REQUEST_CHANGES' as const;\n return 'COMMENT' as const;\n}\n\nfunction isNotFound(error: unknown): boolean {\n return error instanceof PlatformApiError && error.status === 404;\n}\n\n// Platform answers 404 when the installation row is gone, 409 when it is suspended or soft-deleted.\n// A 502 also covers a dead installation but is indistinguishable from a transient GitHub outage.\nfunction isDeadInstallation(error: unknown): boolean {\n return error instanceof PlatformApiError && (error.status === 404 || error.status === 409);\n}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ntervalMs","#pullRequestReconcileEnabled","#issueReconcileEnabled","#pullRequestReconcileIntervalMs","#issueReconcileIntervalMs","#installationReposCache","#repositoryAccessCache","#collaboratorPermissionCache","#collaboratorPermissionInFlight","#resolveIntakeDispatch","#listIssues","#listPullRequests","#getIssue","#createIssueComment","#updateIntakeIssue","#storage","#getPullRequest","#createPullRequest","#updatePullRequest","#mergePullRequest","#listComments","#createComment","#updateComment","#deleteComment","#listReviews","#getReview","#createReview","#updateReview","#submitReview","#dismissReview","#deletePendingReview","#listReviewComments","#createReviewComment","#updateReviewComment","#deleteReviewComment","#requestedReviewers","#integrationStorage","#statusRoute","#connectRoute","#connectUserRoute","#syncInstallations","#fetchUserConnection","#observeSelfAuthor"],"sources":["../../../../src/integrations/platform/github/integration.ts"],"sourcesContent":["import type { RequestContext } from '@mastra/core/request-context';\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { MastraWorker } from '@mastra/core/worker';\nimport type { Context } from 'hono';\n\nimport type { IntegrationConnection } from '../../../capabilities/connection.js';\nimport type {\n CreateIntakeCommentInput,\n Intake,\n IntakeIssue,\n IntakeIssueDetail,\n UpdateIntakeIssueInput,\n} from '../../../capabilities/intake.js';\nimport type {\n CreatePullRequestCommentInput,\n CreatePullRequestInput,\n CreateReviewCommentInput,\n CreateReviewInput,\n DeletePullRequestCommentInput,\n DismissReviewInput,\n ListPullRequestCommentsInput,\n ListPullRequestsInput,\n ListReviewCommentsInput,\n ListReviewsInput,\n MergePullRequestInput,\n PullRequest,\n PullRequestComment,\n PullRequestRef,\n RepositoryAccess,\n Review,\n ReviewComment,\n ReviewRef,\n SubmitReviewInput,\n UpdatePullRequestCommentInput,\n UpdatePullRequestInput,\n UpdateReviewInput,\n UpdateReviewersInput,\n VersionControl,\n} from '../../../capabilities/version-control.js';\nimport type { IntegrationStorageHandle } from '../../../storage/domains/integrations/base.js';\nimport type {\n SourceControlInstallation,\n SourceControlStorageHandle,\n} from '../../../storage/domains/source-control/base.js';\nimport type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../../base.js';\nimport { GithubAppIdentity } from '../../github/app-identity.js';\nimport type {\n GithubIntegration,\n GithubRepositoryPermission,\n GithubTriageCommentUpsertInput,\n GithubTriageCommentUpsertResult,\n RepoSummary,\n} from '../../github/integration.js';\nimport { attachGithubIssueReconciler } from '../../github/issue-reconciler.js';\nimport { reconcileInterval, reconciliationEnabled } from '../../github/reconciliation-config.js';\nimport { buildGithubRoutes } from '../../github/routes.js';\nimport { attachGithubReconciler, attachGithubRules } from '../../github/rules.js';\nimport type { ReconcileIssueState, ReconcilePullRequestState } from '../../github/rules.js';\nimport {\n createGithubSubscriptionTools,\n parseCreatedPullRequest,\n subscribeCurrentSessionToPullRequest,\n} from '../../github/session-subscriptions.js';\nimport { settleOrAbort } from '../../github/settle-or-abort.js';\nimport type { GithubSubscriptionStorage } from '../../github/subscriptions.js';\nimport { parseAuthorizedBotsEnv } from '../../github/webhook.js';\nimport {\n logPlatformInfo,\n logPlatformWarn,\n PlatformApiClient,\n PlatformApiError,\n platformApiClientConfigFromEnv,\n} from '../api-client.js';\nimport { PlatformGithubEventWorker } from './event-worker.js';\nimport type { PlatformGithubEventStorage } from './event-worker.js';\n\ntype GithubActor = { login: string; avatarUrl: string | null; htmlUrl: string | null } | null;\n\ntype PlatformGithubInstallation = {\n installationId: number;\n accountLogin: string;\n accountType: string;\n suspendedAt: string | null;\n usable: boolean;\n};\n\ntype PlatformGithubUserConnection = {\n connected: boolean;\n githubUsername: string | null;\n reason?: 'token-invalid' | 'no-accessible-installation' | 'missing-permissions' | 'verification-unavailable' | null;\n};\n\ntype GithubIssue = {\n number: number;\n state: 'open' | 'closed';\n title: string;\n body: string | null;\n htmlUrl: string;\n labels: string[];\n assignees: string[];\n commentCount: number;\n user: GithubActor;\n createdAt: string;\n updatedAt: string;\n};\n\ntype GithubComment = {\n id: number;\n body: string;\n htmlUrl: string;\n user: GithubActor;\n createdAt: string;\n updatedAt: string;\n};\n\ntype GithubPullRequest = {\n number: number;\n title: string;\n body: string | null;\n state: 'open' | 'closed';\n htmlUrl: string;\n merged: boolean;\n mergeable: boolean | null;\n draft: boolean;\n head: { ref: string; sha: string };\n base: { ref: string; repo: { id: number; fullName: string } };\n user: GithubActor;\n assignees?: string[];\n requestedReviewers?: string[];\n labels?: string[];\n createdAt: string;\n updatedAt: string;\n};\n\ntype GithubReview = {\n id: number;\n htmlUrl: string | null;\n body: string | null;\n state: 'PENDING' | 'COMMENTED' | 'APPROVED' | 'CHANGES_REQUESTED' | 'DISMISSED';\n commitId: string | null;\n submittedAt: string | null;\n user: GithubActor;\n};\n\ntype GithubReviewComment = GithubComment & {\n path: string;\n line: number | null;\n side: 'LEFT' | 'RIGHT' | null;\n commitId: string;\n replyToId: number | null;\n};\n\nconst PAGE_SIZE = 30;\nconst API_PREFIX = '/v1/server';\n/**\n * Slug of the GitHub App this integration posts as. Platform credentials do not\n * carry their own identity, so Factory cannot otherwise recognise its own\n * writes — and failing to recognise them makes Factory wake itself. Override\n * with `MASTRA_PLATFORM_GITHUB_APP_SLUG` when pointing at a non-production App.\n */\nconst PLATFORM_GITHUB_APP_SLUG = 'mastra-platform';\n/**\n * How long an installation's repository listing may be reused. The repos\n * route and token minting both call it — often several times within one UI\n * interaction — and each call is a full Platform round trip.\n */\nconst INSTALLATION_REPOS_CACHE_TTL_MS = 30_000;\n/**\n * How long a minted repository-scoped token may be reused. GitHub\n * installation tokens live ~60 minutes; 5 minutes keeps a wide validity\n * margin while collapsing the per-session-materialization mint round trip.\n */\nconst REPOSITORY_ACCESS_CACHE_TTL_MS = 5 * 60_000;\n/**\n * How long a collaborator permission lookup may be reused. The reconcile\n * sweep re-stamps every open card's author and the event tail gates every\n * human-authored event on it, so one login can cost dozens of identical\n * requests per cycle against the installation's REST budget. Revoked access\n * reads as trusted for at most this long.\n */\nconst COLLABORATOR_PERMISSION_CACHE_TTL_MS = 30 * 60_000;\n/** Bound on the shared upstream lookup; callers race their own signal against it. */\nconst COLLABORATOR_PERMISSION_LOOKUP_TIMEOUT_MS = 10_000;\n/**\n * Upper bound for both TTL caches. Entries expire lazily on re-access, so\n * without a hard cap keys that stop being queried would accumulate for the\n * integration's (long) lifetime. Insertion-order eviction — matches the\n * bounded verification cache in `@mastra/auth-studio`.\n */\nconst MAX_CACHE_ENTRIES = 1000;\n\nfunction setBounded<K, V>(cache: Map<K, V>, key: K, value: V): void {\n cache.delete(key);\n cache.set(key, value);\n if (cache.size > MAX_CACHE_ENTRIES) {\n const oldest = cache.keys().next().value;\n if (oldest !== undefined) cache.delete(oldest);\n }\n}\n\nconst REPOSITORY_TOKEN_PERMISSIONS = {\n contents: 'write',\n issues: 'write',\n pull_requests: 'write',\n} as const;\n\nfunction loose(c: unknown): Context {\n return c as Context;\n}\n\nfunction routeBaseUrl(ctx: IntegrationContext, requestUrl: string): string {\n return (ctx.baseUrl || new URL(requestUrl).origin).replace(/\\/+$/, '');\n}\n\nexport class PlatformGithubIntegration implements FactoryIntegration {\n readonly id = 'github';\n readonly #client: PlatformApiClient;\n readonly #endpointHost: string;\n readonly #slug: string | undefined;\n /**\n * Factory's own GitHub identity. Platform credentials do not carry the login\n * they post as, so this starts from the configured slug (usually absent on a\n * Platform deployment) and is corrected the first time Factory writes.\n */\n readonly identity: GithubAppIdentity;\n /**\n * Extra reviewer bot logins this deployment trusts for author-gated\n * notifications, merged over the built-in defaults.\n */\n readonly authorizedBots: readonly string[];\n readonly #pollingEnabled: boolean;\n readonly #pollingIntervalMs: number | undefined;\n readonly #pullRequestReconcileEnabled: boolean;\n readonly #issueReconcileEnabled: boolean;\n readonly #pullRequestReconcileIntervalMs: number | undefined;\n readonly #issueReconcileIntervalMs: number | undefined;\n #storage: SourceControlStorageHandle | undefined;\n #integrationStorage: GithubSubscriptionStorage | undefined;\n /** installationId → cached repository listing (TTL-bounded). */\n readonly #installationReposCache = new Map<number, { repos: RepoSummary[]; expiresAt: number }>();\n /** `orgId:repositoryId` → cached repository access (TTL-bounded). */\n readonly #repositoryAccessCache = new Map<string, { access: RepositoryAccess; expiresAt: number }>();\n /** `owner/repo:login` → cached collaborator permission (TTL-bounded). */\n readonly #collaboratorPermissionCache = new Map<\n string,\n { permission: GithubRepositoryPermission; expiresAt: number }\n >();\n /** Same key → lookup already in flight, so overlapping callers share one request. */\n readonly #collaboratorPermissionInFlight = new Map<string, Promise<GithubRepositoryPermission | undefined>>();\n\n readonly intake: Intake = {\n resolveIntakeDispatch: input => this.#resolveIntakeDispatch(input),\n listSources: async ({ orgId, userId }) => {\n const installations = await this.#client.request<{\n installations: Array<{\n installationId: number;\n accountLogin: string;\n accountType: string;\n suspendedAt: string | null;\n usable: boolean;\n }>;\n }>('GET', `${API_PREFIX}/github-app/installations`);\n const usable = installations.installations.filter(\n installation => installation.usable && !installation.suspendedAt,\n );\n const repositories = await Promise.all(\n usable.map(async installation => {\n const storedInstallation = await this.versionControl.registerInstallation({\n orgId,\n userId,\n installation: {\n externalId: String(installation.installationId),\n accountName: installation.accountLogin,\n accountType: installation.accountType,\n },\n });\n const result = await this.#client.request<{\n repositories: Array<{\n id: number;\n fullName: string;\n private: boolean;\n defaultBranch: string;\n htmlUrl: string;\n }>;\n }>('GET', `${API_PREFIX}/github-app/installations/${installation.installationId}/repositories`);\n await this.versionControl.registerRepositories({\n orgId,\n installationId: storedInstallation.id,\n repositories: result.repositories.map(repository => ({\n externalId: String(repository.id),\n slug: repository.fullName,\n defaultBranch: repository.defaultBranch,\n metadata: { private: repository.private, url: repository.htmlUrl },\n })),\n });\n return result.repositories.map(repository => ({ repository, installation }));\n }),\n );\n return repositories.flat().map(({ repository, installation }) => ({\n id: repository.fullName,\n name: repository.fullName,\n type: 'repository',\n metadata: {\n installationId: installation.installationId,\n accountLogin: installation.accountLogin,\n accountType: installation.accountType,\n repositoryId: repository.id,\n defaultBranch: repository.defaultBranch,\n private: repository.private,\n url: repository.htmlUrl,\n },\n }));\n },\n listItems: async ({ sourceIds, cursor }) => {\n const page = parsePositiveCursor(cursor);\n const pages = await Promise.all(\n sourceIds.map(async sourceId => {\n const connection = { type: 'app-installation' as const, installationId: 1 };\n const [issues, pullRequests] = await Promise.all([\n this.#listIssues(connection, sourceId, page),\n this.#listPullRequests({ connection, sourceId, includeDrafts: false, cursor: String(page) }),\n ]);\n return {\n items: [\n ...issues.issues.map(issue => ({\n source: { type: 'issue', externalId: `${sourceId}:${issue.id}`, url: issue.url },\n sourceId,\n title: 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: { repository: sourceId, number: Number(issue.id), author: issue.author },\n })),\n ...pullRequests.pullRequests.map(pullRequest => ({\n source: { type: 'pull-request', externalId: `${sourceId}:${pullRequest.id}`, url: pullRequest.url },\n sourceId,\n title: pullRequest.title,\n status: pullRequest.state,\n createdAt: pullRequest.createdAt,\n updatedAt: pullRequest.updatedAt,\n metadata: {\n repository: sourceId,\n number: Number(pullRequest.id),\n author: pullRequest.author,\n baseBranch: pullRequest.baseBranch,\n headBranch: pullRequest.headBranch,\n },\n })),\n ],\n hasNextPage: issues.nextCursor !== null || pullRequests.nextCursor !== null,\n };\n }),\n );\n return {\n items: pages.flatMap(result => result.items),\n nextCursor: pages.some(result => result.hasNextPage) ? String(page + 1) : null,\n };\n },\n listIssues: async input => {\n requireGithubConnection(input.connection);\n const sourceId = requireSingleSource(input.sourceIds, 'GitHub Intake requires exactly one repository source.');\n return this.#listIssues(input.connection, sourceId, parsePositiveCursor(input.cursor), input.labels);\n },\n getIssue: input => this.#getIssue(input.connection, input.sourceId, input.issueId),\n createComment: input => this.#createIssueComment(input),\n updateIssue: input => this.#updateIntakeIssue(input),\n };\n\n readonly versionControl: VersionControl = {\n initialize: ({ storage }) => {\n this.#storage = storage;\n },\n registerInstallation: ({ orgId, userId, installation }) =>\n this.storage.installations.upsert({\n orgId,\n connectedByUserId: userId,\n externalId: installation.externalId,\n accountName: installation.accountName,\n accountType: installation.accountType,\n providerMetadata: installation.metadata,\n }),\n registerRepositories: ({ orgId, installationId, repositories }) =>\n Promise.all(\n repositories.map(repository =>\n this.storage.repositories.upsert({\n orgId,\n input: {\n installationId,\n externalId: repository.externalId,\n slug: repository.slug,\n defaultBranch: repository.defaultBranch,\n providerMetadata: repository.metadata,\n },\n }),\n ),\n ),\n getRepositoryAccess: async ({ orgId, repositoryId }) => {\n // Every session materialization requests access; reuse a recent grant\n // instead of re-minting through the Platform each time. The TTL keeps\n // a wide margin under GitHub's ~60min installation-token lifetime.\n const cacheKey = `${orgId}:${repositoryId}`;\n const cached = this.#repositoryAccessCache.get(cacheKey);\n if (cached && cached.expiresAt > Date.now()) return cached.access;\n this.#repositoryAccessCache.delete(cacheKey);\n\n const repository = await this.storage.repositories.get({ orgId, id: repositoryId });\n if (!repository) throw new Error('Version-control repository not found.');\n const cloneUrl = `https://github.com/${repository.slug}.git`;\n const installation = await this.storage.installations.get({ orgId, id: repository.installationId });\n if (!installation) throw new Error('Version-control installation not found.');\n const installationId = parsePositiveInteger(installation.externalId);\n if (installationId === null) throw new Error('GitHub installation id is invalid.');\n const repositoryName = splitRepository(repository.slug).repo;\n\n try {\n const token = await this.#client.request<{ token: string }>(\n 'POST',\n `${API_PREFIX}/github-app/installations/${installationId}/token`,\n { repositories: [repositoryName], permissions: REPOSITORY_TOKEN_PERMISSIONS },\n );\n const access: RepositoryAccess = {\n cloneUrl,\n authorization: { scheme: 'bearer', token: token.token },\n };\n setBounded(this.#repositoryAccessCache, cacheKey, {\n access,\n expiresAt: Date.now() + REPOSITORY_ACCESS_CACHE_TTL_MS,\n });\n return access;\n } catch (err) {\n // Recover from stale installation: when a GitHub App is uninstalled and reinstalled,\n // GitHub assigns a new installation ID. Platform creates a new installation row,\n // and Factory's intake.listSources creates a new local installation row with the\n // new externalId. Try to find the new installation by accountName.\n if (!isDeadInstallation(err) || !installation.accountName) throw err;\n const installations = await this.storage.installations.list({ orgId });\n const newInstallation = installations.find(\n inst => inst.accountName === installation.accountName && inst.id !== installation.id,\n );\n if (!newInstallation) throw err;\n const newInstallationId = parsePositiveInteger(newInstallation.externalId);\n if (newInstallationId === null) throw err;\n\n // Persist the migration so we don't hit the recovery path on every call.\n await this.storage.repositories.migrateInstallation({\n orgId,\n id: repositoryId,\n newInstallationId: newInstallation.id,\n });\n\n const token = await this.#client.request<{ token: string }>(\n 'POST',\n `${API_PREFIX}/github-app/installations/${newInstallationId}/token`,\n { repositories: [repositoryName], permissions: REPOSITORY_TOKEN_PERMISSIONS },\n );\n const access: RepositoryAccess = {\n cloneUrl,\n authorization: { scheme: 'bearer', token: token.token },\n };\n setBounded(this.#repositoryAccessCache, cacheKey, {\n access,\n expiresAt: Date.now() + REPOSITORY_ACCESS_CACHE_TTL_MS,\n });\n return access;\n }\n },\n listPullRequests: input => this.#listPullRequests(input),\n getPullRequest: input => this.#getPullRequest(input),\n createPullRequest: input => this.#createPullRequest(input),\n updatePullRequest: input => this.#updatePullRequest(input),\n closePullRequest: input => this.#updatePullRequest({ ...input, state: 'closed' }),\n mergePullRequest: input => this.#mergePullRequest(input),\n listComments: input => this.#listComments(input),\n createComment: input => this.#createComment(input),\n updateComment: input => this.#updateComment(input),\n deleteComment: input => this.#deleteComment(input),\n listReviews: input => this.#listReviews(input),\n getReview: input => this.#getReview(input),\n createReview: input => this.#createReview(input),\n updateReview: input => this.#updateReview(input),\n submitReview: input => this.#submitReview(input),\n dismissReview: input => this.#dismissReview(input),\n deletePendingReview: input => this.#deletePendingReview(input),\n listReviewComments: input => this.#listReviewComments(input),\n createReviewComment: input => this.#createReviewComment(input),\n updateReviewComment: input => this.#updateReviewComment(input),\n deleteReviewComment: input => this.#deleteReviewComment(input),\n listRequestedReviewers: input => this.#requestedReviewers('GET', input),\n requestReviewers: input => this.#requestedReviewers('POST', input),\n removeRequestedReviewers: input => this.#requestedReviewers('DELETE', input),\n };\n\n constructor(\n options: {\n /** GitHub App slug used to recognize Factory's own webhook writes. */\n slug?: string;\n } = {},\n ) {\n const config = platformApiClientConfigFromEnv();\n this.#client = new PlatformApiClient(config);\n this.#endpointHost = new URL(config.baseUrl).host;\n this.#slug = options.slug;\n // Identity is deliberately NOT taken from `options.slug`. That slug names\n // the deployment's own self-hosted GitHub App, which is a different App\n // than the one this integration posts as — and on a Platform deployment it\n // is legitimately unset. Borrowing it is what left every self-loop guard\n // comparing against `undefined[bot]`. This integration *is* the Platform\n // App, so it names itself, with an override for non-production Apps.\n this.identity = new GithubAppIdentity(\n process.env.MASTRA_PLATFORM_GITHUB_APP_SLUG?.trim() || PLATFORM_GITHUB_APP_SLUG,\n );\n this.authorizedBots = parseAuthorizedBotsEnv(process.env.MASTRACODE_GITHUB_AUTHORIZED_BOTS) ?? [];\n this.#pollingEnabled = process.env.MASTRA_PLATFORM_GITHUB_POLLING_ENABLED?.trim().toLowerCase() !== 'false';\n this.#pollingIntervalMs = optionalPositiveIntegerEnv('MASTRA_PLATFORM_GITHUB_POLLING_INTERVAL_MS');\n const legacyReconcileEnabled = process.env.MASTRA_PLATFORM_GITHUB_RECONCILE_ENABLED;\n this.#pullRequestReconcileEnabled = reconciliationEnabled(\n process.env.MASTRACODE_PLATFORM_GITHUB_PR_RECONCILE_ENABLED,\n legacyReconcileEnabled,\n );\n this.#issueReconcileEnabled = reconciliationEnabled(\n process.env.MASTRACODE_PLATFORM_GITHUB_ISSUE_RECONCILE_ENABLED,\n legacyReconcileEnabled,\n );\n const legacyReconcileIntervalMs = reconcileInterval(process.env.MASTRACODE_PLATFORM_GITHUB_RECONCILE_INTERVAL_MS);\n this.#pullRequestReconcileIntervalMs =\n reconcileInterval(process.env.MASTRACODE_PLATFORM_GITHUB_PR_RECONCILE_INTERVAL_MS) ?? legacyReconcileIntervalMs;\n this.#issueReconcileIntervalMs =\n reconcileInterval(process.env.MASTRACODE_PLATFORM_GITHUB_ISSUE_RECONCILE_INTERVAL_MS) ?? legacyReconcileIntervalMs;\n }\n\n /** GitHub App slug when the deployment explicitly provides it. */\n get slug(): string | undefined {\n return this.#slug;\n }\n\n isFactoryCommentAuthor(login: string | null | undefined): boolean {\n return typeof login === 'string' && this.identity.matches(login);\n }\n\n get storage(): SourceControlStorageHandle {\n if (!this.#storage) throw new Error('PlatformGithubIntegration source-control storage has not been initialized.');\n return this.#storage;\n }\n\n get sourceControlStorage(): SourceControlStorageHandle {\n return this.storage;\n }\n\n get integrationStorage(): GithubSubscriptionStorage {\n if (!this.#integrationStorage) {\n throw new Error('PlatformGithubIntegration generic storage has not been initialized.');\n }\n return this.#integrationStorage;\n }\n\n /** Resolve a stored GitHub locator without scanning installations or repositories. */\n async #resolveIntakeDispatch({\n orgId,\n externalSource,\n }: {\n orgId: string;\n externalSource: { type: string; externalId: string };\n }): Promise<{ connection: IntegrationConnection; sourceId: string; issueId: string } | null> {\n const target = parseGithubExternalTarget(externalSource.externalId);\n if (!target) return null;\n const repository = target.repository.includes('/')\n ? target.repository\n : (await this.storage.repositories.findByExternalId({ orgId, externalId: target.repository }))?.slug;\n if (!repository) return null;\n return {\n connection: { type: 'app-installation', installationId: 1 },\n sourceId: repository,\n issueId: target.issueId,\n };\n }\n\n initialize({ storage }: { storage: IntegrationStorageHandle }): void {\n this.#integrationStorage = storage as unknown as GithubSubscriptionStorage;\n logPlatformInfo('Platform GitHub integration initialized', {\n endpointHost: this.#endpointHost,\n pollingEnabled: this.#pollingEnabled,\n pollingIntervalMs: this.#pollingIntervalMs,\n pullRequestReconcileEnabled: this.#pullRequestReconcileEnabled,\n issueReconcileEnabled: this.#issueReconcileEnabled,\n });\n }\n\n routes(ctx: IntegrationContext): ApiRoute[] {\n const ingestFactoryEvent = attachGithubRules(this, ctx);\n return [\n this.#statusRoute(ctx),\n this.#connectRoute(ctx),\n this.#connectUserRoute(ctx),\n ...buildGithubRoutes({\n auth: ctx.auth,\n sandbox: ctx.sandbox,\n storage: ctx.factoryStorage,\n github: this as unknown as GithubIntegration,\n stateSigner: ctx.stateSigner,\n baseUrl: ctx.baseUrl,\n controller: ctx.controller,\n memorySettings: ctx.storage.memorySettings,\n projects: ctx.storage.projects,\n emitAudit: ctx.hooks?.emitAudit,\n ingestFactoryEvent,\n ...(ctx.workItems ? { workItems: ctx.workItems } : {}),\n }).filter(\n route =>\n route.path !== '/web/github/status' &&\n route.path !== '/web/github/webhook' &&\n !route.path.startsWith('/auth/github/'),\n ),\n ];\n }\n\n #statusRoute(ctx: IntegrationContext): ApiRoute {\n return registerApiRoute('/web/github/status', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n await ctx.auth.ensureUser(loose(c));\n const tenant = ctx.auth.tenant(loose(c));\n if (!tenant) return c.json({ error: 'unauthorized', reason: 'auth_required' }, 401);\n if (!tenant.orgId) {\n return c.json({\n enabled: true,\n sandboxEnabled: !!ctx.sandbox,\n organizationRequired: true,\n connected: false,\n installations: [],\n userConnected: false,\n userGithubUsername: null,\n reason: 'organization_required',\n diagnostics: this.diagnostics(),\n });\n }\n\n const [installations, userConnection] = await Promise.all([\n this.#syncInstallations(tenant.orgId, tenant.userId),\n this.#fetchUserConnection(tenant.userId),\n ]);\n return c.json({\n enabled: true,\n sandboxEnabled: !!ctx.sandbox,\n connected: installations.length > 0,\n installations: installations.map(installation => ({\n installationId: Number(installation.externalId),\n accountLogin: installation.accountName,\n accountType: installation.accountType,\n })),\n userConnected: userConnection.connected,\n userGithubUsername: userConnection.githubUsername,\n reason: installations.length > 0 ? 'ready' : 'not_connected',\n diagnostics: this.diagnostics(),\n });\n },\n });\n }\n\n #connectRoute(ctx: IntegrationContext): ApiRoute {\n return registerApiRoute('/auth/github/connect', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n await ctx.auth.ensureUser(loose(c));\n const tenant = ctx.auth.tenant(loose(c));\n if (!tenant?.orgId) return c.json({ error: 'unauthorized' }, 401);\n\n const redirectTo = c.req.query('redirectTo') || c.req.query('return_to') || '/';\n const originator = routeBaseUrl(ctx, c.req.url);\n logPlatformInfo('Starting Platform GitHub connect flow', {\n orgId: tenant.orgId,\n redirectTo,\n originator,\n });\n const query = new URLSearchParams({\n action: 'install',\n redirectTo,\n originator,\n });\n const { url } = await this.#client.request<{ url: string }>(\n 'GET',\n `${API_PREFIX}/github-app/install-url?${query}`,\n );\n return c.redirect(url);\n },\n });\n }\n\n #connectUserRoute(ctx: IntegrationContext): ApiRoute {\n return registerApiRoute('/auth/github/connect-user', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n await ctx.auth.ensureUser(loose(c));\n const tenant = ctx.auth.tenant(loose(c));\n if (!tenant?.orgId) return c.json({ error: 'unauthorized' }, 401);\n\n const redirectTo = c.req.query('redirectTo') || c.req.query('return_to') || '/';\n const originator = routeBaseUrl(ctx, c.req.url);\n logPlatformInfo('Starting Platform GitHub user authorization flow', {\n orgId: tenant.orgId,\n redirectTo,\n originator,\n });\n const query = new URLSearchParams({\n userId: tenant.userId,\n redirectTo,\n originator,\n });\n const { url } = await this.#client.request<{ url: string }>(\n 'GET',\n `${API_PREFIX}/github-app/authenticate?${query}`,\n );\n return c.redirect(url);\n },\n });\n }\n\n /**\n * Personal GitHub connection status for the acting user. Returns\n * not-connected when the platform predates the user-connection endpoint.\n */\n async #fetchUserConnection(userId: string): Promise<PlatformGithubUserConnection> {\n try {\n const connection = await this.#client.request<PlatformGithubUserConnection>(\n 'GET',\n `${API_PREFIX}/github-app/user-connection?${new URLSearchParams({ userId })}`,\n );\n if (!connection.connected && connection.reason) {\n logPlatformWarn('Platform GitHub user connection verification failed', {\n userId,\n reason: connection.reason,\n });\n }\n return connection;\n } catch {\n return { connected: false, githubUsername: null };\n }\n }\n\n async #syncInstallations(orgId: string, userId: string): Promise<SourceControlInstallation[]> {\n const result = await this.#client.request<{ installations: PlatformGithubInstallation[] }>(\n 'GET',\n `${API_PREFIX}/github-app/installations`,\n );\n const usableInstallations = result.installations.filter(\n installation => installation.usable && !installation.suspendedAt,\n );\n return Promise.all(\n usableInstallations.map(installation =>\n this.versionControl.registerInstallation({\n orgId,\n userId,\n installation: {\n externalId: String(installation.installationId),\n accountName: installation.accountLogin,\n accountType: installation.accountType,\n },\n }),\n ),\n );\n }\n\n workers(ctx: IntegrationContext): MastraWorker[] {\n if (!this.#pollingEnabled && !this.#pullRequestReconcileEnabled && !this.#issueReconcileEnabled) return [];\n if (!ctx.controller) {\n throw new Error('Platform GitHub event polling requires the mounted Mastra Code controller.');\n }\n return [\n new PlatformGithubEventWorker({\n client: this.#client,\n controller: ctx.controller,\n github: this,\n storage: ctx.storage.generic as unknown as PlatformGithubEventStorage,\n ingestFactoryEvent: attachGithubRules(this, ctx),\n reconcileFactoryState: this.#pullRequestReconcileEnabled\n ? attachGithubReconciler(this, ctx, input => this.fetchPullRequestState(input))\n : undefined,\n reconcileIssuesFactoryState: this.#issueReconcileEnabled\n ? attachGithubIssueReconciler(this, ctx, input => this.fetchIssueState(input))\n : undefined,\n pollEventsEnabled: this.#pollingEnabled,\n intervalMs: this.#pollingIntervalMs,\n pullRequestReconcileIntervalMs: this.#pullRequestReconcileIntervalMs,\n issueReconcileIntervalMs: this.#issueReconcileIntervalMs,\n // Resolved lazily: workers are constructed before versionControl\n // storage is initialized, and the worker only reads these slices once\n // it is running.\n sourceControl: {\n projectRepositories: {\n listConfiguredExternalKeys: () => this.storage.projectRepositories.listConfiguredExternalKeys(),\n listByExternalRepository: args => this.storage.projectRepositories.listByExternalRepository(args),\n },\n repositories: {\n findByExternalId: args => this.storage.repositories.findByExternalId(args),\n },\n },\n }),\n ];\n }\n\n /**\n * Reads live PR state through the Platform GitHub proxy for the merge\n * reconciler. Returns undefined when the PR cannot be resolved (missing,\n * proxy error) so a sweep never fabricates a merge.\n */\n async fetchPullRequestState(input: {\n installationId: number;\n repository: string;\n number: number;\n }): Promise<ReconcilePullRequestState | undefined> {\n let repository: { owner: string; repo: string };\n try {\n repository = splitRepository(input.repository);\n } catch {\n return undefined;\n }\n try {\n const result = await this.#client.request<{\n title?: string;\n html_url?: string;\n state?: string;\n draft?: boolean;\n merged?: boolean;\n created_at?: string;\n user?: { login?: string } | null;\n assignees?: Array<{ login?: string }> | null;\n requested_reviewers?: Array<{ login?: string }> | null;\n labels?: Array<{ name?: string } | string> | null;\n merged_by?: { login?: string } | null;\n head?: { ref?: string };\n base?: { ref?: string };\n }>(\n 'GET',\n `${API_PREFIX}/github/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}/pulls/${input.number}`,\n );\n return {\n title: result.title ?? `PR ${input.number}`,\n url: result.html_url ?? `https://github.com/${input.repository}/pull/${input.number}`,\n state: result.state === 'closed' ? 'closed' : 'open',\n draft: result.draft === true,\n merged: result.merged === true,\n assignees: (result.assignees ?? []).flatMap(assignee => (assignee.login ? [assignee.login] : [])),\n requestedReviewers: (result.requested_reviewers ?? []).flatMap(reviewer =>\n reviewer.login ? [reviewer.login] : [],\n ),\n labels: (result.labels ?? []).flatMap(label =>\n typeof label === 'string' ? [label] : label.name ? [label.name] : [],\n ),\n headBranch: result.head?.ref ?? '',\n baseBranch: result.base?.ref ?? '',\n ...(result.user?.login ? { author: result.user.login } : {}),\n ...(result.created_at ? { createdAt: result.created_at } : {}),\n ...(result.merged_by?.login ? { mergedBy: result.merged_by.login } : {}),\n };\n } catch {\n return undefined;\n }\n }\n\n /**\n * Reads live issue state through the Platform GitHub proxy for the\n * reconciler. Returns undefined when the issue cannot be resolved (missing,\n * is actually a PR, proxy error) so a sweep never fabricates a close.\n */\n async fetchIssueState(input: {\n installationId: number;\n repository: string;\n number: number;\n }): Promise<ReconcileIssueState | undefined> {\n let repository: { owner: string; repo: string };\n try {\n repository = splitRepository(input.repository);\n } catch {\n return undefined;\n }\n try {\n const result = await this.#client.request<{\n title?: string;\n html_url?: string;\n state?: string;\n state_reason?: string | null;\n created_at?: string;\n updated_at?: string;\n user?: { login?: string } | null;\n assignees?: Array<{ login?: string }> | null;\n labels?: Array<{ name?: string } | string> | null;\n pull_request?: unknown;\n }>(\n 'GET',\n `${API_PREFIX}/github/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}/issues/${input.number}`,\n );\n if (result.pull_request) return undefined;\n return {\n title: result.title ?? `Issue ${input.number}`,\n url: result.html_url ?? `https://github.com/${input.repository}/issues/${input.number}`,\n state: result.state === 'closed' ? 'closed' : 'open',\n ...(result.state_reason ? { stateReason: result.state_reason } : {}),\n assignees: (result.assignees ?? []).flatMap(assignee => (assignee.login ? [assignee.login] : [])),\n labels: (result.labels ?? []).map(label => (typeof label === 'string' ? label : label.name)).filter((name): name is string => Boolean(name)),\n ...(result.user?.login ? { author: result.user.login } : {}),\n ...(result.created_at ? { createdAt: result.created_at } : {}),\n ...(result.updated_at ? { updatedAt: result.updated_at } : {}),\n };\n } catch {\n return undefined;\n }\n }\n\n async upsertFactoryTriageComment(input: GithubTriageCommentUpsertInput): Promise<GithubTriageCommentUpsertResult> {\n const comments: GithubComment[] = [];\n for (let page = 1; ; page += 1) {\n const query = new URLSearchParams({ page: String(page), per_page: String(PAGE_SIZE) });\n const result = await this.#client.request<{ comments: GithubComment[] }>(\n 'GET',\n `${repositoryPath(input.repository, `issues/${input.issueNumber}/comments`)}?${query}`,\n );\n comments.push(...result.comments);\n if (result.comments.length < PAGE_SIZE) break;\n }\n const existing = comments\n .filter(comment => comment.body.includes('<!-- mastra-factory-triage -->') && this.isFactoryCommentAuthor(comment.user?.login))\n .sort((left, right) => left.id - right.id)[0];\n if (existing) {\n const comment = await this.#client.request<GithubComment>(\n 'PATCH',\n repositoryPath(input.repository, `issues/comments/${existing.id}`),\n { body: input.body },\n );\n this.#observeSelfAuthor(comment, undefined);\n return { action: 'updated', commentId: String(comment.id), url: comment.htmlUrl };\n }\n const comment = await this.#client.request<GithubComment>(\n 'POST',\n repositoryPath(input.repository, `issues/${input.issueNumber}/comments`),\n { body: input.body },\n );\n this.#observeSelfAuthor(comment, undefined);\n return { action: 'created', commentId: String(comment.id), url: comment.htmlUrl };\n }\n\n sessionTools({ requestContext }: { requestContext: RequestContext }): IntegrationTools {\n return createGithubSubscriptionTools(requestContext, this as unknown as GithubIntegration);\n }\n\n async postToolObserver({\n toolContext,\n requestContext,\n }: Parameters<NonNullable<FactoryIntegration['postToolObserver']>>[0]): Promise<void> {\n const pullRequestUrl = parseCreatedPullRequest(toolContext);\n if (!pullRequestUrl || !requestContext) return;\n await subscribeCurrentSessionToPullRequest(\n requestContext,\n pullRequestUrl,\n 'auto-gh-pr-create',\n this as unknown as GithubIntegration,\n );\n }\n\n diagnostics(): Record<string, unknown> {\n return {\n mode: 'platform',\n endpointHost: this.#endpointHost,\n polling: {\n enabled: this.#pollingEnabled,\n ...(this.#pollingIntervalMs === undefined ? {} : { intervalMs: this.#pollingIntervalMs }),\n },\n reconcile: {\n pullRequests: {\n enabled: this.#pullRequestReconcileEnabled,\n ...(this.#pullRequestReconcileIntervalMs === undefined\n ? {}\n : { intervalMs: this.#pullRequestReconcileIntervalMs }),\n },\n issues: {\n enabled: this.#issueReconcileEnabled,\n ...(this.#issueReconcileIntervalMs === undefined ? {} : { intervalMs: this.#issueReconcileIntervalMs }),\n },\n },\n };\n }\n\n async getRepositoryCollaboratorPermission(\n _installationId: number,\n repoFullName: string,\n username: string,\n signal?: AbortSignal,\n ): Promise<GithubRepositoryPermission | undefined> {\n let repository: { owner: string; repo: string };\n try {\n repository = splitRepository(repoFullName);\n } catch {\n return undefined;\n }\n const cacheKey = `${repository.owner}/${repository.repo}:${username.toLowerCase()}`;\n const cached = this.#collaboratorPermissionCache.get(cacheKey);\n if (cached && cached.expiresAt > Date.now()) return cached.permission;\n this.#collaboratorPermissionCache.delete(cacheKey);\n const inFlight = this.#collaboratorPermissionInFlight.get(cacheKey);\n if (inFlight) return settleOrAbort(inFlight, signal, undefined);\n const lookup = (async () => {\n try {\n const result = await this.#client.request<{ permission: GithubRepositoryPermission }>(\n 'GET',\n `${API_PREFIX}/github/repos/${encodeURIComponent(repository.owner)}/${encodeURIComponent(repository.repo)}/collaborators/${encodeURIComponent(username)}/permission`,\n undefined,\n { signal: AbortSignal.timeout(COLLABORATOR_PERMISSION_LOOKUP_TIMEOUT_MS) },\n );\n // Failures are not cached: a rate-limited or aborted lookup must retry\n // on the next call rather than pin the login as unknown.\n setBounded(this.#collaboratorPermissionCache, cacheKey, {\n permission: result.permission,\n expiresAt: Date.now() + COLLABORATOR_PERMISSION_CACHE_TTL_MS,\n });\n return result.permission;\n } catch {\n return undefined;\n } finally {\n this.#collaboratorPermissionInFlight.delete(cacheKey);\n }\n })();\n this.#collaboratorPermissionInFlight.set(cacheKey, lookup);\n return settleOrAbort(lookup, signal, undefined);\n }\n\n async listInstallationRepos(installationId: number): Promise<RepoSummary[]> {\n // Hot in two places — the repos route and token minting (which re-lists\n // only to validate the 1–10 repo rule). A short TTL collapses repeat\n // Platform round trips within one UI interaction.\n const cached = this.#installationReposCache.get(installationId);\n if (cached && cached.expiresAt > Date.now()) return cached.repos;\n this.#installationReposCache.delete(installationId);\n\n const result = await this.#client.request<{\n repositories: Array<{\n id: number;\n owner: string;\n name: string;\n fullName: string;\n private: boolean;\n defaultBranch: string;\n }>;\n }>('GET', `${API_PREFIX}/github-app/installations/${installationId}/repositories`);\n const repos = result.repositories.map(repository => ({ ...repository, installationId }));\n setBounded(this.#installationReposCache, installationId, {\n repos,\n expiresAt: Date.now() + INSTALLATION_REPOS_CACHE_TTL_MS,\n });\n return repos;\n }\n\n async mintInstallationToken(installationId: number): Promise<string> {\n const repositories = await this.listInstallationRepos(installationId);\n if (repositories.length === 0 || repositories.length > 10) {\n throw new Error('Platform GitHub token minting requires between one and ten installation repositories.');\n }\n const result = await this.#client.request<{ token: string }>(\n 'POST',\n `${API_PREFIX}/github-app/installations/${installationId}/token`,\n { repositories: repositories.map(repository => repository.name), permissions: REPOSITORY_TOKEN_PERMISSIONS },\n );\n return result.token;\n }\n\n async addIssueLabels(\n _installationId: number,\n sourceId: string,\n issueNumber: number,\n labels: string[],\n ): Promise<string[]> {\n const result = await this.#client.request<{ labels: string[] }>(\n 'POST',\n repositoryPath(sourceId, `issues/${issueNumber}/labels`),\n { labels },\n );\n return result.labels;\n }\n\n getInstallationOctokit(_installationId: number): ReturnType<GithubIntegration['getInstallationOctokit']> {\n return {\n pulls: {\n get: async ({ owner, repo, pull_number }: { owner: string; repo: string; pull_number: number }) => {\n const data = await this.#client.request<GithubPullRequest>(\n 'GET',\n repositoryPath(`${owner}/${repo}`, `pulls/${pull_number}`),\n );\n return { data: { base: { repo: { id: data.base.repo.id } } } };\n },\n },\n } as unknown as ReturnType<GithubIntegration['getInstallationOctokit']>;\n }\n\n async #listIssues(connection: IntegrationConnection, sourceId: string, page: number, labels?: string[]) {\n requireGithubConnection(connection);\n const path = repositoryPath(sourceId, 'issues');\n const query = new URLSearchParams({ state: 'open', page: String(page), per_page: String(PAGE_SIZE) });\n const normalizedLabels = normalizeLabels(labels);\n if (normalizedLabels.length > 0) query.set('label', normalizedLabels.join(','));\n const result = await this.#client.request<{ issues: GithubIssue[] }>('GET', `${path}?${query}`);\n return {\n issues: result.issues.map(issue => parseIntakeIssue(sourceId, issue)),\n nextCursor: result.issues.length > 0 ? String(page + 1) : null,\n };\n }\n\n async #getIssue(connection: IntegrationConnection, sourceId: string | undefined, issueId: string) {\n requireGithubConnection(connection);\n const repository = requireSource(sourceId, 'GitHub Intake requires a repository source.');\n const issueNumber = requirePositiveId(issueId, 'issue');\n try {\n const [issue, comments] = await Promise.all([\n this.#client.request<GithubIssue>('GET', repositoryPath(repository, `issues/${issueNumber}`)),\n this.#client.request<{ comments: GithubComment[] }>(\n 'GET',\n `${repositoryPath(repository, `issues/${issueNumber}/comments`)}?per_page=100`,\n ),\n ]);\n return parseIntakeIssueDetail(repository, issue, comments.comments);\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n async #updateIntakeIssue(input: UpdateIntakeIssueInput): Promise<IntakeIssue | null> {\n requireGithubConnection(input.connection);\n const repository = requireSource(input.sourceId, 'GitHub Intake requires a repository source.');\n const issueNumber = requirePositiveId(input.issueId, 'issue');\n if (input.state.kind === 'byName') {\n logPlatformWarn(`Platform GitHub: updateIssue byName is not supported (name=${input.state.name}); ignoring.`);\n return null;\n }\n const targetState: 'open' | 'closed' =\n input.state.stateType === 'unstarted' || input.state.stateType === 'started' ? 'open' : 'closed';\n const stateReason: 'completed' | 'not_planned' | null =\n targetState === 'closed' ? (input.state.stateType === 'canceled' ? 'not_planned' : 'completed') : null;\n // Reject PR targets: probe the pulls endpoint. A 200 means the number is a\n // pull request, not an issue. Factory does not close PRs via updateIssue —\n // PR merges/closes go through the version-control pipeline.\n try {\n await this.#client.request<GithubPullRequest>('GET', repositoryPath(repository, `pulls/${issueNumber}`));\n logPlatformWarn(`Platform GitHub: updateIssue rejected — target ${repository}#${issueNumber} is a pull request.`);\n return null;\n } catch (error) {\n if (!isNotFound(error)) throw error;\n // 404 on pulls means it's an issue (or nothing) — fall through to PATCH.\n }\n try {\n const issue = await this.#client.request<GithubIssue>(\n 'PATCH',\n repositoryPath(repository, `issues/${issueNumber}`),\n {\n state: targetState,\n ...(stateReason ? { state_reason: stateReason } : {}),\n },\n { actingUserId: input.actingUserId },\n );\n return parseIntakeIssue(repository, issue);\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n /**\n * Learn Factory's own login from a write it just made. Skipped when the write\n * was made on behalf of a user — that comment is authored by the human, and\n * recording it would teach Factory to mistake a person for itself.\n */\n #observeSelfAuthor(comment: GithubComment, actingUserId: string | undefined): void {\n if (actingUserId) return;\n this.identity.observeSelfAuthor(comment.user?.login);\n }\n\n async #createIssueComment(input: CreateIntakeCommentInput) {\n requireGithubConnection(input.connection);\n const repository = requireSource(input.sourceId, 'GitHub Intake requires a repository source.');\n const issueNumber = requirePositiveId(input.issueId, 'issue');\n try {\n const comment = await this.#client.request<GithubComment>(\n 'POST',\n repositoryPath(repository, `issues/${issueNumber}/comments`),\n { body: input.body },\n { actingUserId: input.actingUserId },\n );\n this.#observeSelfAuthor(comment, input.actingUserId);\n return { id: String(comment.id), url: comment.htmlUrl };\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n async #listPullRequests(input: ListPullRequestsInput) {\n requireGithubConnection(input.connection);\n const page = parsePositiveCursor(input.cursor);\n const query = new URLSearchParams({\n state: input.state ?? 'open',\n page: String(page),\n per_page: String(PAGE_SIZE),\n });\n const result = await this.#client.request<{ pullRequests: GithubPullRequest[] }>(\n 'GET',\n `${repositoryPath(input.sourceId, 'pulls')}?${query}`,\n );\n return {\n pullRequests: result.pullRequests\n .filter(pullRequest => input.includeDrafts !== false || !pullRequest.draft)\n .map(parsePullRequest),\n nextCursor: result.pullRequests.length === PAGE_SIZE ? String(page + 1) : null,\n };\n }\n\n async #getPullRequest(input: PullRequestRef) {\n try {\n return parsePullRequest(\n await this.#client.request<GithubPullRequest>('GET', pullRequestPath(input, input.pullRequestId)),\n );\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n async #createPullRequest(input: CreatePullRequestInput) {\n requireGithubConnection(input.connection);\n const result = await this.#client.request<GithubPullRequest>(\n 'POST',\n repositoryPath(input.sourceId, 'pulls'),\n {\n head: input.headBranch,\n base: input.baseBranch,\n title: input.title,\n body: input.body,\n draft: input.draft,\n },\n { actingUserId: input.actingUserId },\n );\n return parsePullRequest(result);\n }\n\n async #updatePullRequest(input: UpdatePullRequestInput) {\n const result = await this.#client.request<GithubPullRequest>(\n 'PATCH',\n pullRequestPath(input, input.pullRequestId),\n {\n title: input.title,\n body: input.body === null ? '' : input.body,\n base: input.baseBranch,\n state: input.state,\n },\n { actingUserId: input.actingUserId },\n );\n return parsePullRequest(result);\n }\n\n #mergePullRequest(input: MergePullRequestInput) {\n return this.#client.request<{ merged: boolean; message: string; sha: string | null }>(\n 'PUT',\n `${pullRequestPath(input, input.pullRequestId)}/merge`,\n { commitTitle: input.commitTitle, commitMessage: input.commitMessage, method: input.method },\n { actingUserId: input.actingUserId },\n );\n }\n\n async #listComments(input: ListPullRequestCommentsInput) {\n const page = parsePositiveCursor(input.cursor);\n const result = await this.#client.request<{ comments: GithubComment[] }>(\n 'GET',\n `${repositoryPath(input.sourceId, `issues/${requirePositiveId(input.pullRequestId, 'pull request')}/comments`)}?page=${page}&per_page=${PAGE_SIZE}`,\n );\n return {\n comments: result.comments.map(parseComment),\n nextCursor: result.comments.length === PAGE_SIZE ? String(page + 1) : null,\n };\n }\n\n async #createComment(input: CreatePullRequestCommentInput) {\n const comment = await this.#client.request<GithubComment>(\n 'POST',\n repositoryPath(input.sourceId, `issues/${requirePositiveId(input.pullRequestId, 'pull request')}/comments`),\n { body: input.body },\n { actingUserId: input.actingUserId },\n );\n this.#observeSelfAuthor(comment, input.actingUserId);\n return parseComment(comment);\n }\n\n async #updateComment(input: UpdatePullRequestCommentInput) {\n requireGithubConnection(input.connection);\n const comment = await this.#client.request<GithubComment>(\n 'PATCH',\n repositoryPath(input.sourceId, `issues/comments/${requirePositiveId(input.commentId, 'comment')}`),\n { body: input.body },\n { actingUserId: input.actingUserId },\n );\n return parseComment(comment);\n }\n\n async #deleteComment(input: DeletePullRequestCommentInput) {\n requireGithubConnection(input.connection);\n await this.#client.request<void>(\n 'DELETE',\n repositoryPath(input.sourceId, `issues/comments/${requirePositiveId(input.commentId, 'comment')}`),\n undefined,\n { actingUserId: input.actingUserId },\n );\n }\n\n async #listReviews(input: ListReviewsInput) {\n const page = parsePositiveCursor(input.cursor);\n const result = await this.#client.request<{ reviews: GithubReview[] }>(\n 'GET',\n `${pullRequestPath(input, input.pullRequestId)}/reviews?page=${page}&per_page=${PAGE_SIZE}`,\n );\n return {\n reviews: result.reviews.map(parseReview),\n nextCursor: result.reviews.length === PAGE_SIZE ? String(page + 1) : null,\n };\n }\n\n async #getReview(input: ReviewRef) {\n try {\n return parseReview(\n await this.#client.request<GithubReview>(\n 'GET',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}`,\n ),\n );\n } catch (error) {\n if (isNotFound(error)) return null;\n throw error;\n }\n }\n\n async #createReview(input: CreateReviewInput) {\n const review = await this.#client.request<GithubReview>(\n 'POST',\n `${pullRequestPath(input, input.pullRequestId)}/reviews`,\n { body: input.body, commitId: input.commitId, event: input.event ? reviewEvent(input.event) : undefined },\n { actingUserId: input.actingUserId },\n );\n return parseReview(review);\n }\n\n async #updateReview(input: UpdateReviewInput) {\n const review = await this.#client.request<GithubReview>(\n 'PUT',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}`,\n { body: input.body },\n { actingUserId: input.actingUserId },\n );\n return parseReview(review);\n }\n\n async #submitReview(input: SubmitReviewInput) {\n const review = await this.#client.request<GithubReview>(\n 'POST',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}/events`,\n { body: input.body, event: reviewEvent(input.event) },\n { actingUserId: input.actingUserId },\n );\n return parseReview(review);\n }\n\n async #dismissReview(input: DismissReviewInput) {\n const review = await this.#client.request<GithubReview>(\n 'PUT',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}/dismissals`,\n { message: input.message },\n { actingUserId: input.actingUserId },\n );\n return parseReview(review);\n }\n\n async #deletePendingReview(input: ReviewRef) {\n await this.#client.request<void>(\n 'DELETE',\n `${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, 'review')}`,\n undefined,\n { actingUserId: input.actingUserId },\n );\n }\n\n async #listReviewComments(input: ListReviewCommentsInput) {\n const page = parsePositiveCursor(input.cursor);\n const result = await this.#client.request<{ comments: GithubReviewComment[] }>(\n 'GET',\n `${pullRequestPath(input, input.pullRequestId)}/comments?page=${page}&per_page=${PAGE_SIZE}`,\n );\n return {\n comments: result.comments.map(parseReviewComment),\n nextCursor: result.comments.length === PAGE_SIZE ? String(page + 1) : null,\n };\n }\n\n async #createReviewComment(input: CreateReviewCommentInput) {\n let body: Record<string, unknown>;\n if (input.replyToId !== undefined) {\n body = { body: input.body, replyToId: requirePositiveId(input.replyToId, 'review comment') };\n } else {\n if (!input.commitId || !input.path || input.line === undefined || !input.side) {\n throw new Error('A review comment requires commitId, path, line, and side unless it is a reply.');\n }\n body = {\n body: input.body,\n commitId: input.commitId,\n path: input.path,\n line: input.line,\n side: input.side.toUpperCase(),\n startLine: input.startLine,\n startSide: input.startSide?.toUpperCase(),\n };\n }\n return parseReviewComment(\n await this.#client.request<GithubReviewComment>(\n 'POST',\n `${pullRequestPath(input, input.pullRequestId)}/comments`,\n body,\n { actingUserId: input.actingUserId },\n ),\n );\n }\n\n async #updateReviewComment(input: UpdatePullRequestCommentInput) {\n requireGithubConnection(input.connection);\n return parseReviewComment(\n await this.#client.request<GithubReviewComment>(\n 'PATCH',\n repositoryPath(input.sourceId, `pulls/comments/${requirePositiveId(input.commentId, 'review comment')}`),\n { body: input.body },\n { actingUserId: input.actingUserId },\n ),\n );\n }\n\n async #deleteReviewComment(input: DeletePullRequestCommentInput) {\n requireGithubConnection(input.connection);\n await this.#client.request<void>(\n 'DELETE',\n repositoryPath(input.sourceId, `pulls/comments/${requirePositiveId(input.commentId, 'review comment')}`),\n undefined,\n { actingUserId: input.actingUserId },\n );\n }\n\n #requestedReviewers(method: 'GET' | 'POST' | 'DELETE', input: UpdateReviewersInput) {\n requireGithubConnection(input.connection);\n return this.#client.request<{ users: string[]; teams: string[] }>(\n method,\n `${pullRequestPath(input, input.pullRequestId)}/requested-reviewers`,\n method === 'GET' ? undefined : { users: input.users, teams: input.teams },\n method === 'GET' ? undefined : { actingUserId: input.actingUserId },\n );\n }\n}\n\nfunction repositoryPath(sourceId: string, suffix: string): string {\n const { owner, repo } = splitRepository(sourceId);\n return `${API_PREFIX}/github/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/${suffix}`;\n}\n\nfunction pullRequestPath(\n input: { connection: IntegrationConnection; sourceId: string },\n pullRequestId: string,\n): string {\n requireGithubConnection(input.connection);\n return repositoryPath(input.sourceId, `pulls/${requirePositiveId(pullRequestId, 'pull request')}`);\n}\n\nfunction splitRepository(sourceId: string): { owner: string; repo: string } {\n const slash = sourceId.indexOf('/');\n if (slash <= 0 || slash === sourceId.length - 1) {\n throw new Error('GitHub capabilities require an owner/repository source.');\n }\n return { owner: sourceId.slice(0, slash), repo: sourceId.slice(slash + 1) };\n}\n\nfunction parseIntakeIssue(sourceId: string, issue: GithubIssue): IntakeIssue {\n return {\n id: String(issue.number),\n identifier: `#${issue.number}`,\n title: issue.title,\n url: issue.htmlUrl,\n author: issue.user?.login ?? null,\n state: issue.state,\n stateType: issue.state,\n priority: null,\n assignee: issue.assignees[0] ?? null,\n assignees: issue.assignees,\n source: sourceId,\n labels: issue.labels,\n commentCount: issue.commentCount,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n };\n}\n\nfunction parseIntakeIssueDetail(sourceId: string, issue: GithubIssue, comments: GithubComment[]): IntakeIssueDetail {\n return {\n ...parseIntakeIssue(sourceId, issue),\n description: issue.body?.trim() ? issue.body : null,\n comments: comments.map(comment => ({\n author: comment.user?.login ?? null,\n body: comment.body,\n createdAt: comment.createdAt,\n })),\n };\n}\n\nfunction parsePullRequest(pullRequest: GithubPullRequest): PullRequest {\n return {\n id: String(pullRequest.number),\n title: pullRequest.title,\n url: pullRequest.htmlUrl,\n author: pullRequest.user?.login ?? null,\n assignees: pullRequest.assignees ?? [],\n requestedReviewers: pullRequest.requestedReviewers ?? [],\n labels: pullRequest.labels ?? [],\n body: pullRequest.body?.trim() ? pullRequest.body : null,\n state: pullRequest.state,\n draft: pullRequest.draft,\n merged: pullRequest.merged,\n mergeable: pullRequest.mergeable,\n baseBranch: pullRequest.base.ref,\n headBranch: pullRequest.head.ref,\n headSha: pullRequest.head.sha,\n createdAt: pullRequest.createdAt,\n updatedAt: pullRequest.updatedAt,\n };\n}\n\nfunction parseComment(comment: GithubComment): PullRequestComment {\n return {\n id: String(comment.id),\n url: comment.htmlUrl,\n author: comment.user?.login ?? null,\n body: comment.body,\n createdAt: comment.createdAt,\n updatedAt: comment.updatedAt,\n };\n}\n\nfunction parseReview(review: GithubReview): Review {\n const states: Record<GithubReview['state'], Review['state']> = {\n PENDING: 'pending',\n COMMENTED: 'commented',\n APPROVED: 'approved',\n CHANGES_REQUESTED: 'changes-requested',\n DISMISSED: 'dismissed',\n };\n return {\n id: String(review.id),\n url: review.htmlUrl,\n author: review.user?.login ?? null,\n body: review.body?.trim() ? review.body : null,\n state: states[review.state],\n commitId: review.commitId,\n submittedAt: review.submittedAt,\n };\n}\n\nfunction parseReviewComment(comment: GithubReviewComment): ReviewComment {\n return {\n ...parseComment(comment),\n path: comment.path,\n line: comment.line,\n side: comment.side?.toLowerCase() as 'left' | 'right' | null,\n commitId: comment.commitId,\n replyToId: comment.replyToId === null ? null : String(comment.replyToId),\n };\n}\n\nfunction requireGithubConnection(connection: IntegrationConnection): void {\n if (connection.type !== 'app-installation' && connection.type !== 'oauth') {\n throw new Error('GitHub capabilities require a GitHub connection.');\n }\n}\n\nfunction requireSingleSource(sourceIds: string[], message: string): string {\n if (sourceIds.length !== 1) throw new Error(message);\n return sourceIds[0]!;\n}\n\nfunction requireSource(sourceId: string | undefined, message: string): string {\n if (!sourceId) throw new Error(message);\n return sourceId;\n}\n\nfunction normalizeLabels(labels: string[] | undefined): string[] {\n return [...new Set((labels ?? []).map(label => label.trim()).filter(Boolean))];\n}\n\nfunction parsePositiveCursor(cursor: string | undefined): number {\n if (cursor === undefined) return 1;\n const parsed = parsePositiveInteger(cursor);\n if (parsed === null) throw new Error('GitHub cursor must be a positive page number.');\n return parsed;\n}\n\nfunction parsePositiveInteger(value: string): number | null {\n if (!/^\\d+$/.test(value)) return null;\n const parsed = Number(value);\n return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : null;\n}\n\nfunction parseGithubExternalTarget(externalId: string): { repository: string; issueId: string } | null {\n const match =\n externalId.match(/^(.+\\/.+):(\\d+)$/) ??\n externalId.match(/^github:(\\d+):(?:issue|pull-request):(\\d+)$/) ??\n externalId.match(/^(\\d+):(\\d+)$/);\n if (!match?.[1] || !match[2] || parsePositiveInteger(match[2]) === null) return null;\n return { repository: match[1], issueId: match[2] };\n}\n\nfunction optionalPositiveIntegerEnv(name: 'MASTRA_PLATFORM_GITHUB_POLLING_INTERVAL_MS'): number | undefined {\n const value = process.env[name]?.trim();\n if (!value) return undefined;\n const parsed = parsePositiveInteger(value);\n if (parsed === null) throw new Error(`${name} must be a positive integer.`);\n return parsed;\n}\n\nfunction requirePositiveId(value: string, resource: string): number {\n const parsed = parsePositiveInteger(value);\n if (parsed === null) throw new Error(`GitHub ${resource} id must be a positive integer.`);\n return parsed;\n}\n\nfunction reviewEvent(event: 'approve' | 'request-changes' | 'comment') {\n if (event === 'approve') return 'APPROVE' as const;\n if (event === 'request-changes') return 'REQUEST_CHANGES' as const;\n return 'COMMENT' as const;\n}\n\nfunction isNotFound(error: unknown): boolean {\n return error instanceof PlatformApiError && error.status === 404;\n}\n\n// Platform answers 404 when the installation row is gone, 409 when it is suspended or soft-deleted.\n// A 502 also covers a dead installation but is indistinguishable from a transient GitHub outage.\nfunction isDeadInstallation(error: unknown): boolean {\n return error instanceof PlatformApiError && (error.status === 404 || error.status === 409);\n}\n"],"mappings":";;;;;;;;;;;;AAyJA,MAAM,YAAY;AAClB,MAAM,aAAa;;;;;;;AAOnB,MAAM,2BAA2B;;;;;;AAMjC,MAAM,kCAAkC;;;;;;AAMxC,MAAM,iCAAiC,IAAI;;;;;;;;AAQ3C,MAAM,uCAAuC,KAAK;;AAElD,MAAM,4CAA4C;;;;;;;AAOlD,MAAM,oBAAoB;AAE1B,SAAS,WAAiB,OAAkB,KAAQ,OAAgB;CAClE,MAAM,OAAO,GAAG;CAChB,MAAM,IAAI,KAAK,KAAK;CACpB,IAAI,MAAM,OAAO,mBAAmB;EAClC,MAAM,SAAS,MAAM,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;EACnC,IAAI,WAAW,KAAA,GAAW,MAAM,OAAO,MAAM;CAC/C;AACF;AAEA,MAAM,+BAA+B;CACnC,UAAU;CACV,QAAQ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SAAS,WAAW,OAAyB;CAC3C,OAAO,iBAAiB,oBAAoB,MAAM,WAAW;AAC/D;AAIA,SAAS,mBAAmB,OAAyB;CACnD,OAAO,iBAAiB,qBAAqB,MAAM,WAAW,OAAO,MAAM,WAAW;AACxF"}
@@ -0,0 +1,35 @@
1
+ import { createHash } from "crypto";
2
+ //#region ../../packages/_internals/workspace/dist/index.js
3
+ /**
4
+ * Setup completion marker shared by repo templates and their consumers.
5
+ *
6
+ * A repo template writes this file beside the checkout as its last build
7
+ * step, so it exists only in images where every setup command succeeded. Its
8
+ * content is a digest of the setup commands the image ran, letting a sandbox
9
+ * booted from the image tell whether the setup it is about to run already
10
+ * happened. Relative to the template's build cwd, which is also the runtime
11
+ * working directory the repo was cloned into.
12
+ */
13
+ const SETUP_MARKER_PATH = ".mastra-sandbox/setup";
14
+ /** Blank entries never become build steps, so they never count toward the digest either. */
15
+ function normalizeSetupCommands(setupCommand) {
16
+ return (setupCommand === void 0 ? [] : Array.isArray(setupCommand) ? setupCommand : [setupCommand]).filter((command) => command.trim() !== "");
17
+ }
18
+ /** The marker content for a setup command list: `sha256:<hex>` over the commands joined by newlines. */
19
+ function setupMarkerContent(setupCommand) {
20
+ return `sha256:${createHash("sha256").update(normalizeSetupCommands(setupCommand).join("\n")).digest("hex")}`;
21
+ }
22
+ function repoCloneCommand({ cloneUrl, destination, branch, tokenEnv }) {
23
+ return `git ${tokenEnv ? `${gitAuthFlag(tokenEnv)} ` : ""}clone --depth=1 --single-branch ${branch ? `--branch ${shellQuote(branch)} ` : ""}${shellQuote(cloneUrl)} ${shellQuote(destination)}`;
24
+ }
25
+ /** Per-invocation auth header; `-c` config never reaches `.git/config`. */
26
+ function gitAuthFlag(tokenEnv) {
27
+ return `-c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$${tokenEnv}" | base64 -w0)"`;
28
+ }
29
+ function shellQuote(value) {
30
+ return `'${value.replace(/'/g, `'\\''`)}'`;
31
+ }
32
+ //#endregion
33
+ export { SETUP_MARKER_PATH, normalizeSetupCommands, repoCloneCommand, setupMarkerContent };
34
+
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../../../packages/_internals/workspace/dist/index.js"],"sourcesContent":["import { createHash } from \"crypto\";\n//#region src/setup-marker.ts\n/**\n* Setup completion marker shared by repo templates and their consumers.\n*\n* A repo template writes this file beside the checkout as its last build\n* step, so it exists only in images where every setup command succeeded. Its\n* content is a digest of the setup commands the image ran, letting a sandbox\n* booted from the image tell whether the setup it is about to run already\n* happened. Relative to the template's build cwd, which is also the runtime\n* working directory the repo was cloned into.\n*/\nconst SETUP_MARKER_PATH = \".mastra-sandbox/setup\";\n/** Blank entries never become build steps, so they never count toward the digest either. */\nfunction normalizeSetupCommands(setupCommand) {\n\treturn (setupCommand === void 0 ? [] : Array.isArray(setupCommand) ? setupCommand : [setupCommand]).filter((command) => command.trim() !== \"\");\n}\n/** The marker content for a setup command list: `sha256:<hex>` over the commands joined by newlines. */\nfunction setupMarkerContent(setupCommand) {\n\treturn `sha256:${createHash(\"sha256\").update(normalizeSetupCommands(setupCommand).join(\"\\n\")).digest(\"hex\")}`;\n}\n/** Shell step that writes the marker relative to the cwd. `content` is a digest, so it is shell-safe. */\nfunction setupMarkerCommand(content) {\n\treturn `mkdir -p \"$(dirname \"${SETUP_MARKER_PATH}\")\" && printf '%s' '${content}' > \"${SETUP_MARKER_PATH}\"`;\n}\n//#endregion\n//#region src/repo-clone.ts\nfunction repoCloneCommand({ cloneUrl, destination, branch, tokenEnv }) {\n\treturn `git ${tokenEnv ? `${gitAuthFlag(tokenEnv)} ` : \"\"}clone --depth=1 --single-branch ${branch ? `--branch ${shellQuote(branch)} ` : \"\"}${shellQuote(cloneUrl)} ${shellQuote(destination)}`;\n}\n/** Per-invocation auth header; `-c` config never reaches `.git/config`. */\nfunction gitAuthFlag(tokenEnv) {\n\treturn `-c http.extraheader=\"AUTHORIZATION: basic $(printf 'x-access-token:%s' \"$${tokenEnv}\" | base64 -w0)\"`;\n}\nfunction shellQuote(value) {\n\treturn `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n//#endregion\nexport { SETUP_MARKER_PATH, normalizeSetupCommands, repoCloneCommand, setupMarkerCommand, setupMarkerContent };\n\n//# sourceMappingURL=index.js.map"],"mappings":";;;;;;;;;;;;AAYA,MAAM,oBAAoB;;AAE1B,SAAS,uBAAuB,cAAc;CAC7C,QAAQ,iBAAiB,KAAK,IAAI,CAAC,IAAI,MAAM,QAAQ,YAAY,IAAI,eAAe,CAAC,YAAY,EAAA,CAAG,QAAQ,YAAY,QAAQ,KAAK,MAAM,EAAE;AAC9I;;AAEA,SAAS,mBAAmB,cAAc;CACzC,OAAO,UAAU,WAAW,QAAQ,CAAC,CAAC,OAAO,uBAAuB,YAAY,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK;AAC3G;AAOA,SAAS,iBAAiB,EAAE,UAAU,aAAa,QAAQ,YAAY;CACtE,OAAO,OAAO,WAAW,GAAG,YAAY,QAAQ,EAAE,KAAK,GAAG,kCAAkC,SAAS,YAAY,WAAW,MAAM,EAAE,KAAK,KAAK,WAAW,QAAQ,EAAE,GAAG,WAAW,WAAW;AAC7L;;AAEA,SAAS,YAAY,UAAU;CAC9B,OAAO,4EAA4E,SAAS;AAC7F;AACA,SAAS,WAAW,OAAO;CAC1B,OAAO,IAAI,MAAM,QAAQ,MAAM,OAAO,EAAE;AACzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/routes/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAGjE,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAuB,MAAM,mCAAmC,CAAC;AAQvG,OAAO,KAAK,EAAyB,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AACxG,OAAO,KAAK,EAAE,QAAQ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