@mastra/factory 0.1.0-alpha.3 → 0.1.0-alpha.4
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 +33 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +772 -206
- package/dist/factory.js.map +1 -1
- package/dist/index.js +772 -206
- package/dist/index.js.map +1 -1
- package/dist/integrations/github/integration.d.ts +2 -2
- package/dist/integrations/github/integration.js +43 -11
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/routes.js +10 -9
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +1 -0
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +2 -2
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/github/session-subscriptions.d.ts +3 -0
- package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
- package/dist/integrations/github/session-subscriptions.js +30 -0
- package/dist/integrations/github/session-subscriptions.js.map +1 -1
- package/dist/integrations/github/token-refresh.d.ts +6 -0
- package/dist/integrations/github/token-refresh.d.ts.map +1 -0
- package/dist/integrations/github/token-refresh.js +17 -0
- package/dist/integrations/github/token-refresh.js.map +1 -0
- package/dist/integrations/platform/github/integration.js +41 -9
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/routes/config.d.ts +16 -11
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +222 -109
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/custom-provider-source.d.ts +52 -0
- package/dist/routes/custom-provider-source.d.ts.map +1 -0
- package/dist/routes/custom-provider-source.js +107 -0
- package/dist/routes/custom-provider-source.js.map +1 -0
- package/dist/routes/oauth.js +33 -1
- package/dist/routes/oauth.js.map +1 -1
- package/dist/routes/surface.d.ts +4 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +266 -110
- package/dist/routes/surface.js.map +1 -1
- package/dist/sandbox/fleet.d.ts +3 -0
- package/dist/sandbox/fleet.d.ts.map +1 -1
- package/dist/sandbox/fleet.js +10 -3
- package/dist/sandbox/fleet.js.map +1 -1
- package/dist/spa-static.d.ts +4 -5
- package/dist/spa-static.d.ts.map +1 -1
- package/dist/spa-static.js +5 -2
- package/dist/spa-static.js.map +1 -1
- package/dist/storage/domains/custom-providers/base.d.ts +57 -0
- package/dist/storage/domains/custom-providers/base.d.ts.map +1 -0
- package/dist/storage/domains/custom-providers/base.js +150 -0
- package/dist/storage/domains/custom-providers/base.js.map +1 -0
- package/dist/storage/domains/memory-settings/base.d.ts +62 -0
- package/dist/storage/domains/memory-settings/base.d.ts.map +1 -0
- package/dist/storage/domains/memory-settings/base.js +111 -0
- package/dist/storage/domains/memory-settings/base.js.map +1 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +17 -0
- package/dist/workspace.js.map +1 -1
- package/package.json +7 -6
|
@@ -117,8 +117,8 @@ function bindingStore(row, storage) {
|
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
119
|
async function ensureProjectSandbox(options) {
|
|
120
|
-
const { fleet, row, storage, onProgress } = options;
|
|
121
|
-
return fleet.ensureSandbox(bindingStore(row, storage), onProgress);
|
|
120
|
+
const { fleet, row, storage, token, onProgress } = options;
|
|
121
|
+
return fleet.ensureSandbox(bindingStore(row, storage), { GH_TOKEN: token }, onProgress);
|
|
122
122
|
}
|
|
123
123
|
async function teardownProjectSandbox(options) {
|
|
124
124
|
const { fleet, row, storage, sandbox } = options;
|
|
@@ -1395,13 +1395,6 @@ async function loadOrCreateSandboxRow(github, project, userId) {
|
|
|
1395
1395
|
async function prepareProject(options) {
|
|
1396
1396
|
const { github, fleet, project, userId, onProgress } = options;
|
|
1397
1397
|
const sandboxRow = await loadOrCreateSandboxRow(github, project, userId);
|
|
1398
|
-
const sandbox = await ensureProjectSandbox({
|
|
1399
|
-
fleet,
|
|
1400
|
-
row: sandboxRow,
|
|
1401
|
-
storage: github.sourceControlStorage.sandboxes,
|
|
1402
|
-
onProgress
|
|
1403
|
-
});
|
|
1404
|
-
const fresh = await github.sourceControlStorage.sandboxes.getById({ id: sandboxRow.id });
|
|
1405
1398
|
const access = await github.versionControl.getRepositoryAccess({
|
|
1406
1399
|
orgId: project.installation.orgId,
|
|
1407
1400
|
repositoryId: project.repository.id
|
|
@@ -1409,6 +1402,14 @@ async function prepareProject(options) {
|
|
|
1409
1402
|
if (!access.authorization) {
|
|
1410
1403
|
throw new MaterializeError("Repository access did not include a bearer token.", "clone-failed");
|
|
1411
1404
|
}
|
|
1405
|
+
const sandbox = await ensureProjectSandbox({
|
|
1406
|
+
fleet,
|
|
1407
|
+
row: sandboxRow,
|
|
1408
|
+
storage: github.sourceControlStorage.sandboxes,
|
|
1409
|
+
token: access.authorization.token,
|
|
1410
|
+
onProgress
|
|
1411
|
+
});
|
|
1412
|
+
const fresh = await github.sourceControlStorage.sandboxes.getById({ id: sandboxRow.id });
|
|
1412
1413
|
const finalRow = fresh ?? sandboxRow;
|
|
1413
1414
|
await materializeRepo({
|
|
1414
1415
|
row: finalRow,
|
|
@@ -1839,6 +1840,18 @@ async function resolveSessionWorkspace(github, projectId, userId, sessionId) {
|
|
|
1839
1840
|
// src/integrations/github/session-subscriptions.ts
|
|
1840
1841
|
import { createTool } from "@mastra/core/tools";
|
|
1841
1842
|
import { z } from "zod";
|
|
1843
|
+
|
|
1844
|
+
// src/integrations/github/token-refresh.ts
|
|
1845
|
+
var GITHUB_TOKEN_INJECTOR_CONTEXT_KEY = "factoryGithubTokenInjector";
|
|
1846
|
+
function injectGithubToken(requestContext, token) {
|
|
1847
|
+
const injector = requestContext.get(GITHUB_TOKEN_INJECTOR_CONTEXT_KEY);
|
|
1848
|
+
if (!injector) {
|
|
1849
|
+
throw new Error("GitHub token refresh requires an active Factory sandbox workspace.");
|
|
1850
|
+
}
|
|
1851
|
+
injector(token);
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
// src/integrations/github/session-subscriptions.ts
|
|
1842
1855
|
function sessionUserId(user) {
|
|
1843
1856
|
return user?.workosId ?? user?.id;
|
|
1844
1857
|
}
|
|
@@ -1925,11 +1938,30 @@ async function unsubscribeCurrentSessionFromPullRequest(requestContext, pullRequ
|
|
|
1925
1938
|
await unsubscribeFromPullRequest(await subscriptionInput(target, number), github.integrationStorage);
|
|
1926
1939
|
return number;
|
|
1927
1940
|
}
|
|
1941
|
+
async function refreshGithubToken(requestContext, github) {
|
|
1942
|
+
const target = await resolveSessionTarget(requestContext, github);
|
|
1943
|
+
const access = await github.versionControl.getRepositoryAccess({
|
|
1944
|
+
orgId: target.orgId,
|
|
1945
|
+
repositoryId: target.repository.id
|
|
1946
|
+
});
|
|
1947
|
+
const token = access.authorization?.token;
|
|
1948
|
+
if (!token) throw new Error("Repository access did not include a bearer token for the Factory session.");
|
|
1949
|
+
injectGithubToken(requestContext, token);
|
|
1950
|
+
}
|
|
1928
1951
|
function createGithubSubscriptionTools(requestContext, github) {
|
|
1929
1952
|
const context = requestContext.get("controller");
|
|
1930
1953
|
const user = requestContext.get("user");
|
|
1931
1954
|
if (!context?.getState().projectRepositoryId || !sessionOrgId(user) || !sessionUserId(user)) return {};
|
|
1932
1955
|
return {
|
|
1956
|
+
github_refresh_token: createTool({
|
|
1957
|
+
id: "github_refresh_token",
|
|
1958
|
+
description: "Refresh GitHub CLI authentication in the active Factory sandbox. Use this after a gh command fails because authentication is expired, invalid, or missing. It installs a fresh GH_TOKEN for subsequent sandbox commands. After this tool succeeds, retry the failed gh command. Takes no arguments and never returns the token.",
|
|
1959
|
+
inputSchema: z.object({}),
|
|
1960
|
+
execute: async () => {
|
|
1961
|
+
await refreshGithubToken(requestContext, github);
|
|
1962
|
+
return { refreshed: true };
|
|
1963
|
+
}
|
|
1964
|
+
}),
|
|
1933
1965
|
github_subscribe_pr: createTool({
|
|
1934
1966
|
id: "github_subscribe_pr",
|
|
1935
1967
|
description: "Subscribe this thread to GitHub pull request activity. You usually do not need this tool: successful gh pr create commands subscribe automatically. Use it for an existing PR or to recover when automatic subscription did not occur. Closed or merged PRs are unsubscribed automatically. Accepts a PR number or canonical URL for the active project.",
|