@mastra/factory 0.1.0-alpha.3 → 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.
Files changed (72) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/capabilities/intake.d.ts +2 -0
  3. package/dist/capabilities/intake.d.ts.map +1 -1
  4. package/dist/capabilities/version-control.d.ts +6 -0
  5. package/dist/capabilities/version-control.d.ts.map +1 -1
  6. package/dist/factory.d.ts.map +1 -1
  7. package/dist/factory.js +912 -242
  8. package/dist/factory.js.map +1 -1
  9. package/dist/index.js +912 -242
  10. package/dist/index.js.map +1 -1
  11. package/dist/integrations/github/integration.d.ts +2 -2
  12. package/dist/integrations/github/integration.js +45 -12
  13. package/dist/integrations/github/integration.js.map +1 -1
  14. package/dist/integrations/github/provenance.js.map +1 -1
  15. package/dist/integrations/github/routes.js +12 -10
  16. package/dist/integrations/github/routes.js.map +1 -1
  17. package/dist/integrations/github/sandbox.d.ts +1 -0
  18. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  19. package/dist/integrations/github/sandbox.js +2 -2
  20. package/dist/integrations/github/sandbox.js.map +1 -1
  21. package/dist/integrations/github/session-subscriptions.d.ts +3 -0
  22. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
  23. package/dist/integrations/github/session-subscriptions.js +30 -0
  24. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  25. package/dist/integrations/github/token-refresh.d.ts +6 -0
  26. package/dist/integrations/github/token-refresh.d.ts.map +1 -0
  27. package/dist/integrations/github/token-refresh.js +17 -0
  28. package/dist/integrations/github/token-refresh.js.map +1 -0
  29. package/dist/integrations/platform/api-client.d.ts +2 -0
  30. package/dist/integrations/platform/api-client.d.ts.map +1 -1
  31. package/dist/integrations/platform/api-client.js +7 -0
  32. package/dist/integrations/platform/api-client.js.map +1 -1
  33. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  34. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  35. package/dist/integrations/platform/github/integration.js +173 -45
  36. package/dist/integrations/platform/github/integration.js.map +1 -1
  37. package/dist/integrations/platform/linear/integration.js +3 -0
  38. package/dist/integrations/platform/linear/integration.js.map +1 -1
  39. package/dist/routes/config.d.ts +16 -11
  40. package/dist/routes/config.d.ts.map +1 -1
  41. package/dist/routes/config.js +222 -109
  42. package/dist/routes/config.js.map +1 -1
  43. package/dist/routes/custom-provider-source.d.ts +52 -0
  44. package/dist/routes/custom-provider-source.d.ts.map +1 -0
  45. package/dist/routes/custom-provider-source.js +107 -0
  46. package/dist/routes/custom-provider-source.js.map +1 -0
  47. package/dist/routes/oauth.js +33 -1
  48. package/dist/routes/oauth.js.map +1 -1
  49. package/dist/routes/surface.d.ts +4 -0
  50. package/dist/routes/surface.d.ts.map +1 -1
  51. package/dist/routes/surface.js +266 -110
  52. package/dist/routes/surface.js.map +1 -1
  53. package/dist/sandbox/fleet.d.ts +3 -0
  54. package/dist/sandbox/fleet.d.ts.map +1 -1
  55. package/dist/sandbox/fleet.js +10 -3
  56. package/dist/sandbox/fleet.js.map +1 -1
  57. package/dist/spa-static.d.ts +4 -5
  58. package/dist/spa-static.d.ts.map +1 -1
  59. package/dist/spa-static.js +5 -2
  60. package/dist/spa-static.js.map +1 -1
  61. package/dist/storage/domains/custom-providers/base.d.ts +57 -0
  62. package/dist/storage/domains/custom-providers/base.d.ts.map +1 -0
  63. package/dist/storage/domains/custom-providers/base.js +150 -0
  64. package/dist/storage/domains/custom-providers/base.js.map +1 -0
  65. package/dist/storage/domains/memory-settings/base.d.ts +62 -0
  66. package/dist/storage/domains/memory-settings/base.d.ts.map +1 -0
  67. package/dist/storage/domains/memory-settings/base.js +111 -0
  68. package/dist/storage/domains/memory-settings/base.js.map +1 -0
  69. package/dist/workspace.d.ts.map +1 -1
  70. package/dist/workspace.js +17 -0
  71. package/dist/workspace.js.map +1 -1
  72. package/package.json +8 -7
@@ -178,8 +178,8 @@ export declare class GithubIntegration implements FactoryIntegration {
178
178
  */
179
179
  routes(ctx: IntegrationContext): ApiRoute[];
180
180
  /**
181
- * Session-scoped agent tools: PR subscribe/unsubscribe for sessions bound
182
- * to a GitHub-backed project. Empty for sessions outside a GitHub project.
181
+ * Session-scoped agent tools for token refresh and PR subscriptions in
182
+ * sessions bound to a GitHub-backed project. Empty elsewhere.
183
183
  */
184
184
  sessionTools({ requestContext }: {
185
185
  requestContext: RequestContext;
@@ -196,8 +196,8 @@ function bindingStore(row, storage) {
196
196
  };
197
197
  }
198
198
  async function ensureProjectSandbox(options) {
199
- const { fleet, row, storage, onProgress } = options;
200
- return fleet.ensureSandbox(bindingStore(row, storage), onProgress);
199
+ const { fleet, row, storage, token, onProgress } = options;
200
+ return fleet.ensureSandbox(bindingStore(row, storage), { GH_TOKEN: token }, onProgress);
201
201
  }
202
202
  async function teardownProjectSandbox(options) {
203
203
  const { fleet, row, storage, sandbox } = options;
@@ -1474,13 +1474,6 @@ async function loadOrCreateSandboxRow(github, project, userId) {
1474
1474
  async function prepareProject(options) {
1475
1475
  const { github, fleet, project, userId, onProgress } = options;
1476
1476
  const sandboxRow = await loadOrCreateSandboxRow(github, project, userId);
1477
- const sandbox = await ensureProjectSandbox({
1478
- fleet,
1479
- row: sandboxRow,
1480
- storage: github.sourceControlStorage.sandboxes,
1481
- onProgress
1482
- });
1483
- const fresh = await github.sourceControlStorage.sandboxes.getById({ id: sandboxRow.id });
1484
1477
  const access = await github.versionControl.getRepositoryAccess({
1485
1478
  orgId: project.installation.orgId,
1486
1479
  repositoryId: project.repository.id
@@ -1488,6 +1481,14 @@ async function prepareProject(options) {
1488
1481
  if (!access.authorization) {
1489
1482
  throw new MaterializeError("Repository access did not include a bearer token.", "clone-failed");
1490
1483
  }
1484
+ const sandbox = await ensureProjectSandbox({
1485
+ fleet,
1486
+ row: sandboxRow,
1487
+ storage: github.sourceControlStorage.sandboxes,
1488
+ token: access.authorization.token,
1489
+ onProgress
1490
+ });
1491
+ const fresh = await github.sourceControlStorage.sandboxes.getById({ id: sandboxRow.id });
1491
1492
  const finalRow = fresh ?? sandboxRow;
1492
1493
  await materializeRepo({
1493
1494
  row: finalRow,
@@ -1807,7 +1808,8 @@ function buildProjectGitRoutes({
1807
1808
  baseBranch: base,
1808
1809
  headBranch: head,
1809
1810
  title,
1810
- body: prBody
1811
+ body: prBody,
1812
+ actingUserId: userId
1811
1813
  });
1812
1814
  await emitAudit?.({
1813
1815
  context: loose(c),
@@ -1918,6 +1920,18 @@ async function resolveSessionWorkspace(github, projectId, userId, sessionId) {
1918
1920
  // src/integrations/github/session-subscriptions.ts
1919
1921
  import { createTool } from "@mastra/core/tools";
1920
1922
  import { z } from "zod";
1923
+
1924
+ // src/integrations/github/token-refresh.ts
1925
+ var GITHUB_TOKEN_INJECTOR_CONTEXT_KEY = "factoryGithubTokenInjector";
1926
+ function injectGithubToken(requestContext, token) {
1927
+ const injector = requestContext.get(GITHUB_TOKEN_INJECTOR_CONTEXT_KEY);
1928
+ if (!injector) {
1929
+ throw new Error("GitHub token refresh requires an active Factory sandbox workspace.");
1930
+ }
1931
+ injector(token);
1932
+ }
1933
+
1934
+ // src/integrations/github/session-subscriptions.ts
1921
1935
  function sessionUserId(user) {
1922
1936
  return user?.workosId ?? user?.id;
1923
1937
  }
@@ -2004,11 +2018,30 @@ async function unsubscribeCurrentSessionFromPullRequest(requestContext, pullRequ
2004
2018
  await unsubscribeFromPullRequest(await subscriptionInput(target, number), github.integrationStorage);
2005
2019
  return number;
2006
2020
  }
2021
+ async function refreshGithubToken(requestContext, github) {
2022
+ const target = await resolveSessionTarget(requestContext, github);
2023
+ const access = await github.versionControl.getRepositoryAccess({
2024
+ orgId: target.orgId,
2025
+ repositoryId: target.repository.id
2026
+ });
2027
+ const token = access.authorization?.token;
2028
+ if (!token) throw new Error("Repository access did not include a bearer token for the Factory session.");
2029
+ injectGithubToken(requestContext, token);
2030
+ }
2007
2031
  function createGithubSubscriptionTools(requestContext, github) {
2008
2032
  const context = requestContext.get("controller");
2009
2033
  const user = requestContext.get("user");
2010
2034
  if (!context?.getState().projectRepositoryId || !sessionOrgId(user) || !sessionUserId(user)) return {};
2011
2035
  return {
2036
+ github_refresh_token: createTool({
2037
+ id: "github_refresh_token",
2038
+ 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.",
2039
+ inputSchema: z.object({}),
2040
+ execute: async () => {
2041
+ await refreshGithubToken(requestContext, github);
2042
+ return { refreshed: true };
2043
+ }
2044
+ }),
2012
2045
  github_subscribe_pr: createTool({
2013
2046
  id: "github_subscribe_pr",
2014
2047
  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.",
@@ -2857,8 +2890,8 @@ var GithubIntegration = class {
2857
2890
  });
2858
2891
  }
2859
2892
  /**
2860
- * Session-scoped agent tools: PR subscribe/unsubscribe for sessions bound
2861
- * to a GitHub-backed project. Empty for sessions outside a GitHub project.
2893
+ * Session-scoped agent tools for token refresh and PR subscriptions in
2894
+ * sessions bound to a GitHub-backed project. Empty elsewhere.
2862
2895
  */
2863
2896
  sessionTools({ requestContext }) {
2864
2897
  return createGithubSubscriptionTools(requestContext, this);