@mastra/factory 0.1.0-alpha.4 → 0.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/capabilities/intake.d.ts +2 -0
- package/dist/capabilities/intake.d.ts.map +1 -1
- package/dist/capabilities/version-control.d.ts +6 -0
- package/dist/capabilities/version-control.d.ts.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +140 -36
- package/dist/factory.js.map +1 -1
- package/dist/index.js +140 -36
- package/dist/index.js.map +1 -1
- package/dist/integrations/github/integration.js +2 -1
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/routes.js +2 -1
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/platform/api-client.d.ts +2 -0
- package/dist/integrations/platform/api-client.d.ts.map +1 -1
- package/dist/integrations/platform/api-client.js +7 -0
- package/dist/integrations/platform/api-client.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +132 -36
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/linear/integration.js +3 -0
- package/dist/integrations/platform/linear/integration.js.map +1 -1
- package/package.json +5 -5
|
@@ -1729,7 +1729,8 @@ function buildProjectGitRoutes({
|
|
|
1729
1729
|
baseBranch: base,
|
|
1730
1730
|
headBranch: head,
|
|
1731
1731
|
title,
|
|
1732
|
-
body: prBody
|
|
1732
|
+
body: prBody,
|
|
1733
|
+
actingUserId: userId
|
|
1733
1734
|
});
|
|
1734
1735
|
await emitAudit?.({
|
|
1735
1736
|
context: loose(c),
|
|
@@ -2088,6 +2089,9 @@ var PlatformApiClient = class {
|
|
|
2088
2089
|
accept: "application/json",
|
|
2089
2090
|
authorization: `Bearer ${this.#accessToken}`
|
|
2090
2091
|
};
|
|
2092
|
+
if (options?.actingUserId) {
|
|
2093
|
+
headers["x-acting-user-id"] = options.actingUserId;
|
|
2094
|
+
}
|
|
2091
2095
|
const timeoutSignal = AbortSignal.timeout(15e3);
|
|
2092
2096
|
const init = {
|
|
2093
2097
|
method,
|
|
@@ -2139,6 +2143,9 @@ function redact(message, accessToken) {
|
|
|
2139
2143
|
function logPlatformInfo(message, fields) {
|
|
2140
2144
|
writePlatformLog("info", message, fields);
|
|
2141
2145
|
}
|
|
2146
|
+
function logPlatformWarn(message, fields) {
|
|
2147
|
+
writePlatformLog("warn", message, fields);
|
|
2148
|
+
}
|
|
2142
2149
|
function logPlatformError(message, fields) {
|
|
2143
2150
|
writePlatformLog("error", message, fields);
|
|
2144
2151
|
}
|
|
@@ -2457,6 +2464,11 @@ function retryDelay(error, fallbackMs) {
|
|
|
2457
2464
|
// src/integrations/platform/github/integration.ts
|
|
2458
2465
|
var PAGE_SIZE = 30;
|
|
2459
2466
|
var API_PREFIX2 = "/v1/server";
|
|
2467
|
+
var REPOSITORY_TOKEN_PERMISSIONS = {
|
|
2468
|
+
contents: "write",
|
|
2469
|
+
issues: "write",
|
|
2470
|
+
pull_requests: "write"
|
|
2471
|
+
};
|
|
2460
2472
|
function loose2(c) {
|
|
2461
2473
|
return c;
|
|
2462
2474
|
}
|
|
@@ -2570,7 +2582,7 @@ var PlatformGithubIntegration = class {
|
|
|
2570
2582
|
return this.#listIssues(input.connection, sourceId, parsePositiveCursor(input.cursor), input.labels);
|
|
2571
2583
|
},
|
|
2572
2584
|
getIssue: (input) => this.#getIssue(input.connection, input.sourceId, input.issueId),
|
|
2573
|
-
createComment: (input) => this.#createIssueComment(input
|
|
2585
|
+
createComment: (input) => this.#createIssueComment(input)
|
|
2574
2586
|
};
|
|
2575
2587
|
versionControl = {
|
|
2576
2588
|
initialize: ({ storage }) => {
|
|
@@ -2609,7 +2621,7 @@ var PlatformGithubIntegration = class {
|
|
|
2609
2621
|
const token = await this.#client.request(
|
|
2610
2622
|
"POST",
|
|
2611
2623
|
`${API_PREFIX2}/github-app/installations/${installationId}/token`,
|
|
2612
|
-
{ repositories: [repositoryName], permissions:
|
|
2624
|
+
{ repositories: [repositoryName], permissions: REPOSITORY_TOKEN_PERMISSIONS }
|
|
2613
2625
|
);
|
|
2614
2626
|
return {
|
|
2615
2627
|
cloneUrl: `https://github.com/${repository.slug}.git`,
|
|
@@ -2673,6 +2685,7 @@ var PlatformGithubIntegration = class {
|
|
|
2673
2685
|
return [
|
|
2674
2686
|
this.#statusRoute(ctx),
|
|
2675
2687
|
this.#connectRoute(ctx),
|
|
2688
|
+
this.#connectUserRoute(ctx),
|
|
2676
2689
|
...buildGithubRoutes({
|
|
2677
2690
|
auth: ctx.auth,
|
|
2678
2691
|
fleet: ctx.fleet,
|
|
@@ -2704,11 +2717,16 @@ var PlatformGithubIntegration = class {
|
|
|
2704
2717
|
organizationRequired: true,
|
|
2705
2718
|
connected: false,
|
|
2706
2719
|
installations: [],
|
|
2720
|
+
userConnected: false,
|
|
2721
|
+
userGithubUsername: null,
|
|
2707
2722
|
reason: "organization_required",
|
|
2708
2723
|
diagnostics: this.diagnostics()
|
|
2709
2724
|
});
|
|
2710
2725
|
}
|
|
2711
|
-
const installations = await
|
|
2726
|
+
const [installations, userConnection] = await Promise.all([
|
|
2727
|
+
this.#syncInstallations(tenant.orgId, tenant.userId),
|
|
2728
|
+
this.#fetchUserConnection(tenant.userId)
|
|
2729
|
+
]);
|
|
2712
2730
|
return c.json({
|
|
2713
2731
|
enabled: true,
|
|
2714
2732
|
sandboxEnabled: ctx.fleet.enabled,
|
|
@@ -2718,6 +2736,8 @@ var PlatformGithubIntegration = class {
|
|
|
2718
2736
|
accountLogin: installation.accountName,
|
|
2719
2737
|
accountType: installation.accountType
|
|
2720
2738
|
})),
|
|
2739
|
+
userConnected: userConnection.connected,
|
|
2740
|
+
userGithubUsername: userConnection.githubUsername,
|
|
2721
2741
|
reason: installations.length > 0 ? "ready" : "not_connected",
|
|
2722
2742
|
diagnostics: this.diagnostics()
|
|
2723
2743
|
});
|
|
@@ -2752,6 +2772,55 @@ var PlatformGithubIntegration = class {
|
|
|
2752
2772
|
}
|
|
2753
2773
|
});
|
|
2754
2774
|
}
|
|
2775
|
+
#connectUserRoute(ctx) {
|
|
2776
|
+
return registerApiRoute2("/auth/github/connect-user", {
|
|
2777
|
+
method: "GET",
|
|
2778
|
+
requiresAuth: false,
|
|
2779
|
+
handler: async (c) => {
|
|
2780
|
+
await ctx.auth.ensureUser(loose2(c));
|
|
2781
|
+
const tenant = ctx.auth.tenant(loose2(c));
|
|
2782
|
+
if (!tenant?.orgId) return c.json({ error: "unauthorized" }, 401);
|
|
2783
|
+
const redirectTo = c.req.query("redirectTo") || c.req.query("return_to") || "/";
|
|
2784
|
+
const originator = routeBaseUrl(ctx, c.req.url);
|
|
2785
|
+
logPlatformInfo("Starting Platform GitHub user authorization flow", {
|
|
2786
|
+
orgId: tenant.orgId,
|
|
2787
|
+
redirectTo,
|
|
2788
|
+
originator
|
|
2789
|
+
});
|
|
2790
|
+
const query = new URLSearchParams({
|
|
2791
|
+
userId: tenant.userId,
|
|
2792
|
+
redirectTo,
|
|
2793
|
+
originator
|
|
2794
|
+
});
|
|
2795
|
+
const { url } = await this.#client.request(
|
|
2796
|
+
"GET",
|
|
2797
|
+
`${API_PREFIX2}/github-app/authenticate?${query}`
|
|
2798
|
+
);
|
|
2799
|
+
return c.redirect(url);
|
|
2800
|
+
}
|
|
2801
|
+
});
|
|
2802
|
+
}
|
|
2803
|
+
/**
|
|
2804
|
+
* Personal GitHub connection status for the acting user. Returns
|
|
2805
|
+
* not-connected when the platform predates the user-connection endpoint.
|
|
2806
|
+
*/
|
|
2807
|
+
async #fetchUserConnection(userId) {
|
|
2808
|
+
try {
|
|
2809
|
+
const connection = await this.#client.request(
|
|
2810
|
+
"GET",
|
|
2811
|
+
`${API_PREFIX2}/github-app/user-connection?${new URLSearchParams({ userId })}`
|
|
2812
|
+
);
|
|
2813
|
+
if (!connection.connected && connection.reason) {
|
|
2814
|
+
logPlatformWarn("Platform GitHub user connection verification failed", {
|
|
2815
|
+
userId,
|
|
2816
|
+
reason: connection.reason
|
|
2817
|
+
});
|
|
2818
|
+
}
|
|
2819
|
+
return connection;
|
|
2820
|
+
} catch {
|
|
2821
|
+
return { connected: false, githubUsername: null };
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2755
2824
|
async #syncInstallations(orgId, userId) {
|
|
2756
2825
|
const result = await this.#client.request(
|
|
2757
2826
|
"GET",
|
|
@@ -2847,7 +2916,7 @@ var PlatformGithubIntegration = class {
|
|
|
2847
2916
|
const result = await this.#client.request(
|
|
2848
2917
|
"POST",
|
|
2849
2918
|
`${API_PREFIX2}/github-app/installations/${installationId}/token`,
|
|
2850
|
-
{ repositories: repositories.map((repository) => repository.name), permissions:
|
|
2919
|
+
{ repositories: repositories.map((repository) => repository.name), permissions: REPOSITORY_TOKEN_PERMISSIONS }
|
|
2851
2920
|
);
|
|
2852
2921
|
return result.token;
|
|
2853
2922
|
}
|
|
@@ -2902,15 +2971,16 @@ var PlatformGithubIntegration = class {
|
|
|
2902
2971
|
throw error;
|
|
2903
2972
|
}
|
|
2904
2973
|
}
|
|
2905
|
-
async #createIssueComment(
|
|
2906
|
-
requireGithubConnection(connection);
|
|
2907
|
-
const repository = requireSource(sourceId, "GitHub Intake requires a repository source.");
|
|
2908
|
-
const issueNumber = requirePositiveId(issueId, "issue");
|
|
2974
|
+
async #createIssueComment(input) {
|
|
2975
|
+
requireGithubConnection(input.connection);
|
|
2976
|
+
const repository = requireSource(input.sourceId, "GitHub Intake requires a repository source.");
|
|
2977
|
+
const issueNumber = requirePositiveId(input.issueId, "issue");
|
|
2909
2978
|
try {
|
|
2910
2979
|
const comment = await this.#client.request(
|
|
2911
2980
|
"POST",
|
|
2912
2981
|
repositoryPath(repository, `issues/${issueNumber}/comments`),
|
|
2913
|
-
{ body }
|
|
2982
|
+
{ body: input.body },
|
|
2983
|
+
{ actingUserId: input.actingUserId }
|
|
2914
2984
|
);
|
|
2915
2985
|
return { id: String(comment.id), url: comment.htmlUrl };
|
|
2916
2986
|
} catch (error) {
|
|
@@ -2947,29 +3017,40 @@ var PlatformGithubIntegration = class {
|
|
|
2947
3017
|
}
|
|
2948
3018
|
async #createPullRequest(input) {
|
|
2949
3019
|
requireGithubConnection(input.connection);
|
|
2950
|
-
const result = await this.#client.request(
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
3020
|
+
const result = await this.#client.request(
|
|
3021
|
+
"POST",
|
|
3022
|
+
repositoryPath(input.sourceId, "pulls"),
|
|
3023
|
+
{
|
|
3024
|
+
head: input.headBranch,
|
|
3025
|
+
base: input.baseBranch,
|
|
3026
|
+
title: input.title,
|
|
3027
|
+
body: input.body,
|
|
3028
|
+
draft: input.draft
|
|
3029
|
+
},
|
|
3030
|
+
{ actingUserId: input.actingUserId }
|
|
3031
|
+
);
|
|
2957
3032
|
return parsePullRequest2(result);
|
|
2958
3033
|
}
|
|
2959
3034
|
async #updatePullRequest(input) {
|
|
2960
|
-
const result = await this.#client.request(
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
3035
|
+
const result = await this.#client.request(
|
|
3036
|
+
"PATCH",
|
|
3037
|
+
pullRequestPath(input, input.pullRequestId),
|
|
3038
|
+
{
|
|
3039
|
+
title: input.title,
|
|
3040
|
+
body: input.body === null ? "" : input.body,
|
|
3041
|
+
base: input.baseBranch,
|
|
3042
|
+
state: input.state
|
|
3043
|
+
},
|
|
3044
|
+
{ actingUserId: input.actingUserId }
|
|
3045
|
+
);
|
|
2966
3046
|
return parsePullRequest2(result);
|
|
2967
3047
|
}
|
|
2968
3048
|
#mergePullRequest(input) {
|
|
2969
3049
|
return this.#client.request(
|
|
2970
3050
|
"PUT",
|
|
2971
3051
|
`${pullRequestPath(input, input.pullRequestId)}/merge`,
|
|
2972
|
-
{ commitTitle: input.commitTitle, commitMessage: input.commitMessage, method: input.method }
|
|
3052
|
+
{ commitTitle: input.commitTitle, commitMessage: input.commitMessage, method: input.method },
|
|
3053
|
+
{ actingUserId: input.actingUserId }
|
|
2973
3054
|
);
|
|
2974
3055
|
}
|
|
2975
3056
|
async #listComments(input) {
|
|
@@ -2987,7 +3068,8 @@ var PlatformGithubIntegration = class {
|
|
|
2987
3068
|
const comment = await this.#client.request(
|
|
2988
3069
|
"POST",
|
|
2989
3070
|
repositoryPath(input.sourceId, `issues/${requirePositiveId(input.pullRequestId, "pull request")}/comments`),
|
|
2990
|
-
{ body: input.body }
|
|
3071
|
+
{ body: input.body },
|
|
3072
|
+
{ actingUserId: input.actingUserId }
|
|
2991
3073
|
);
|
|
2992
3074
|
return parseComment(comment);
|
|
2993
3075
|
}
|
|
@@ -2996,7 +3078,8 @@ var PlatformGithubIntegration = class {
|
|
|
2996
3078
|
const comment = await this.#client.request(
|
|
2997
3079
|
"PATCH",
|
|
2998
3080
|
repositoryPath(input.sourceId, `issues/comments/${requirePositiveId(input.commentId, "comment")}`),
|
|
2999
|
-
{ body: input.body }
|
|
3081
|
+
{ body: input.body },
|
|
3082
|
+
{ actingUserId: input.actingUserId }
|
|
3000
3083
|
);
|
|
3001
3084
|
return parseComment(comment);
|
|
3002
3085
|
}
|
|
@@ -3004,7 +3087,9 @@ var PlatformGithubIntegration = class {
|
|
|
3004
3087
|
requireGithubConnection(input.connection);
|
|
3005
3088
|
await this.#client.request(
|
|
3006
3089
|
"DELETE",
|
|
3007
|
-
repositoryPath(input.sourceId, `issues/comments/${requirePositiveId(input.commentId, "comment")}`)
|
|
3090
|
+
repositoryPath(input.sourceId, `issues/comments/${requirePositiveId(input.commentId, "comment")}`),
|
|
3091
|
+
void 0,
|
|
3092
|
+
{ actingUserId: input.actingUserId }
|
|
3008
3093
|
);
|
|
3009
3094
|
}
|
|
3010
3095
|
async #listReviews(input) {
|
|
@@ -3035,7 +3120,8 @@ var PlatformGithubIntegration = class {
|
|
|
3035
3120
|
const review = await this.#client.request(
|
|
3036
3121
|
"POST",
|
|
3037
3122
|
`${pullRequestPath(input, input.pullRequestId)}/reviews`,
|
|
3038
|
-
{ body: input.body, commitId: input.commitId, event: input.event ? reviewEvent(input.event) : void 0 }
|
|
3123
|
+
{ body: input.body, commitId: input.commitId, event: input.event ? reviewEvent(input.event) : void 0 },
|
|
3124
|
+
{ actingUserId: input.actingUserId }
|
|
3039
3125
|
);
|
|
3040
3126
|
return parseReview(review);
|
|
3041
3127
|
}
|
|
@@ -3043,7 +3129,8 @@ var PlatformGithubIntegration = class {
|
|
|
3043
3129
|
const review = await this.#client.request(
|
|
3044
3130
|
"PUT",
|
|
3045
3131
|
`${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, "review")}`,
|
|
3046
|
-
{ body: input.body }
|
|
3132
|
+
{ body: input.body },
|
|
3133
|
+
{ actingUserId: input.actingUserId }
|
|
3047
3134
|
);
|
|
3048
3135
|
return parseReview(review);
|
|
3049
3136
|
}
|
|
@@ -3051,7 +3138,8 @@ var PlatformGithubIntegration = class {
|
|
|
3051
3138
|
const review = await this.#client.request(
|
|
3052
3139
|
"POST",
|
|
3053
3140
|
`${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, "review")}/events`,
|
|
3054
|
-
{ body: input.body, event: reviewEvent(input.event) }
|
|
3141
|
+
{ body: input.body, event: reviewEvent(input.event) },
|
|
3142
|
+
{ actingUserId: input.actingUserId }
|
|
3055
3143
|
);
|
|
3056
3144
|
return parseReview(review);
|
|
3057
3145
|
}
|
|
@@ -3059,14 +3147,17 @@ var PlatformGithubIntegration = class {
|
|
|
3059
3147
|
const review = await this.#client.request(
|
|
3060
3148
|
"PUT",
|
|
3061
3149
|
`${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, "review")}/dismissals`,
|
|
3062
|
-
{ message: input.message }
|
|
3150
|
+
{ message: input.message },
|
|
3151
|
+
{ actingUserId: input.actingUserId }
|
|
3063
3152
|
);
|
|
3064
3153
|
return parseReview(review);
|
|
3065
3154
|
}
|
|
3066
3155
|
async #deletePendingReview(input) {
|
|
3067
3156
|
await this.#client.request(
|
|
3068
3157
|
"DELETE",
|
|
3069
|
-
`${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, "review")}
|
|
3158
|
+
`${pullRequestPath(input, input.pullRequestId)}/reviews/${requirePositiveId(input.reviewId, "review")}`,
|
|
3159
|
+
void 0,
|
|
3160
|
+
{ actingUserId: input.actingUserId }
|
|
3070
3161
|
);
|
|
3071
3162
|
}
|
|
3072
3163
|
async #listReviewComments(input) {
|
|
@@ -3102,7 +3193,8 @@ var PlatformGithubIntegration = class {
|
|
|
3102
3193
|
await this.#client.request(
|
|
3103
3194
|
"POST",
|
|
3104
3195
|
`${pullRequestPath(input, input.pullRequestId)}/comments`,
|
|
3105
|
-
body
|
|
3196
|
+
body,
|
|
3197
|
+
{ actingUserId: input.actingUserId }
|
|
3106
3198
|
)
|
|
3107
3199
|
);
|
|
3108
3200
|
}
|
|
@@ -3112,7 +3204,8 @@ var PlatformGithubIntegration = class {
|
|
|
3112
3204
|
await this.#client.request(
|
|
3113
3205
|
"PATCH",
|
|
3114
3206
|
repositoryPath(input.sourceId, `pulls/comments/${requirePositiveId(input.commentId, "review comment")}`),
|
|
3115
|
-
{ body: input.body }
|
|
3207
|
+
{ body: input.body },
|
|
3208
|
+
{ actingUserId: input.actingUserId }
|
|
3116
3209
|
)
|
|
3117
3210
|
);
|
|
3118
3211
|
}
|
|
@@ -3120,7 +3213,9 @@ var PlatformGithubIntegration = class {
|
|
|
3120
3213
|
requireGithubConnection(input.connection);
|
|
3121
3214
|
await this.#client.request(
|
|
3122
3215
|
"DELETE",
|
|
3123
|
-
repositoryPath(input.sourceId, `pulls/comments/${requirePositiveId(input.commentId, "review comment")}`)
|
|
3216
|
+
repositoryPath(input.sourceId, `pulls/comments/${requirePositiveId(input.commentId, "review comment")}`),
|
|
3217
|
+
void 0,
|
|
3218
|
+
{ actingUserId: input.actingUserId }
|
|
3124
3219
|
);
|
|
3125
3220
|
}
|
|
3126
3221
|
#requestedReviewers(method, input) {
|
|
@@ -3128,7 +3223,8 @@ var PlatformGithubIntegration = class {
|
|
|
3128
3223
|
return this.#client.request(
|
|
3129
3224
|
method,
|
|
3130
3225
|
`${pullRequestPath(input, input.pullRequestId)}/requested-reviewers`,
|
|
3131
|
-
method === "GET" ? void 0 : { users: input.users, teams: input.teams }
|
|
3226
|
+
method === "GET" ? void 0 : { users: input.users, teams: input.teams },
|
|
3227
|
+
method === "GET" ? void 0 : { actingUserId: input.actingUserId }
|
|
3132
3228
|
);
|
|
3133
3229
|
}
|
|
3134
3230
|
};
|