@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.
Files changed (60) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/factory.d.ts.map +1 -1
  3. package/dist/factory.js +772 -206
  4. package/dist/factory.js.map +1 -1
  5. package/dist/index.js +772 -206
  6. package/dist/index.js.map +1 -1
  7. package/dist/integrations/github/integration.d.ts +2 -2
  8. package/dist/integrations/github/integration.js +43 -11
  9. package/dist/integrations/github/integration.js.map +1 -1
  10. package/dist/integrations/github/provenance.js.map +1 -1
  11. package/dist/integrations/github/routes.js +10 -9
  12. package/dist/integrations/github/routes.js.map +1 -1
  13. package/dist/integrations/github/sandbox.d.ts +1 -0
  14. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  15. package/dist/integrations/github/sandbox.js +2 -2
  16. package/dist/integrations/github/sandbox.js.map +1 -1
  17. package/dist/integrations/github/session-subscriptions.d.ts +3 -0
  18. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
  19. package/dist/integrations/github/session-subscriptions.js +30 -0
  20. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  21. package/dist/integrations/github/token-refresh.d.ts +6 -0
  22. package/dist/integrations/github/token-refresh.d.ts.map +1 -0
  23. package/dist/integrations/github/token-refresh.js +17 -0
  24. package/dist/integrations/github/token-refresh.js.map +1 -0
  25. package/dist/integrations/platform/github/integration.js +41 -9
  26. package/dist/integrations/platform/github/integration.js.map +1 -1
  27. package/dist/routes/config.d.ts +16 -11
  28. package/dist/routes/config.d.ts.map +1 -1
  29. package/dist/routes/config.js +222 -109
  30. package/dist/routes/config.js.map +1 -1
  31. package/dist/routes/custom-provider-source.d.ts +52 -0
  32. package/dist/routes/custom-provider-source.d.ts.map +1 -0
  33. package/dist/routes/custom-provider-source.js +107 -0
  34. package/dist/routes/custom-provider-source.js.map +1 -0
  35. package/dist/routes/oauth.js +33 -1
  36. package/dist/routes/oauth.js.map +1 -1
  37. package/dist/routes/surface.d.ts +4 -0
  38. package/dist/routes/surface.d.ts.map +1 -1
  39. package/dist/routes/surface.js +266 -110
  40. package/dist/routes/surface.js.map +1 -1
  41. package/dist/sandbox/fleet.d.ts +3 -0
  42. package/dist/sandbox/fleet.d.ts.map +1 -1
  43. package/dist/sandbox/fleet.js +10 -3
  44. package/dist/sandbox/fleet.js.map +1 -1
  45. package/dist/spa-static.d.ts +4 -5
  46. package/dist/spa-static.d.ts.map +1 -1
  47. package/dist/spa-static.js +5 -2
  48. package/dist/spa-static.js.map +1 -1
  49. package/dist/storage/domains/custom-providers/base.d.ts +57 -0
  50. package/dist/storage/domains/custom-providers/base.d.ts.map +1 -0
  51. package/dist/storage/domains/custom-providers/base.js +150 -0
  52. package/dist/storage/domains/custom-providers/base.js.map +1 -0
  53. package/dist/storage/domains/memory-settings/base.d.ts +62 -0
  54. package/dist/storage/domains/memory-settings/base.d.ts.map +1 -0
  55. package/dist/storage/domains/memory-settings/base.js +111 -0
  56. package/dist/storage/domains/memory-settings/base.js.map +1 -0
  57. package/dist/workspace.d.ts.map +1 -1
  58. package/dist/workspace.js +17 -0
  59. package/dist/workspace.js.map +1 -1
  60. package/package.json +7 -6
@@ -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,
@@ -1918,6 +1919,18 @@ async function resolveSessionWorkspace(github, projectId, userId, sessionId) {
1918
1919
  // src/integrations/github/session-subscriptions.ts
1919
1920
  import { createTool } from "@mastra/core/tools";
1920
1921
  import { z } from "zod";
1922
+
1923
+ // src/integrations/github/token-refresh.ts
1924
+ var GITHUB_TOKEN_INJECTOR_CONTEXT_KEY = "factoryGithubTokenInjector";
1925
+ function injectGithubToken(requestContext, token) {
1926
+ const injector = requestContext.get(GITHUB_TOKEN_INJECTOR_CONTEXT_KEY);
1927
+ if (!injector) {
1928
+ throw new Error("GitHub token refresh requires an active Factory sandbox workspace.");
1929
+ }
1930
+ injector(token);
1931
+ }
1932
+
1933
+ // src/integrations/github/session-subscriptions.ts
1921
1934
  function sessionUserId(user) {
1922
1935
  return user?.workosId ?? user?.id;
1923
1936
  }
@@ -2004,11 +2017,30 @@ async function unsubscribeCurrentSessionFromPullRequest(requestContext, pullRequ
2004
2017
  await unsubscribeFromPullRequest(await subscriptionInput(target, number), github.integrationStorage);
2005
2018
  return number;
2006
2019
  }
2020
+ async function refreshGithubToken(requestContext, github) {
2021
+ const target = await resolveSessionTarget(requestContext, github);
2022
+ const access = await github.versionControl.getRepositoryAccess({
2023
+ orgId: target.orgId,
2024
+ repositoryId: target.repository.id
2025
+ });
2026
+ const token = access.authorization?.token;
2027
+ if (!token) throw new Error("Repository access did not include a bearer token for the Factory session.");
2028
+ injectGithubToken(requestContext, token);
2029
+ }
2007
2030
  function createGithubSubscriptionTools(requestContext, github) {
2008
2031
  const context = requestContext.get("controller");
2009
2032
  const user = requestContext.get("user");
2010
2033
  if (!context?.getState().projectRepositoryId || !sessionOrgId(user) || !sessionUserId(user)) return {};
2011
2034
  return {
2035
+ github_refresh_token: createTool({
2036
+ id: "github_refresh_token",
2037
+ 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.",
2038
+ inputSchema: z.object({}),
2039
+ execute: async () => {
2040
+ await refreshGithubToken(requestContext, github);
2041
+ return { refreshed: true };
2042
+ }
2043
+ }),
2012
2044
  github_subscribe_pr: createTool({
2013
2045
  id: "github_subscribe_pr",
2014
2046
  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 +2889,8 @@ var GithubIntegration = class {
2857
2889
  });
2858
2890
  }
2859
2891
  /**
2860
- * Session-scoped agent tools: PR subscribe/unsubscribe for sessions bound
2861
- * to a GitHub-backed project. Empty for sessions outside a GitHub project.
2892
+ * Session-scoped agent tools for token refresh and PR subscriptions in
2893
+ * sessions bound to a GitHub-backed project. Empty elsewhere.
2862
2894
  */
2863
2895
  sessionTools({ requestContext }) {
2864
2896
  return createGithubSubscriptionTools(requestContext, this);