@mastra/factory 0.8.0-alpha.8 → 0.8.0

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 (182) hide show
  1. package/CHANGELOG.md +660 -0
  2. package/dist/factory.d.ts.map +1 -1
  3. package/dist/factory.js +42 -4
  4. package/dist/factory.js.map +1 -1
  5. package/dist/integrations/base.d.ts +8 -0
  6. package/dist/integrations/base.d.ts.map +1 -1
  7. package/dist/integrations/github/app-identity.d.ts +43 -0
  8. package/dist/integrations/github/app-identity.d.ts.map +1 -0
  9. package/dist/integrations/github/app-identity.js +62 -0
  10. package/dist/integrations/github/app-identity.js.map +1 -0
  11. package/dist/integrations/github/integration.d.ts +9 -0
  12. package/dist/integrations/github/integration.d.ts.map +1 -1
  13. package/dist/integrations/github/integration.js +9 -1
  14. package/dist/integrations/github/integration.js.map +1 -1
  15. package/dist/integrations/github/reconcile-worker.d.ts +5 -0
  16. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
  17. package/dist/integrations/github/reconcile-worker.js +7 -0
  18. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  19. package/dist/integrations/github/routes.d.ts.map +1 -1
  20. package/dist/integrations/github/routes.js +11 -6
  21. package/dist/integrations/github/routes.js.map +1 -1
  22. package/dist/integrations/github/rules.d.ts +8 -0
  23. package/dist/integrations/github/rules.d.ts.map +1 -1
  24. package/dist/integrations/github/rules.js +30 -8
  25. package/dist/integrations/github/rules.js.map +1 -1
  26. package/dist/integrations/github/sandbox.d.ts +39 -6
  27. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  28. package/dist/integrations/github/sandbox.js +48 -14
  29. package/dist/integrations/github/sandbox.js.map +1 -1
  30. package/dist/integrations/github/webhook.d.ts +39 -0
  31. package/dist/integrations/github/webhook.d.ts.map +1 -1
  32. package/dist/integrations/github/webhook.js +74 -13
  33. package/dist/integrations/github/webhook.js.map +1 -1
  34. package/dist/integrations/linear/integration.d.ts.map +1 -1
  35. package/dist/integrations/linear/integration.js +1 -0
  36. package/dist/integrations/linear/integration.js.map +1 -1
  37. package/dist/integrations/linear/routes.d.ts +10 -0
  38. package/dist/integrations/linear/routes.d.ts.map +1 -1
  39. package/dist/integrations/linear/routes.js +35 -1
  40. package/dist/integrations/linear/routes.js.map +1 -1
  41. package/dist/integrations/linear/rules.d.ts.map +1 -1
  42. package/dist/integrations/linear/rules.js +2 -1
  43. package/dist/integrations/linear/rules.js.map +1 -1
  44. package/dist/integrations/platform/github/event-worker.d.ts +11 -0
  45. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  46. package/dist/integrations/platform/github/event-worker.js +64 -16
  47. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  48. package/dist/integrations/platform/github/integration.d.ts +12 -0
  49. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  50. package/dist/integrations/platform/github/integration.js +47 -4
  51. package/dist/integrations/platform/github/integration.js.map +1 -1
  52. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  53. package/dist/integrations/platform/linear/integration.js +1 -0
  54. package/dist/integrations/platform/linear/integration.js.map +1 -1
  55. package/dist/integrations/slack/slack.d.ts.map +1 -1
  56. package/dist/integrations/slack/slack.js +2 -1
  57. package/dist/integrations/slack/slack.js.map +1 -1
  58. package/dist/routes/config.d.ts +12 -6
  59. package/dist/routes/config.d.ts.map +1 -1
  60. package/dist/routes/config.js +97 -56
  61. package/dist/routes/config.js.map +1 -1
  62. package/dist/routes/fs.d.ts.map +1 -1
  63. package/dist/routes/fs.js +2 -0
  64. package/dist/routes/fs.js.map +1 -1
  65. package/dist/routes/intake.d.ts +15 -0
  66. package/dist/routes/intake.d.ts.map +1 -1
  67. package/dist/routes/intake.js +65 -2
  68. package/dist/routes/intake.js.map +1 -1
  69. package/dist/routes/knowledge.d.ts +152 -0
  70. package/dist/routes/knowledge.d.ts.map +1 -0
  71. package/dist/routes/knowledge.js +442 -0
  72. package/dist/routes/knowledge.js.map +1 -0
  73. package/dist/routes/projects.d.ts +9 -1
  74. package/dist/routes/projects.d.ts.map +1 -1
  75. package/dist/routes/projects.js +8 -0
  76. package/dist/routes/projects.js.map +1 -1
  77. package/dist/routes/surface.d.ts +6 -0
  78. package/dist/routes/surface.d.ts.map +1 -1
  79. package/dist/routes/surface.js +10 -0
  80. package/dist/routes/surface.js.map +1 -1
  81. package/dist/routes/work-items.d.ts.map +1 -1
  82. package/dist/routes/work-items.js +3 -1
  83. package/dist/routes/work-items.js.map +1 -1
  84. package/dist/rules/binding-context.d.ts.map +1 -1
  85. package/dist/rules/binding-context.js +4 -1
  86. package/dist/rules/binding-context.js.map +1 -1
  87. package/dist/rules/defaults.d.ts.map +1 -1
  88. package/dist/rules/defaults.js +87 -4
  89. package/dist/rules/defaults.js.map +1 -1
  90. package/dist/rules/dispatcher.d.ts +6 -0
  91. package/dist/rules/dispatcher.d.ts.map +1 -1
  92. package/dist/rules/dispatcher.js +118 -16
  93. package/dist/rules/dispatcher.js.map +1 -1
  94. package/dist/rules/processor.d.ts.map +1 -1
  95. package/dist/rules/processor.js +20 -7
  96. package/dist/rules/processor.js.map +1 -1
  97. package/dist/rules/resolve.d.ts +1 -0
  98. package/dist/rules/resolve.d.ts.map +1 -1
  99. package/dist/rules/resolve.js +3 -2
  100. package/dist/rules/resolve.js.map +1 -1
  101. package/dist/rules/start-coordinator.d.ts +2 -0
  102. package/dist/rules/start-coordinator.d.ts.map +1 -1
  103. package/dist/rules/start-coordinator.js +3 -1
  104. package/dist/rules/start-coordinator.js.map +1 -1
  105. package/dist/rules/terminal-cleanup.d.ts +23 -0
  106. package/dist/rules/terminal-cleanup.d.ts.map +1 -0
  107. package/dist/rules/terminal-cleanup.js +43 -0
  108. package/dist/rules/terminal-cleanup.js.map +1 -0
  109. package/dist/rules/tools.d.ts.map +1 -1
  110. package/dist/rules/tools.js +24 -2
  111. package/dist/rules/tools.js.map +1 -1
  112. package/dist/rules/transition-service.d.ts +3 -0
  113. package/dist/rules/transition-service.d.ts.map +1 -1
  114. package/dist/rules/transition-service.js +10 -6
  115. package/dist/rules/transition-service.js.map +1 -1
  116. package/dist/rules/types.d.ts +32 -3
  117. package/dist/rules/types.d.ts.map +1 -1
  118. package/dist/rules/types.js +2 -0
  119. package/dist/rules/types.js.map +1 -1
  120. package/dist/rules/validation.d.ts.map +1 -1
  121. package/dist/rules/validation.js +8 -3
  122. package/dist/rules/validation.js.map +1 -1
  123. package/dist/sandbox/base-checkpoint-triggers.d.ts +77 -0
  124. package/dist/sandbox/base-checkpoint-triggers.d.ts.map +1 -0
  125. package/dist/sandbox/base-checkpoint-triggers.js +137 -0
  126. package/dist/sandbox/base-checkpoint-triggers.js.map +1 -0
  127. package/dist/sandbox/base-checkpoint.d.ts +59 -0
  128. package/dist/sandbox/base-checkpoint.d.ts.map +1 -0
  129. package/dist/sandbox/base-checkpoint.js +145 -0
  130. package/dist/sandbox/base-checkpoint.js.map +1 -0
  131. package/dist/sandbox/fleet.d.ts +32 -0
  132. package/dist/sandbox/fleet.d.ts.map +1 -1
  133. package/dist/sandbox/fleet.js +39 -10
  134. package/dist/sandbox/fleet.js.map +1 -1
  135. package/dist/session/checkpoint-capture.d.ts +3 -2
  136. package/dist/session/checkpoint-capture.d.ts.map +1 -1
  137. package/dist/session/checkpoint-capture.js +3 -3
  138. package/dist/session/checkpoint-capture.js.map +1 -1
  139. package/dist/session/factory-session.d.ts.map +1 -1
  140. package/dist/session/factory-session.js +2 -1
  141. package/dist/session/factory-session.js.map +1 -1
  142. package/dist/session/filesystem-capture.d.ts +7 -0
  143. package/dist/session/filesystem-capture.d.ts.map +1 -1
  144. package/dist/session/filesystem-capture.js +41 -4
  145. package/dist/session/filesystem-capture.js.map +1 -1
  146. package/dist/session/model-pack-hydration.d.ts +55 -0
  147. package/dist/session/model-pack-hydration.d.ts.map +1 -0
  148. package/dist/session/model-pack-hydration.js +56 -0
  149. package/dist/session/model-pack-hydration.js.map +1 -0
  150. package/dist/skills/service.d.ts +9 -0
  151. package/dist/skills/service.d.ts.map +1 -1
  152. package/dist/skills/service.js +10 -1
  153. package/dist/skills/service.js.map +1 -1
  154. package/dist/storage/domains/intake/base.d.ts +36 -0
  155. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  156. package/dist/storage/domains/intake/base.js +91 -2
  157. package/dist/storage/domains/intake/base.js.map +1 -1
  158. package/dist/storage/domains/model-packs/base.d.ts +26 -0
  159. package/dist/storage/domains/model-packs/base.d.ts.map +1 -1
  160. package/dist/storage/domains/model-packs/base.js +102 -13
  161. package/dist/storage/domains/model-packs/base.js.map +1 -1
  162. package/dist/storage/domains/source-control/base.d.ts +47 -1
  163. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  164. package/dist/storage/domains/source-control/base.js +78 -19
  165. package/dist/storage/domains/source-control/base.js.map +1 -1
  166. package/dist/storage/domains/source-control/inmemory.d.ts +11 -3
  167. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
  168. package/dist/storage/domains/source-control/inmemory.js +10 -1
  169. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  170. package/dist/storage/domains/work-items/base.d.ts +67 -1
  171. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  172. package/dist/storage/domains/work-items/base.js +183 -12
  173. package/dist/storage/domains/work-items/base.js.map +1 -1
  174. package/dist/workspace.d.ts +31 -2
  175. package/dist/workspace.d.ts.map +1 -1
  176. package/dist/workspace.js +225 -54
  177. package/dist/workspace.js.map +1 -1
  178. package/factory-skills/factory-plan/SKILL.md +1 -1
  179. package/factory-skills/factory-rereview/SKILL.md +3 -3
  180. package/factory-skills/factory-review/SKILL.md +3 -3
  181. package/factory-skills/factory-triage/SKILL.md +2 -0
  182. package/package.json +8 -8
@@ -1,10 +1,11 @@
1
1
  import { WEB_OAUTH_FLOW_KINDS, getAuthProviderId, listTenantCredentialsForRequest, resolveCredentialContext, tenantOrgId } from "./provider-credentials.js";
2
2
  import { Route } from "./route.js";
3
3
  import { applyStoredMemorySettings } from "../session/memory-settings-hydration.js";
4
+ import { applyActiveModelPack } from "../session/model-pack-hydration.js";
4
5
  import { registerApiRoute } from "@mastra/core/server";
5
6
  import { DEFAULT_OM_MODEL_ID } from "@mastra/code-sdk/constants";
6
7
  import { getAvailableModePacks, resolveProviderOMDefault } from "@mastra/code-sdk/onboarding/packs";
7
- import { THINKING_LEVEL_VALUES, THREAD_ACTIVE_MODEL_PACK_ID_KEY, getCustomProviderId, isThinkingLevelSetting, loadSettings, saveSettings } from "@mastra/code-sdk/onboarding/settings";
8
+ import { THINKING_LEVEL_VALUES, getCustomProviderId, isThinkingLevelSetting, loadSettings, saveSettings } from "@mastra/code-sdk/onboarding/settings";
8
9
  //#region src/routes/config.ts
9
10
  /** Widen a route-local Hono context to the plain `Context` the auth helpers take. */
10
11
  function loose(c) {
@@ -173,6 +174,13 @@ async function resolvePackContext({ c, auth, modelPacks }) {
173
174
  message: "Model pack storage is unavailable — the app database is not configured or failed to start."
174
175
  }, 503) };
175
176
  }
177
+ async function authorizePackSession({ c, auth, sessions, packContext, resourceId, scope }) {
178
+ if (!auth.enabled()) return null;
179
+ if (!sessions) return c.json({ error: "session_authorization_unavailable" }, 503);
180
+ const sourceSession = await sessions.getBySessionId(resourceId);
181
+ if (!sourceSession || sourceSession.orgId !== packContext.orgId || sourceSession.userId !== packContext.userId || !scope || sourceSession.sandboxWorkdir !== scope) return c.json({ error: `No session for resourceId "${resourceId}"` }, 404);
182
+ return null;
183
+ }
176
184
  /** DB row → the `ModePack` shape the packs list and activation flow consume. */
177
185
  function recordToModePack(record) {
178
186
  return {
@@ -185,8 +193,8 @@ function recordToModePack(record) {
185
193
  /**
186
194
  * List available model packs (built-in, gated by provider access, plus saved
187
195
  * custom packs from the request's pack context). Drops the synthetic
188
- * "New Custom" placeholder the web client has its own create flow. `active`
189
- * is set from the given session's thread when a resourceId is supplied.
196
+ * "New Custom" placeholder because the web client has its own create flow.
197
+ * `active` marks the user's default pack for new interactive chats.
190
198
  */
191
199
  async function listModelPacks({ controller, authStorage, tenantCredentials, packContext, activePackId }) {
192
200
  return [...getAvailableModePacks(await buildProviderAccess({
@@ -199,50 +207,11 @@ async function listModelPacks({ controller, authStorage, tenantCredentials, pack
199
207
  active: activePackId != null && p.id === activePackId
200
208
  }));
201
209
  }
202
- /** Resolve the active pack id for a session by reading its current thread. */
203
- async function resolveActivePackId(session) {
204
- if (!session) return null;
205
- const threadId = session.thread.getId();
206
- if (!threadId) return null;
207
- const value = (await session.thread.list()).find((t) => t.id === threadId)?.metadata?.[THREAD_ACTIVE_MODEL_PACK_ID_KEY];
210
+ async function resolveSessionModelPackId(session) {
211
+ if (!session?.thread.getId()) return null;
212
+ const value = await session.thread.getSetting({ key: "activeModelPackId" });
208
213
  return typeof value === "string" ? value : null;
209
214
  }
210
- /**
211
- * Apply a pack to a session: seed each mode's default model, switch the current
212
- * mode's model, set per-subagent models, and tag the thread with the active
213
- * pack id. Mirrors the TUI `applyPack` orchestration.
214
- */
215
- async function applyPackToSession({ controller, session, pack }) {
216
- const modes = controller.listModes?.() ?? [];
217
- const packModels = pack.models;
218
- for (const mode of modes) {
219
- const modelId = packModels[mode.id];
220
- if (modelId) {
221
- mode.defaultModelId = modelId;
222
- await session.thread.setSetting({
223
- key: `modeModelId_${mode.id}`,
224
- value: modelId
225
- });
226
- }
227
- }
228
- const currentModeModel = packModels[session.mode.get()];
229
- if (currentModeModel) await session.model.switch({ modelId: currentModeModel });
230
- for (const [agentType, modeId] of Object.entries({
231
- explore: "fast",
232
- plan: "plan",
233
- execute: "build"
234
- })) {
235
- const saModelId = packModels[modeId];
236
- if (saModelId) await session.subagents.model.set({
237
- modelId: saModelId,
238
- agentType
239
- });
240
- }
241
- await session.thread.setSetting({
242
- key: THREAD_ACTIVE_MODEL_PACK_ID_KEY,
243
- value: pack.id
244
- });
245
- }
246
215
  function readOMConfig(session) {
247
216
  const observeAttachments = (session.state.get() ?? {}).observeAttachments;
248
217
  return {
@@ -295,6 +264,7 @@ async function persistMemorySettings(context, patch, fillIfUnset) {
295
264
  }
296
265
  /**
297
266
  * The web config routes as Mastra `apiRoutes`:
267
+ * - `GET /web/config/features` — list server-enabled product features
298
268
  * - `GET /web/config/providers` — list providers + key source
299
269
  * - `PUT /web/config/providers/:provider/key` — set/update a provider's API key
300
270
  * - `DELETE /web/config/providers/:provider/key` — remove a stored API key
@@ -316,6 +286,11 @@ var ConfigRoutes = class extends Route {
316
286
  const onCredentialsChanged = options.onCredentialsChanged ?? (() => {});
317
287
  const onCustomProvidersChanged = options.onCustomProvidersChanged ?? (() => {});
318
288
  return [
289
+ registerApiRoute("/web/config/features", {
290
+ method: "GET",
291
+ requiresAuth: false,
292
+ handler: async (c) => c.json({ knowledge: options.features?.knowledge ?? false })
293
+ }),
319
294
  registerApiRoute("/web/config/providers", {
320
295
  method: "GET",
321
296
  requiresAuth: false,
@@ -589,7 +564,22 @@ var ConfigRoutes = class extends Route {
589
564
  const resourceId = c.req.query("resourceId");
590
565
  const scope = c.req.query("scope") || void 0;
591
566
  try {
592
- const activePackId = await resolveActivePackId(resourceId ? await controller.getSessionByResource?.(resourceId, scope) : void 0);
567
+ const activePackId = (await packContext.storage.getActive({
568
+ orgId: packContext.orgId,
569
+ userId: packContext.userId
570
+ }))?.packId ?? null;
571
+ if (resourceId) {
572
+ const unauthorized = await authorizePackSession({
573
+ c: loose(c),
574
+ auth,
575
+ sessions: options.sourceControlSessions,
576
+ packContext,
577
+ resourceId,
578
+ scope
579
+ });
580
+ if (unauthorized) return unauthorized;
581
+ }
582
+ const sessionPackId = await resolveSessionModelPackId(resourceId ? await controller.getSessionByResource?.(resourceId, scope) : void 0);
593
583
  const tenantCredentials = await listTenantCredentialsForRequest({
594
584
  c: loose(c),
595
585
  auth,
@@ -603,7 +593,8 @@ var ConfigRoutes = class extends Route {
603
593
  packContext,
604
594
  activePackId
605
595
  }),
606
- activePackId
596
+ activePackId,
597
+ sessionPackId
607
598
  });
608
599
  } catch (error) {
609
600
  return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
@@ -655,6 +646,30 @@ var ConfigRoutes = class extends Route {
655
646
  }
656
647
  }
657
648
  }),
649
+ registerApiRoute("/web/config/model-packs/active", {
650
+ method: "DELETE",
651
+ requiresAuth: false,
652
+ handler: async (c) => {
653
+ const packContext = await resolvePackContext({
654
+ c: loose(c),
655
+ auth,
656
+ modelPacks: options.modelPacks
657
+ });
658
+ if ("response" in packContext) return packContext.response;
659
+ try {
660
+ await packContext.storage.clearActive({
661
+ orgId: packContext.orgId,
662
+ userId: packContext.userId
663
+ });
664
+ return c.json({
665
+ ok: true,
666
+ activePackId: null
667
+ });
668
+ } catch (error) {
669
+ return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);
670
+ }
671
+ }
672
+ }),
658
673
  registerApiRoute("/web/config/model-packs/:id", {
659
674
  method: "DELETE",
660
675
  requiresAuth: false,
@@ -694,12 +709,25 @@ var ConfigRoutes = class extends Route {
694
709
  } catch {
695
710
  return c.json({ error: "Invalid JSON body" }, 400);
696
711
  }
697
- const resourceId = typeof body.resourceId === "string" ? body.resourceId : "";
712
+ const target = body.target ?? "default";
713
+ if (target !== "default" && target !== "session") return c.json({ error: "target must be \"default\" or \"session\"" }, 400);
714
+ const resourceId = typeof body.resourceId === "string" && body.resourceId ? body.resourceId : void 0;
698
715
  const scope = typeof body.scope === "string" && body.scope ? body.scope : void 0;
699
- if (!resourceId) return c.json({ error: "Missing required field: resourceId" }, 400);
716
+ if (target === "session" && !resourceId) return c.json({ error: "Missing required field for session activation: resourceId" }, 400);
700
717
  try {
701
- const session = await controller.getSessionByResource?.(resourceId, scope);
702
- if (!session) return c.json({ error: `No session for resourceId "${resourceId}"` }, 404);
718
+ if (target === "session" && resourceId) {
719
+ const unauthorized = await authorizePackSession({
720
+ c: loose(c),
721
+ auth,
722
+ sessions: options.sourceControlSessions,
723
+ packContext,
724
+ resourceId,
725
+ scope
726
+ });
727
+ if (unauthorized) return unauthorized;
728
+ }
729
+ const session = target === "session" && resourceId ? await controller.getSessionByResource?.(resourceId, scope) : void 0;
730
+ if (target === "session" && !session) return c.json({ error: `No session for resourceId "${resourceId}"` }, 404);
703
731
  const tenantCredentials = await listTenantCredentialsForRequest({
704
732
  c: loose(c),
705
733
  auth,
@@ -712,14 +740,27 @@ var ConfigRoutes = class extends Route {
712
740
  packContext
713
741
  })).find((p) => p.id === id);
714
742
  if (!pack) return c.json({ error: `Unknown pack "${id}"` }, 404);
715
- await applyPackToSession({
716
- controller,
717
- session,
718
- pack
743
+ if (target === "default") {
744
+ await packContext.storage.setActive({
745
+ orgId: packContext.orgId,
746
+ userId: packContext.userId,
747
+ packId: pack.id,
748
+ models: pack.models
749
+ });
750
+ return c.json({
751
+ ok: true,
752
+ target,
753
+ activePackId: pack.id
754
+ });
755
+ }
756
+ if (session) await applyActiveModelPack(session, {
757
+ packId: pack.id,
758
+ models: pack.models
719
759
  });
720
760
  return c.json({
721
761
  ok: true,
722
- activePackId: pack.id
762
+ target,
763
+ sessionPackId: pack.id
723
764
  });
724
765
  } catch (error) {
725
766
  return c.json({ error: error instanceof Error ? error.message : String(error) }, 500);