@mastra/factory 0.1.0-alpha.2 → 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 (85) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/factory.d.ts.map +1 -1
  3. package/dist/factory.js +812 -209
  4. package/dist/factory.js.map +1 -1
  5. package/dist/index.js +812 -209
  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 +45 -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.d.ts.map +1 -1
  12. package/dist/integrations/github/routes.js +12 -9
  13. package/dist/integrations/github/routes.js.map +1 -1
  14. package/dist/integrations/github/sandbox.d.ts +1 -0
  15. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  16. package/dist/integrations/github/sandbox.js +2 -2
  17. package/dist/integrations/github/sandbox.js.map +1 -1
  18. package/dist/integrations/github/session-subscriptions.d.ts +3 -0
  19. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
  20. package/dist/integrations/github/session-subscriptions.js +30 -0
  21. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  22. package/dist/integrations/github/token-refresh.d.ts +6 -0
  23. package/dist/integrations/github/token-refresh.d.ts.map +1 -0
  24. package/dist/integrations/github/token-refresh.js +17 -0
  25. package/dist/integrations/github/token-refresh.js.map +1 -0
  26. package/dist/integrations/platform/github/event-worker.d.ts +2 -0
  27. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  28. package/dist/integrations/platform/github/event-worker.js +8 -0
  29. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  30. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  31. package/dist/integrations/platform/github/integration.js +52 -9
  32. package/dist/integrations/platform/github/integration.js.map +1 -1
  33. package/dist/routes/config.d.ts +16 -11
  34. package/dist/routes/config.d.ts.map +1 -1
  35. package/dist/routes/config.js +222 -109
  36. package/dist/routes/config.js.map +1 -1
  37. package/dist/routes/custom-provider-source.d.ts +52 -0
  38. package/dist/routes/custom-provider-source.d.ts.map +1 -0
  39. package/dist/routes/custom-provider-source.js +107 -0
  40. package/dist/routes/custom-provider-source.js.map +1 -0
  41. package/dist/routes/oauth.js +33 -1
  42. package/dist/routes/oauth.js.map +1 -1
  43. package/dist/routes/surface.d.ts +4 -0
  44. package/dist/routes/surface.d.ts.map +1 -1
  45. package/dist/routes/surface.js +282 -111
  46. package/dist/routes/surface.js.map +1 -1
  47. package/dist/routes/work-items.js.map +1 -1
  48. package/dist/rules/defaults.d.ts.map +1 -1
  49. package/dist/rules/defaults.js +8 -2
  50. package/dist/rules/defaults.js.map +1 -1
  51. package/dist/rules/dispatcher.js.map +1 -1
  52. package/dist/rules/github-service.d.ts +2 -0
  53. package/dist/rules/github-service.d.ts.map +1 -1
  54. package/dist/rules/github-service.js +15 -1
  55. package/dist/rules/github-service.js.map +1 -1
  56. package/dist/rules/index.js +8 -2
  57. package/dist/rules/index.js.map +1 -1
  58. package/dist/rules/linear-service.js.map +1 -1
  59. package/dist/rules/processor.js.map +1 -1
  60. package/dist/rules/tools.js.map +1 -1
  61. package/dist/rules/transition-service.js.map +1 -1
  62. package/dist/rules/types.d.ts +5 -0
  63. package/dist/rules/types.d.ts.map +1 -1
  64. package/dist/rules/types.js.map +1 -1
  65. package/dist/rules/validation.js.map +1 -1
  66. package/dist/sandbox/fleet.d.ts +3 -0
  67. package/dist/sandbox/fleet.d.ts.map +1 -1
  68. package/dist/sandbox/fleet.js +10 -3
  69. package/dist/sandbox/fleet.js.map +1 -1
  70. package/dist/spa-static.d.ts +4 -5
  71. package/dist/spa-static.d.ts.map +1 -1
  72. package/dist/spa-static.js +5 -2
  73. package/dist/spa-static.js.map +1 -1
  74. package/dist/storage/domains/custom-providers/base.d.ts +57 -0
  75. package/dist/storage/domains/custom-providers/base.d.ts.map +1 -0
  76. package/dist/storage/domains/custom-providers/base.js +150 -0
  77. package/dist/storage/domains/custom-providers/base.js.map +1 -0
  78. package/dist/storage/domains/memory-settings/base.d.ts +62 -0
  79. package/dist/storage/domains/memory-settings/base.d.ts.map +1 -0
  80. package/dist/storage/domains/memory-settings/base.js +111 -0
  81. package/dist/storage/domains/memory-settings/base.js.map +1 -0
  82. package/dist/workspace.d.ts.map +1 -1
  83. package/dist/workspace.js +17 -0
  84. package/dist/workspace.js.map +1 -1
  85. 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;
@@ -924,6 +924,7 @@ function polledIssueEvent(project, issue) {
924
924
  number: issue.number,
925
925
  title: issue.title,
926
926
  html_url: issue.url,
927
+ created_at: issue.createdAt,
927
928
  labels: issue.labels.map((name) => ({ name }))
928
929
  }
929
930
  }
@@ -943,6 +944,7 @@ function polledPullRequestEvent(project, pullRequest) {
943
944
  number: pullRequest.number,
944
945
  title: pullRequest.title,
945
946
  html_url: pullRequest.url,
947
+ created_at: pullRequest.createdAt,
946
948
  state: "open",
947
949
  merged: false,
948
950
  head: { ref: pullRequest.headBranch },
@@ -1472,13 +1474,6 @@ async function loadOrCreateSandboxRow(github, project, userId) {
1472
1474
  async function prepareProject(options) {
1473
1475
  const { github, fleet, project, userId, onProgress } = options;
1474
1476
  const sandboxRow = await loadOrCreateSandboxRow(github, project, userId);
1475
- const sandbox = await ensureProjectSandbox({
1476
- fleet,
1477
- row: sandboxRow,
1478
- storage: github.sourceControlStorage.sandboxes,
1479
- onProgress
1480
- });
1481
- const fresh = await github.sourceControlStorage.sandboxes.getById({ id: sandboxRow.id });
1482
1477
  const access = await github.versionControl.getRepositoryAccess({
1483
1478
  orgId: project.installation.orgId,
1484
1479
  repositoryId: project.repository.id
@@ -1486,6 +1481,14 @@ async function prepareProject(options) {
1486
1481
  if (!access.authorization) {
1487
1482
  throw new MaterializeError("Repository access did not include a bearer token.", "clone-failed");
1488
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 });
1489
1492
  const finalRow = fresh ?? sandboxRow;
1490
1493
  await materializeRepo({
1491
1494
  row: finalRow,
@@ -1916,6 +1919,18 @@ async function resolveSessionWorkspace(github, projectId, userId, sessionId) {
1916
1919
  // src/integrations/github/session-subscriptions.ts
1917
1920
  import { createTool } from "@mastra/core/tools";
1918
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
1919
1934
  function sessionUserId(user) {
1920
1935
  return user?.workosId ?? user?.id;
1921
1936
  }
@@ -2002,11 +2017,30 @@ async function unsubscribeCurrentSessionFromPullRequest(requestContext, pullRequ
2002
2017
  await unsubscribeFromPullRequest(await subscriptionInput(target, number), github.integrationStorage);
2003
2018
  return number;
2004
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
+ }
2005
2030
  function createGithubSubscriptionTools(requestContext, github) {
2006
2031
  const context = requestContext.get("controller");
2007
2032
  const user = requestContext.get("user");
2008
2033
  if (!context?.getState().projectRepositoryId || !sessionOrgId(user) || !sessionUserId(user)) return {};
2009
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
+ }),
2010
2044
  github_subscribe_pr: createTool({
2011
2045
  id: "github_subscribe_pr",
2012
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.",
@@ -2855,8 +2889,8 @@ var GithubIntegration = class {
2855
2889
  });
2856
2890
  }
2857
2891
  /**
2858
- * Session-scoped agent tools: PR subscribe/unsubscribe for sessions bound
2859
- * 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.
2860
2894
  */
2861
2895
  sessionTools({ requestContext }) {
2862
2896
  return createGithubSubscriptionTools(requestContext, this);