@mastra/factory 0.28.0-alpha.5 → 0.28.0-alpha.7

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 (289) hide show
  1. package/README.md +52 -28
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/auth.js +5 -5
  4. package/dist/auth.js.map +1 -1
  5. package/dist/boards/board-writes.d.ts +1 -1
  6. package/dist/boards/board-writes.d.ts.map +1 -1
  7. package/dist/boards/board-writes.js +7 -8
  8. package/dist/boards/board-writes.js.map +1 -1
  9. package/dist/boards/index.d.ts +1 -1
  10. package/dist/boards/index.d.ts.map +1 -1
  11. package/dist/boards/index.js +2 -2
  12. package/dist/boards/project-boards.d.ts +30 -4
  13. package/dist/boards/project-boards.d.ts.map +1 -1
  14. package/dist/boards/project-boards.js +71 -19
  15. package/dist/boards/project-boards.js.map +1 -1
  16. package/dist/boards/registry.d.ts +7 -1
  17. package/dist/boards/registry.d.ts.map +1 -1
  18. package/dist/boards/registry.js +16 -3
  19. package/dist/boards/registry.js.map +1 -1
  20. package/dist/boards/semantics.d.ts +5 -4
  21. package/dist/boards/semantics.d.ts.map +1 -1
  22. package/dist/boards/semantics.js +5 -4
  23. package/dist/boards/semantics.js.map +1 -1
  24. package/dist/boards/work-migrations.d.ts +4 -3
  25. package/dist/boards/work-migrations.d.ts.map +1 -1
  26. package/dist/boards/work-migrations.js +6 -5
  27. package/dist/boards/work-migrations.js.map +1 -1
  28. package/dist/boards/work-seeds.d.ts +9 -0
  29. package/dist/boards/work-seeds.d.ts.map +1 -0
  30. package/dist/boards/work-seeds.js +56 -0
  31. package/dist/boards/work-seeds.js.map +1 -0
  32. package/dist/boards/work.d.ts +2 -2
  33. package/dist/boards/work.d.ts.map +1 -1
  34. package/dist/boards/work.js +0 -16
  35. package/dist/boards/work.js.map +1 -1
  36. package/dist/environment/build-runner.d.ts.map +1 -1
  37. package/dist/environment/build-runner.js +2 -2
  38. package/dist/environment/build-runner.js.map +1 -1
  39. package/dist/environment/build-workflow.d.ts.map +1 -1
  40. package/dist/environment/build-workflow.js +6 -5
  41. package/dist/environment/build-workflow.js.map +1 -1
  42. package/dist/environment/build.d.ts +15 -2
  43. package/dist/environment/build.d.ts.map +1 -1
  44. package/dist/environment/build.js +32 -9
  45. package/dist/environment/build.js.map +1 -1
  46. package/dist/factory.d.ts +8 -4
  47. package/dist/factory.d.ts.map +1 -1
  48. package/dist/factory.js +57 -59
  49. package/dist/factory.js.map +1 -1
  50. package/dist/feed-events.d.ts +2 -3
  51. package/dist/feed-events.d.ts.map +1 -1
  52. package/dist/feed-events.js +4 -5
  53. package/dist/feed-events.js.map +1 -1
  54. package/dist/index.d.ts +2 -0
  55. package/dist/index.d.ts.map +1 -1
  56. package/dist/index.js +3 -1
  57. package/dist/integrations/base.d.ts +0 -11
  58. package/dist/integrations/base.d.ts.map +1 -1
  59. package/dist/integrations/github/integration.d.ts.map +1 -1
  60. package/dist/integrations/github/integration.js +7 -3
  61. package/dist/integrations/github/integration.js.map +1 -1
  62. package/dist/integrations/github/issue-reconciler.js +2 -2
  63. package/dist/integrations/github/issue-reconciler.js.map +1 -1
  64. package/dist/integrations/github/provenance.js +1 -1
  65. package/dist/integrations/github/provenance.js.map +1 -1
  66. package/dist/integrations/github/reconcile-worker.d.ts +5 -1
  67. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
  68. package/dist/integrations/github/reconcile-worker.js +39 -6
  69. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  70. package/dist/integrations/github/routes.d.ts +4 -3
  71. package/dist/integrations/github/routes.d.ts.map +1 -1
  72. package/dist/integrations/github/routes.js +9 -86
  73. package/dist/integrations/github/routes.js.map +1 -1
  74. package/dist/integrations/github/rules.d.ts +67 -0
  75. package/dist/integrations/github/rules.d.ts.map +1 -1
  76. package/dist/integrations/github/rules.js +215 -12
  77. package/dist/integrations/github/rules.js.map +1 -1
  78. package/dist/integrations/github/sandbox.d.ts +10 -2
  79. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  80. package/dist/integrations/github/sandbox.js +20 -4
  81. package/dist/integrations/github/sandbox.js.map +1 -1
  82. package/dist/integrations/gitlab/merge-request-reconciler.js +1 -1
  83. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
  84. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  85. package/dist/integrations/gitlab/rules.js +6 -5
  86. package/dist/integrations/gitlab/rules.js.map +1 -1
  87. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  88. package/dist/integrations/incidentio/rules.js +5 -2
  89. package/dist/integrations/incidentio/rules.js.map +1 -1
  90. package/dist/integrations/issue-reconciler.js +1 -1
  91. package/dist/integrations/issue-reconciler.js.map +1 -1
  92. package/dist/integrations/jira/rules.d.ts.map +1 -1
  93. package/dist/integrations/jira/rules.js +5 -2
  94. package/dist/integrations/jira/rules.js.map +1 -1
  95. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  96. package/dist/integrations/linear/agent-tools.js +1 -1
  97. package/dist/integrations/linear/agent-tools.js.map +1 -1
  98. package/dist/integrations/linear/rules.d.ts.map +1 -1
  99. package/dist/integrations/linear/rules.js +2 -2
  100. package/dist/integrations/linear/rules.js.map +1 -1
  101. package/dist/integrations/platform/github/event-worker.d.ts +4 -1
  102. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  103. package/dist/integrations/platform/github/event-worker.js +39 -3
  104. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  105. package/dist/integrations/platform/github/integration.d.ts +8 -0
  106. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  107. package/dist/integrations/platform/github/integration.js +21 -3
  108. package/dist/integrations/platform/github/integration.js.map +1 -1
  109. package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
  110. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
  111. package/dist/integrations/platform/linear/event-worker.js +1 -1
  112. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  113. package/dist/integrations/slack/integration.d.ts +0 -2
  114. package/dist/integrations/slack/integration.d.ts.map +1 -1
  115. package/dist/integrations/slack/integration.js +0 -5
  116. package/dist/integrations/slack/integration.js.map +1 -1
  117. package/dist/integrations/slack/slack.d.ts +3 -18
  118. package/dist/integrations/slack/slack.d.ts.map +1 -1
  119. package/dist/integrations/slack/slack.js +3 -74
  120. package/dist/integrations/slack/slack.js.map +1 -1
  121. package/dist/links.d.ts +1 -2
  122. package/dist/links.d.ts.map +1 -1
  123. package/dist/links.js +1 -2
  124. package/dist/links.js.map +1 -1
  125. package/dist/mcp/routes.js +1 -1
  126. package/dist/mcp/routes.js.map +1 -1
  127. package/dist/routes/attention-parked.js +1 -1
  128. package/dist/routes/attention-parked.js.map +1 -1
  129. package/dist/routes/attention-providers.d.ts +0 -25
  130. package/dist/routes/attention-providers.d.ts.map +1 -1
  131. package/dist/routes/attention-providers.js +2 -150
  132. package/dist/routes/attention-providers.js.map +1 -1
  133. package/dist/routes/attention.d.ts +0 -2
  134. package/dist/routes/attention.d.ts.map +1 -1
  135. package/dist/routes/attention.js +2 -13
  136. package/dist/routes/attention.js.map +1 -1
  137. package/dist/routes/boards.d.ts +1 -1
  138. package/dist/routes/boards.d.ts.map +1 -1
  139. package/dist/routes/boards.js.map +1 -1
  140. package/dist/routes/contracts.d.ts +121 -14
  141. package/dist/routes/contracts.d.ts.map +1 -1
  142. package/dist/routes/contracts.js +73 -3
  143. package/dist/routes/contracts.js.map +1 -1
  144. package/dist/routes/feed-events.d.ts +15 -0
  145. package/dist/routes/feed-events.d.ts.map +1 -0
  146. package/dist/routes/feed-events.js +68 -0
  147. package/dist/routes/feed-events.js.map +1 -0
  148. package/dist/routes/knowledge.js +1 -1
  149. package/dist/routes/projects.d.ts +1 -1
  150. package/dist/routes/projects.d.ts.map +1 -1
  151. package/dist/routes/projects.js +13 -7
  152. package/dist/routes/projects.js.map +1 -1
  153. package/dist/routes/sandbox-envs.d.ts +26 -0
  154. package/dist/routes/sandbox-envs.d.ts.map +1 -0
  155. package/dist/routes/sandbox-envs.js +180 -0
  156. package/dist/routes/sandbox-envs.js.map +1 -0
  157. package/dist/routes/surface.d.ts +0 -7
  158. package/dist/routes/surface.d.ts.map +1 -1
  159. package/dist/routes/surface.js +1 -5
  160. package/dist/routes/surface.js.map +1 -1
  161. package/dist/routes/work-items.d.ts +0 -3
  162. package/dist/routes/work-items.d.ts.map +1 -1
  163. package/dist/routes/work-items.js +1 -2
  164. package/dist/routes/work-items.js.map +1 -1
  165. package/dist/rules/dispatcher.d.ts +0 -3
  166. package/dist/rules/dispatcher.d.ts.map +1 -1
  167. package/dist/rules/dispatcher.js +8 -9
  168. package/dist/rules/dispatcher.js.map +1 -1
  169. package/dist/sandbox/sandbox-env-cache.d.ts +33 -0
  170. package/dist/sandbox/sandbox-env-cache.d.ts.map +1 -0
  171. package/dist/sandbox/sandbox-env-cache.js +140 -0
  172. package/dist/sandbox/sandbox-env-cache.js.map +1 -0
  173. package/dist/sandbox/sandbox-env.d.ts +77 -0
  174. package/dist/sandbox/sandbox-env.d.ts.map +1 -0
  175. package/dist/sandbox/sandbox-env.js +130 -0
  176. package/dist/sandbox/sandbox-env.js.map +1 -0
  177. package/dist/storage/domains/audit/actions.d.ts +2 -1
  178. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  179. package/dist/storage/domains/audit/actions.js +5 -4
  180. package/dist/storage/domains/audit/actions.js.map +1 -1
  181. package/dist/storage/domains/boards/base.d.ts +15 -1
  182. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  183. package/dist/storage/domains/boards/base.js +21 -5
  184. package/dist/storage/domains/boards/base.js.map +1 -1
  185. package/dist/storage/domains/channel-identity/base.d.ts +0 -4
  186. package/dist/storage/domains/channel-identity/base.d.ts.map +1 -1
  187. package/dist/storage/domains/channel-identity/base.js +0 -7
  188. package/dist/storage/domains/channel-identity/base.js.map +1 -1
  189. package/dist/storage/domains/sandbox-envs/base.d.ts +70 -0
  190. package/dist/storage/domains/sandbox-envs/base.d.ts.map +1 -0
  191. package/dist/storage/domains/sandbox-envs/base.js +227 -0
  192. package/dist/storage/domains/sandbox-envs/base.js.map +1 -0
  193. package/dist/storage/domains/work-items/base.d.ts +8 -9
  194. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  195. package/dist/storage/domains/work-items/base.js +20 -86
  196. package/dist/storage/domains/work-items/base.js.map +1 -1
  197. package/dist/storage/domains/work-items/cards.d.ts +3 -3
  198. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  199. package/dist/storage/domains/work-items/cards.js +10 -10
  200. package/dist/storage/domains/work-items/cards.js.map +1 -1
  201. package/dist/storage/domains/work-items/metrics.d.ts +1 -1
  202. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
  203. package/dist/storage/domains/work-items/metrics.js.map +1 -1
  204. package/dist/storage/domains/work-items/work-item-schema.d.ts +1 -2
  205. package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
  206. package/dist/storage/domains/work-items/work-item-schema.js +8 -8
  207. package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
  208. package/dist/tools/read-tools.d.ts +0 -2
  209. package/dist/tools/read-tools.d.ts.map +1 -1
  210. package/dist/tools/read-tools.js +3 -14
  211. package/dist/tools/read-tools.js.map +1 -1
  212. package/dist/tools/work-item-tools.d.ts +0 -3
  213. package/dist/tools/work-item-tools.d.ts.map +1 -1
  214. package/dist/tools/work-item-tools.js +8 -18
  215. package/dist/tools/work-item-tools.js.map +1 -1
  216. package/dist/work-items/create-work-item.d.ts.map +1 -1
  217. package/dist/work-items/create-work-item.js +3 -2
  218. package/dist/work-items/create-work-item.js.map +1 -1
  219. package/dist/work-items/description-context.d.ts +5 -0
  220. package/dist/work-items/description-context.d.ts.map +1 -0
  221. package/dist/work-items/description-context.js +17 -0
  222. package/dist/work-items/description-context.js.map +1 -0
  223. package/dist/work-items/split-migration.d.ts.map +1 -1
  224. package/dist/work-items/split-migration.js +1 -6
  225. package/dist/work-items/split-migration.js.map +1 -1
  226. package/dist/workspace.d.ts +3 -0
  227. package/dist/workspace.d.ts.map +1 -1
  228. package/dist/workspace.js +21 -4
  229. package/dist/workspace.js.map +1 -1
  230. package/factory-skills/configure-factory-rules/SKILL.md +3 -3
  231. package/factory-skills/factory-rereview/SKILL.md +2 -2
  232. package/factory-skills/factory-review/SKILL.md +2 -2
  233. package/factory-skills/factory-triage/SKILL.md +3 -2
  234. package/package.json +7 -7
  235. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts +0 -8
  236. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts.map +0 -1
  237. package/dist/integrations/slack/emoji-shortcodes.generated.js +0 -1984
  238. package/dist/integrations/slack/emoji-shortcodes.generated.js.map +0 -1
  239. package/dist/integrations/slack/emoji.d.ts +0 -3
  240. package/dist/integrations/slack/emoji.d.ts.map +0 -1
  241. package/dist/integrations/slack/emoji.js +0 -11
  242. package/dist/integrations/slack/emoji.js.map +0 -1
  243. package/dist/integrations/slack/feed-publisher.d.ts +0 -26
  244. package/dist/integrations/slack/feed-publisher.d.ts.map +0 -1
  245. package/dist/integrations/slack/feed-publisher.js +0 -43
  246. package/dist/integrations/slack/feed-publisher.js.map +0 -1
  247. package/dist/routes/attention-activity.d.ts +0 -23
  248. package/dist/routes/attention-activity.d.ts.map +0 -1
  249. package/dist/routes/attention-activity.js +0 -154
  250. package/dist/routes/attention-activity.js.map +0 -1
  251. package/dist/storage/domains/comments/activity.d.ts +0 -40
  252. package/dist/storage/domains/comments/activity.d.ts.map +0 -1
  253. package/dist/storage/domains/comments/activity.js +0 -93
  254. package/dist/storage/domains/comments/activity.js.map +0 -1
  255. package/dist/storage/domains/comments/actor.d.ts +0 -51
  256. package/dist/storage/domains/comments/actor.d.ts.map +0 -1
  257. package/dist/storage/domains/comments/actor.js +0 -37
  258. package/dist/storage/domains/comments/actor.js.map +0 -1
  259. package/dist/storage/domains/comments/base.d.ts +0 -245
  260. package/dist/storage/domains/comments/base.d.ts.map +0 -1
  261. package/dist/storage/domains/comments/base.js +0 -539
  262. package/dist/storage/domains/comments/base.js.map +0 -1
  263. package/dist/storage/domains/comments/domain.d.ts +0 -135
  264. package/dist/storage/domains/comments/domain.d.ts.map +0 -1
  265. package/dist/storage/domains/comments/domain.js +0 -284
  266. package/dist/storage/domains/comments/domain.js.map +0 -1
  267. package/dist/storage/domains/comments/feed-context.d.ts +0 -22
  268. package/dist/storage/domains/comments/feed-context.d.ts.map +0 -1
  269. package/dist/storage/domains/comments/feed-context.js +0 -88
  270. package/dist/storage/domains/comments/feed-context.js.map +0 -1
  271. package/dist/storage/domains/comments/feed-sync.d.ts +0 -21
  272. package/dist/storage/domains/comments/feed-sync.d.ts.map +0 -1
  273. package/dist/storage/domains/comments/feed-sync.js +0 -1
  274. package/dist/storage/domains/comments/parse.d.ts +0 -23
  275. package/dist/storage/domains/comments/parse.d.ts.map +0 -1
  276. package/dist/storage/domains/comments/parse.js +0 -89
  277. package/dist/storage/domains/comments/parse.js.map +0 -1
  278. package/dist/storage/domains/comments/routes.d.ts +0 -24
  279. package/dist/storage/domains/comments/routes.d.ts.map +0 -1
  280. package/dist/storage/domains/comments/routes.js +0 -301
  281. package/dist/storage/domains/comments/routes.js.map +0 -1
  282. package/dist/storage/domains/comments/schema.d.ts +0 -5
  283. package/dist/storage/domains/comments/schema.d.ts.map +0 -1
  284. package/dist/storage/domains/comments/schema.js +0 -178
  285. package/dist/storage/domains/comments/schema.js.map +0 -1
  286. package/dist/storage/domains/comments/wire.d.ts +0 -40
  287. package/dist/storage/domains/comments/wire.d.ts.map +0 -1
  288. package/dist/storage/domains/comments/wire.js +0 -36
  289. package/dist/storage/domains/comments/wire.js.map +0 -1
@@ -0,0 +1,33 @@
1
+ import type { PubSub } from '@mastra/core/events';
2
+ import type { ResolvedSandboxEnvs, SandboxEnvAppliesTo, SandboxEnvMetadata, SandboxEnvRevisions, SandboxEnvStore, SetSandboxEnvInput } from '../storage/domains/sandbox-envs/base.js';
3
+ /** One topic for every Factory: a replica drops its cached entry for the Factory named in the event. */
4
+ export declare const SANDBOX_ENV_CHANGED_TOPIC = "factory.sandbox-env";
5
+ /**
6
+ * The sandbox-envs store with reads served from memory. The revision is
7
+ * re-read only when a write is announced (by this replica or another one
8
+ * through the event bus) or the read gets old, and values are decrypted again
9
+ * only when the revision changed. Commands and workspace resolves then cost
10
+ * no storage reads while nobody edits a variable.
11
+ *
12
+ * Writes go through to the store, drop this replica's entry and announce the
13
+ * change, so the next command anywhere sees it.
14
+ */
15
+ export declare class CachedSandboxEnvs implements SandboxEnvStore {
16
+ #private;
17
+ private readonly store;
18
+ private readonly options;
19
+ constructor(store: SandboxEnvStore, options?: {
20
+ pubsub?: PubSub;
21
+ crossProcess?: boolean;
22
+ now?: () => number;
23
+ });
24
+ /** Listen for other replicas' writes; resolves to the unsubscribe. */
25
+ subscribe(): Promise<() => Promise<void>>;
26
+ list(orgId: string, projectId: string): Promise<SandboxEnvMetadata[]>;
27
+ set(orgId: string, projectId: string, input: SetSandboxEnvInput, actorId: string): Promise<SandboxEnvMetadata>;
28
+ updateAppliesTo(orgId: string, projectId: string, name: string, appliesTo: SandboxEnvAppliesTo, actorId: string): Promise<SandboxEnvMetadata | null>;
29
+ delete(orgId: string, projectId: string, name: string): Promise<boolean>;
30
+ revisions(orgId: string, projectId: string): Promise<SandboxEnvRevisions | null>;
31
+ resolve(orgId: string, projectId: string): Promise<ResolvedSandboxEnvs>;
32
+ }
33
+ //# sourceMappingURL=sandbox-env-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-env-cache.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-env-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGjE,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EACnB,MAAM,yCAAyC,CAAC;AAEjD,wGAAwG;AACxG,eAAO,MAAM,yBAAyB,wBAAwB,CAAC;AAoB/D;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,YAAW,eAAe;;IAWrD,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAF1B,YACmB,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,CAAC,EAAE,OAAO,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;KAAO,EAG/F;IAED,sEAAsE;IAChE,SAAS,IAAI,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAM9C;IAED,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAEpE;IAEK,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,+BAIrF;IAEK,eAAe,CACnB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,mBAAmB,EAC9B,OAAO,EAAE,MAAM,sCAKhB;IAEK,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,oBAI1D;IAED,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAE/E;IAEK,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAoB5E;CAgCF"}
@@ -0,0 +1,140 @@
1
+ import { withAck } from "@mastra/core/events";
2
+ // src/sandbox/sandbox-env-cache.ts
3
+ /** One topic for every Factory: a replica drops its cached entry for the Factory named in the event. */
4
+ const SANDBOX_ENV_CHANGED_TOPIC = "factory.sandbox-env";
5
+ /**
6
+ * How long a revision read is trusted without hearing of a change. With a
7
+ * cross-process event bus, other replicas announce their writes, so this is
8
+ * only a safety net for a missed event. Without one, a write on another
9
+ * replica is only seen when the read expires.
10
+ */
11
+ const TRUST_WITH_EVENTS_MS = 6e4;
12
+ const TRUST_WITHOUT_EVENTS_MS = 1e3;
13
+ /**
14
+ * The sandbox-envs store with reads served from memory. The revision is
15
+ * re-read only when a write is announced (by this replica or another one
16
+ * through the event bus) or the read gets old, and values are decrypted again
17
+ * only when the revision changed. Commands and workspace resolves then cost
18
+ * no storage reads while nobody edits a variable.
19
+ *
20
+ * Writes go through to the store, drop this replica's entry and announce the
21
+ * change, so the next command anywhere sees it.
22
+ */
23
+ var CachedSandboxEnvs = class {
24
+ store;
25
+ options;
26
+ #entries = /* @__PURE__ */ new Map();
27
+ #origin = globalThis.crypto.randomUUID();
28
+ #trustMs;
29
+ #onEvent = withAck(async (event) => {
30
+ if (event.runId === this.#origin) return;
31
+ const { orgId, projectId } = event.data ?? {};
32
+ if (typeof orgId === "string" && typeof projectId === "string") this.#forget({
33
+ orgId,
34
+ projectId
35
+ });
36
+ });
37
+ constructor(store, options = {}) {
38
+ this.store = store;
39
+ this.options = options;
40
+ this.#trustMs = options.crossProcess ? TRUST_WITH_EVENTS_MS : TRUST_WITHOUT_EVENTS_MS;
41
+ }
42
+ /** Listen for other replicas' writes; resolves to the unsubscribe. */
43
+ async subscribe() {
44
+ const pubsub = this.options.pubsub;
45
+ if (!pubsub) return async () => {};
46
+ await pubsub.subscribe(SANDBOX_ENV_CHANGED_TOPIC, this.#onEvent, { startFrom: "latest" });
47
+ return () => pubsub.unsubscribe(SANDBOX_ENV_CHANGED_TOPIC, this.#onEvent);
48
+ }
49
+ list(orgId, projectId) {
50
+ return this.store.list(orgId, projectId);
51
+ }
52
+ async set(orgId, projectId, input, actorId) {
53
+ const env = await this.store.set(orgId, projectId, input, actorId);
54
+ this.#changed({
55
+ orgId,
56
+ projectId
57
+ });
58
+ return env;
59
+ }
60
+ async updateAppliesTo(orgId, projectId, name, appliesTo, actorId) {
61
+ const env = await this.store.updateAppliesTo(orgId, projectId, name, appliesTo, actorId);
62
+ if (env) this.#changed({
63
+ orgId,
64
+ projectId
65
+ });
66
+ return env;
67
+ }
68
+ async delete(orgId, projectId, name) {
69
+ const deleted = await this.store.delete(orgId, projectId, name);
70
+ if (deleted) this.#changed({
71
+ orgId,
72
+ projectId
73
+ });
74
+ return deleted;
75
+ }
76
+ revisions(orgId, projectId) {
77
+ return this.#entry({
78
+ orgId,
79
+ projectId
80
+ }).revisions;
81
+ }
82
+ async resolve(orgId, projectId) {
83
+ const entry = this.#entry({
84
+ orgId,
85
+ projectId
86
+ });
87
+ const current = (await entry.revisions)?.revision ?? "";
88
+ if (entry.resolved) {
89
+ const cached = await entry.resolved.catch(() => void 0);
90
+ if (cached?.revision === current) return cached;
91
+ }
92
+ const resolved = this.store.resolve(orgId, projectId);
93
+ entry.resolved = resolved;
94
+ resolved.then(({ revision, buildRevision }) => {
95
+ if (revision !== current) entry.revisions = Promise.resolve({
96
+ revision,
97
+ buildRevision
98
+ });
99
+ }, () => {
100
+ if (entry.resolved === resolved) entry.resolved = void 0;
101
+ });
102
+ return resolved;
103
+ }
104
+ #entry(scope) {
105
+ const key = keyOf(scope);
106
+ const now = (this.options.now ?? Date.now)();
107
+ const existing = this.#entries.get(key);
108
+ if (existing && now - existing.at < this.#trustMs) return existing;
109
+ const revisions = this.store.revisions(scope.orgId, scope.projectId);
110
+ const entry = {
111
+ at: now,
112
+ revisions,
113
+ ...existing?.resolved ? { resolved: existing.resolved } : {}
114
+ };
115
+ this.#entries.set(key, entry);
116
+ revisions.catch(() => {
117
+ if (this.#entries.get(key) === entry) this.#entries.delete(key);
118
+ });
119
+ return entry;
120
+ }
121
+ #forget(scope) {
122
+ this.#entries.delete(keyOf(scope));
123
+ }
124
+ #changed(scope) {
125
+ this.#forget(scope);
126
+ this.options.pubsub?.publish(SANDBOX_ENV_CHANGED_TOPIC, {
127
+ type: "factory.sandbox-env.changed",
128
+ runId: this.#origin,
129
+ data: scope
130
+ }).catch((error) => {
131
+ console.warn("[Factory] Failed to announce a sandbox environment variable change", { error: error instanceof Error ? error.message : String(error) });
132
+ });
133
+ }
134
+ };
135
+ function keyOf(scope) {
136
+ return `${scope.orgId}\u0000${scope.projectId}`;
137
+ }
138
+ export { CachedSandboxEnvs, SANDBOX_ENV_CHANGED_TOPIC };
139
+
140
+ //# sourceMappingURL=sandbox-env-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-env-cache.js","names":[],"sources":["../../src/sandbox/sandbox-env-cache.ts"],"sourcesContent":["import type { EventCallback, PubSub } from '@mastra/core/events';\nimport { withAck } from '@mastra/core/events';\n\nimport type {\n ResolvedSandboxEnvs,\n SandboxEnvAppliesTo,\n SandboxEnvMetadata,\n SandboxEnvRevisions,\n SandboxEnvStore,\n SetSandboxEnvInput,\n} from '../storage/domains/sandbox-envs/base.js';\n\n/** One topic for every Factory: a replica drops its cached entry for the Factory named in the event. */\nexport const SANDBOX_ENV_CHANGED_TOPIC = 'factory.sandbox-env';\n\n/**\n * How long a revision read is trusted without hearing of a change. With a\n * cross-process event bus, other replicas announce their writes, so this is\n * only a safety net for a missed event. Without one, a write on another\n * replica is only seen when the read expires.\n */\nconst TRUST_WITH_EVENTS_MS = 60_000;\nconst TRUST_WITHOUT_EVENTS_MS = 1_000;\n\ntype Scope = { orgId: string; projectId: string };\n\ninterface Entry {\n at: number;\n revisions: Promise<SandboxEnvRevisions | null>;\n /** Decrypted values, reused while the revision they were read at is current. */\n resolved?: Promise<ResolvedSandboxEnvs>;\n}\n\n/**\n * The sandbox-envs store with reads served from memory. The revision is\n * re-read only when a write is announced (by this replica or another one\n * through the event bus) or the read gets old, and values are decrypted again\n * only when the revision changed. Commands and workspace resolves then cost\n * no storage reads while nobody edits a variable.\n *\n * Writes go through to the store, drop this replica's entry and announce the\n * change, so the next command anywhere sees it.\n */\nexport class CachedSandboxEnvs implements SandboxEnvStore {\n readonly #entries = new Map<string, Entry>();\n readonly #origin = globalThis.crypto.randomUUID();\n readonly #trustMs: number;\n readonly #onEvent: EventCallback = withAck(async event => {\n if (event.runId === this.#origin) return;\n const { orgId, projectId } = (event.data ?? {}) as Partial<Scope>;\n if (typeof orgId === 'string' && typeof projectId === 'string') this.#forget({ orgId, projectId });\n });\n\n constructor(\n private readonly store: SandboxEnvStore,\n private readonly options: { pubsub?: PubSub; crossProcess?: boolean; now?: () => number } = {},\n ) {\n this.#trustMs = options.crossProcess ? TRUST_WITH_EVENTS_MS : TRUST_WITHOUT_EVENTS_MS;\n }\n\n /** Listen for other replicas' writes; resolves to the unsubscribe. */\n async subscribe(): Promise<() => Promise<void>> {\n const pubsub = this.options.pubsub;\n if (!pubsub) return async () => {};\n // Without `latest`, a retaining broker replays old changes on boot.\n await pubsub.subscribe(SANDBOX_ENV_CHANGED_TOPIC, this.#onEvent, { startFrom: 'latest' });\n return () => pubsub.unsubscribe(SANDBOX_ENV_CHANGED_TOPIC, this.#onEvent);\n }\n\n list(orgId: string, projectId: string): Promise<SandboxEnvMetadata[]> {\n return this.store.list(orgId, projectId);\n }\n\n async set(orgId: string, projectId: string, input: SetSandboxEnvInput, actorId: string) {\n const env = await this.store.set(orgId, projectId, input, actorId);\n this.#changed({ orgId, projectId });\n return env;\n }\n\n async updateAppliesTo(\n orgId: string,\n projectId: string,\n name: string,\n appliesTo: SandboxEnvAppliesTo,\n actorId: string,\n ) {\n const env = await this.store.updateAppliesTo(orgId, projectId, name, appliesTo, actorId);\n if (env) this.#changed({ orgId, projectId });\n return env;\n }\n\n async delete(orgId: string, projectId: string, name: string) {\n const deleted = await this.store.delete(orgId, projectId, name);\n if (deleted) this.#changed({ orgId, projectId });\n return deleted;\n }\n\n revisions(orgId: string, projectId: string): Promise<SandboxEnvRevisions | null> {\n return this.#entry({ orgId, projectId }).revisions;\n }\n\n async resolve(orgId: string, projectId: string): Promise<ResolvedSandboxEnvs> {\n const entry = this.#entry({ orgId, projectId });\n const current = (await entry.revisions)?.revision ?? '';\n if (entry.resolved) {\n const cached = await entry.resolved.catch(() => undefined);\n if (cached?.revision === current) return cached;\n }\n const resolved = this.store.resolve(orgId, projectId);\n entry.resolved = resolved;\n resolved.then(\n // The values carry their own revision; adopt it so the next call matches instead of decrypting again.\n ({ revision, buildRevision }) => {\n if (revision !== current) entry.revisions = Promise.resolve({ revision, buildRevision });\n },\n // Keep only a read that succeeded.\n () => {\n if (entry.resolved === resolved) entry.resolved = undefined;\n },\n );\n return resolved;\n }\n\n #entry(scope: Scope): Entry {\n const key = keyOf(scope);\n const now = (this.options.now ?? Date.now)();\n const existing = this.#entries.get(key);\n if (existing && now - existing.at < this.#trustMs) return existing;\n const revisions = this.store.revisions(scope.orgId, scope.projectId);\n // The decrypted values survive a re-read: `resolve` reuses them if the revision didn't move.\n const entry: Entry = { at: now, revisions, ...(existing?.resolved ? { resolved: existing.resolved } : {}) };\n this.#entries.set(key, entry);\n // A failed read is never served from memory.\n revisions.catch(() => {\n if (this.#entries.get(key) === entry) this.#entries.delete(key);\n });\n return entry;\n }\n\n #forget(scope: Scope): void {\n this.#entries.delete(keyOf(scope));\n }\n\n #changed(scope: Scope): void {\n this.#forget(scope);\n this.options.pubsub\n ?.publish(SANDBOX_ENV_CHANGED_TOPIC, { type: 'factory.sandbox-env.changed', runId: this.#origin, data: scope })\n .catch((error: unknown) => {\n console.warn('[Factory] Failed to announce a sandbox environment variable change', {\n error: error instanceof Error ? error.message : String(error),\n });\n });\n }\n}\n\nfunction keyOf(scope: Scope): string {\n return `${scope.orgId}\\u0000${scope.projectId}`;\n}\n"],"mappings":";;;AAaA,MAAa,4BAA4B;;;;;;;AAQzC,MAAM,uBAAuB;AAC7B,MAAM,0BAA0B;;;;;;;;;;;AAqBhC,IAAa,oBAAb,MAA0D;CAWrC;CACA;CAXnB,2BAAoB,IAAI,IAAmB;CAC3C,UAAm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,QACT,QAAQ,2BAA2B;GAAE,MAAM;GAA+B,OAAO,KAAK;GAAS,MAAM;EAAM,CAAC,CAAC,CAC9G,OAAO,UAAmB;GACzB,QAAQ,KAAK,sEAAsE,EACjF,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAC9D,CAAC;EACH,CAAC;CACL;AACF;AAEA,SAAS,MAAM,OAAsB;CACnC,OAAO,GAAG,MAAM,MAAM,QAAQ,MAAM;AACtC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Sandbox environment variables: what a session sandbox's commands and builds
3
+ * get from the Factory's stored variables, and how a running sandbox picks up
4
+ * edits on its next command.
5
+ */
6
+ import type { FactorySandboxContext } from '@mastra/core/workspace';
7
+ import type { SandboxEnvStore } from '../storage/domains/sandbox-envs/base.js';
8
+ export interface SandboxEnv {
9
+ /** Variables every command in the sandbox gets. */
10
+ runtime: Record<string, string>;
11
+ /** Variables template builds and Factory-run setup commands get; never runtime commands. */
12
+ build: Record<string, string>;
13
+ /** Read before the values: an edit landing in between makes the next check reload. */
14
+ revision: string;
15
+ buildRevision: string;
16
+ }
17
+ /**
18
+ * The single place a sandbox's environment is resolved. v1 reads only the
19
+ * Factory-wide variables; personal and session layers merge in here later,
20
+ * with session over personal over Factory, so callers never change.
21
+ */
22
+ export declare function resolveSandboxEnv(store: Pick<SandboxEnvStore, 'resolve'>, scope: {
23
+ orgId: string;
24
+ projectId: string;
25
+ }): Promise<SandboxEnv>;
26
+ /**
27
+ * `resolveSandboxEnv` for session boot and setup: a failed read (a storage
28
+ * blip, a value encrypted with a removed key) is logged and yields no Factory
29
+ * variables, so it can't stop a session from starting. Its empty revision
30
+ * makes the first command's refresh try again.
31
+ */
32
+ export declare function resolveSandboxEnvOrEmpty(store: Pick<SandboxEnvStore, 'resolve'>, scope: {
33
+ orgId: string;
34
+ projectId: string;
35
+ }): Promise<SandboxEnv>;
36
+ /**
37
+ * The template-build fields of a sandbox context. Omitted when the Factory has
38
+ * no Build variables, so the template identity matches one built without them.
39
+ * Session boot and environment builds share this, so both name the same template.
40
+ */
41
+ export declare function sandboxBuildContext(env: SandboxEnv | undefined): Pick<FactorySandboxContext, 'buildEnv' | 'buildEnvRevision'>;
42
+ /**
43
+ * Replace every Build value that appears in provider or command output with
44
+ * `***`. Each value is also matched without its edge whitespace, since output
45
+ * often drops a pasted trailing space or newline. Longest first, so a value
46
+ * that contains another is masked whole.
47
+ */
48
+ export declare function maskSandboxEnvValues(text: string, env: Record<string, string> | undefined): string;
49
+ type EnvOverlay = Record<string, string | undefined>;
50
+ /**
51
+ * The Factory runtime values currently applied to a sandbox, so output from a
52
+ * command that ran in it (a failed teardown) can be masked without a storage read.
53
+ */
54
+ export declare function appliedSandboxEnv(sandbox: object): Record<string, string>;
55
+ export interface RefreshableSandbox {
56
+ ensureRunning?: () => Promise<void>;
57
+ setEnv?: (update: (env: EnvOverlay) => EnvOverlay) => void;
58
+ }
59
+ /**
60
+ * Apply the Factory's runtime variables to a sandbox's env overlay and keep
61
+ * them current: after every `ensureRunning()` (which every command path awaits
62
+ * before reading the overlay) the Factory revision is checked, and on a change
63
+ * the variables are reloaded and re-applied, so an add, edit or delete reaches
64
+ * the next command. Processes already running keep the env they started with.
65
+ *
66
+ * A key the sandbox already had (its host `env`) is remembered before Factory
67
+ * first writes it and restored when the Factory variable goes away. A refresh
68
+ * that fails is logged and the command runs with the env last applied.
69
+ */
70
+ export declare function attachSandboxEnvRefresh(sandbox: RefreshableSandbox, options: {
71
+ initial: Pick<SandboxEnv, 'runtime' | 'revision'>;
72
+ revision: () => Promise<string>;
73
+ load: () => Promise<Pick<SandboxEnv, 'runtime' | 'revision'>>;
74
+ onError?: (error: unknown) => void;
75
+ }): void;
76
+ export {};
77
+ //# sourceMappingURL=sandbox-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-env.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,O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CAAC,MAAM,EAAE,MAAM,CAAC,CAEzE;AAED,MAAM,WAAW,kBAAkB;IACjC,aAAa,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,UAAU,KAAK,IAAI,CAAC;CAC5D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE;IACP,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,UAAU,CAAC,CAAC;IAClD,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC;IAC9D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,GACA,IAAI,CAmDN"}
@@ -0,0 +1,130 @@
1
+ // src/sandbox/sandbox-env.ts
2
+ /**
3
+ * The single place a sandbox's environment is resolved. v1 reads only the
4
+ * Factory-wide variables; personal and session layers merge in here later,
5
+ * with session over personal over Factory, so callers never change.
6
+ */
7
+ async function resolveSandboxEnv(store, scope) {
8
+ const { runtime, build, revision, buildRevision } = await store.resolve(scope.orgId, scope.projectId);
9
+ return {
10
+ runtime,
11
+ build,
12
+ revision,
13
+ buildRevision
14
+ };
15
+ }
16
+ function warnReadFailed(message, error) {
17
+ console.warn(`[Mastra Factory] ${message}`, { error: error instanceof Error ? error.message : String(error) });
18
+ }
19
+ /**
20
+ * `resolveSandboxEnv` for session boot and setup: a failed read (a storage
21
+ * blip, a value encrypted with a removed key) is logged and yields no Factory
22
+ * variables, so it can't stop a session from starting. Its empty revision
23
+ * makes the first command's refresh try again.
24
+ */
25
+ async function resolveSandboxEnvOrEmpty(store, scope) {
26
+ try {
27
+ return await resolveSandboxEnv(store, scope);
28
+ } catch (error) {
29
+ warnReadFailed("Could not read sandbox environment variables; starting without them", error);
30
+ return {
31
+ runtime: {},
32
+ build: {},
33
+ revision: "",
34
+ buildRevision: ""
35
+ };
36
+ }
37
+ }
38
+ /**
39
+ * The template-build fields of a sandbox context. Omitted when the Factory has
40
+ * no Build variables, so the template identity matches one built without them.
41
+ * Session boot and environment builds share this, so both name the same template.
42
+ */
43
+ function sandboxBuildContext(env) {
44
+ if (!env || Object.keys(env.build).length === 0) return {};
45
+ return {
46
+ buildEnv: env.build,
47
+ buildEnvRevision: env.buildRevision
48
+ };
49
+ }
50
+ /**
51
+ * Replace every Build value that appears in provider or command output with
52
+ * `***`. Each value is also matched without its edge whitespace, since output
53
+ * often drops a pasted trailing space or newline. Longest first, so a value
54
+ * that contains another is masked whole.
55
+ */
56
+ function maskSandboxEnvValues(text, env) {
57
+ if (!env) return text;
58
+ const values = new Set(Object.values(env).flatMap((value) => [value, value.trim()]));
59
+ let masked = text;
60
+ for (const value of [...values].sort((a, b) => b.length - a.length)) if (value) masked = masked.replaceAll(value, "***");
61
+ return masked;
62
+ }
63
+ const appliedBySandbox = /* @__PURE__ */ new WeakMap();
64
+ /**
65
+ * The Factory runtime values currently applied to a sandbox, so output from a
66
+ * command that ran in it (a failed teardown) can be masked without a storage read.
67
+ */
68
+ function appliedSandboxEnv(sandbox) {
69
+ return appliedBySandbox.get(sandbox)?.() ?? {};
70
+ }
71
+ /**
72
+ * Apply the Factory's runtime variables to a sandbox's env overlay and keep
73
+ * them current: after every `ensureRunning()` (which every command path awaits
74
+ * before reading the overlay) the Factory revision is checked, and on a change
75
+ * the variables are reloaded and re-applied, so an add, edit or delete reaches
76
+ * the next command. Processes already running keep the env they started with.
77
+ *
78
+ * A key the sandbox already had (its host `env`) is remembered before Factory
79
+ * first writes it and restored when the Factory variable goes away. A refresh
80
+ * that fails is logged and the command runs with the env last applied.
81
+ */
82
+ function attachSandboxEnvRefresh(sandbox, options) {
83
+ const setEnv = sandbox.setEnv?.bind(sandbox);
84
+ if (!setEnv) return;
85
+ const shadowed = /* @__PURE__ */ new Map();
86
+ let applied = {};
87
+ let appliedRevision = options.initial.revision;
88
+ const apply = (next) => {
89
+ setEnv((env) => {
90
+ const out = { ...env };
91
+ for (const key of Object.keys(applied)) {
92
+ if (Object.hasOwn(next, key)) continue;
93
+ const previous = shadowed.get(key);
94
+ shadowed.delete(key);
95
+ if (previous === void 0) delete out[key];
96
+ else out[key] = previous;
97
+ }
98
+ for (const [key, value] of Object.entries(next)) {
99
+ if (!Object.hasOwn(applied, key)) shadowed.set(key, env[key]);
100
+ out[key] = value;
101
+ }
102
+ return out;
103
+ });
104
+ applied = { ...next };
105
+ };
106
+ apply(options.initial.runtime);
107
+ appliedBySandbox.set(sandbox, () => applied);
108
+ const original = sandbox.ensureRunning?.bind(sandbox);
109
+ if (!original) return;
110
+ let inFlight;
111
+ const refresh = async () => {
112
+ if (await options.revision() === appliedRevision) return;
113
+ const next = await options.load();
114
+ apply(next.runtime);
115
+ appliedRevision = next.revision;
116
+ };
117
+ sandbox.ensureRunning = async () => {
118
+ await original();
119
+ inFlight ??= refresh().catch((error) => {
120
+ if (options.onError) options.onError(error);
121
+ else warnReadFailed("Could not refresh sandbox environment variables; using the last applied", error);
122
+ }).finally(() => {
123
+ inFlight = void 0;
124
+ });
125
+ await inFlight;
126
+ };
127
+ }
128
+ export { appliedSandboxEnv, attachSandboxEnvRefresh, maskSandboxEnvValues, resolveSandboxEnv, resolveSandboxEnvOrEmpty, sandboxBuildContext };
129
+
130
+ //# sourceMappingURL=sandbox-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-env.js","names":[],"sources":["../../src/sandbox/sandbox-env.ts"],"sourcesContent":["/**\n * Sandbox environment variables: what a session sandbox's commands and builds\n * get from the Factory's stored variables, and how a running sandbox picks up\n * edits on its next command.\n */\n\nimport type { FactorySandboxContext } from '@mastra/core/workspace';\nimport type { SandboxEnvStore } from '../storage/domains/sandbox-envs/base.js';\n\nexport interface SandboxEnv {\n /** Variables every command in the sandbox gets. */\n runtime: Record<string, string>;\n /** Variables template builds and Factory-run setup commands get; never runtime commands. */\n build: Record<string, string>;\n /** Read before the values: an edit landing in between makes the next check reload. */\n revision: string;\n buildRevision: string;\n}\n\n/**\n * The single place a sandbox's environment is resolved. v1 reads only the\n * Factory-wide variables; personal and session layers merge in here later,\n * with session over personal over Factory, so callers never change.\n */\nexport async function resolveSandboxEnv(\n store: Pick<SandboxEnvStore, 'resolve'>,\n scope: { orgId: string; projectId: string },\n): Promise<SandboxEnv> {\n const { runtime, build, revision, buildRevision } = await store.resolve(scope.orgId, scope.projectId);\n return { runtime, build, revision, buildRevision };\n}\n\nfunction warnReadFailed(message: string, error: unknown) {\n console.warn(`[Mastra Factory] ${message}`, {\n // Storage and decryption errors name no values.\n error: error instanceof Error ? error.message : String(error),\n });\n}\n\n/**\n * `resolveSandboxEnv` for session boot and setup: a failed read (a storage\n * blip, a value encrypted with a removed key) is logged and yields no Factory\n * variables, so it can't stop a session from starting. Its empty revision\n * makes the first command's refresh try again.\n */\nexport async function resolveSandboxEnvOrEmpty(\n store: Pick<SandboxEnvStore, 'resolve'>,\n scope: { orgId: string; projectId: string },\n): Promise<SandboxEnv> {\n try {\n return await resolveSandboxEnv(store, scope);\n } catch (error) {\n warnReadFailed('Could not read sandbox environment variables; starting without them', error);\n return { runtime: {}, build: {}, revision: '', buildRevision: '' };\n }\n}\n\n/**\n * The template-build fields of a sandbox context. Omitted when the Factory has\n * no Build variables, so the template identity matches one built without them.\n * Session boot and environment builds share this, so both name the same template.\n */\nexport function sandboxBuildContext(\n env: SandboxEnv | undefined,\n): Pick<FactorySandboxContext, 'buildEnv' | 'buildEnvRevision'> {\n if (!env || Object.keys(env.build).length === 0) return {};\n return { buildEnv: env.build, buildEnvRevision: env.buildRevision };\n}\n\n/**\n * Replace every Build value that appears in provider or command output with\n * `***`. Each value is also matched without its edge whitespace, since output\n * often drops a pasted trailing space or newline. Longest first, so a value\n * that contains another is masked whole.\n */\nexport function maskSandboxEnvValues(text: string, env: Record<string, string> | undefined): string {\n if (!env) return text;\n const values = new Set(Object.values(env).flatMap(value => [value, value.trim()]));\n let masked = text;\n for (const value of [...values].sort((a, b) => b.length - a.length)) {\n if (value) masked = masked.replaceAll(value, '***');\n }\n return masked;\n}\n\ntype EnvOverlay = Record<string, string | undefined>;\n\nconst appliedBySandbox = new WeakMap<object, () => Record<string, string>>();\n\n/**\n * The Factory runtime values currently applied to a sandbox, so output from a\n * command that ran in it (a failed teardown) can be masked without a storage read.\n */\nexport function appliedSandboxEnv(sandbox: object): Record<string, string> {\n return appliedBySandbox.get(sandbox)?.() ?? {};\n}\n\nexport interface RefreshableSandbox {\n ensureRunning?: () => Promise<void>;\n setEnv?: (update: (env: EnvOverlay) => EnvOverlay) => void;\n}\n\n/**\n * Apply the Factory's runtime variables to a sandbox's env overlay and keep\n * them current: after every `ensureRunning()` (which every command path awaits\n * before reading the overlay) the Factory revision is checked, and on a change\n * the variables are reloaded and re-applied, so an add, edit or delete reaches\n * the next command. Processes already running keep the env they started with.\n *\n * A key the sandbox already had (its host `env`) is remembered before Factory\n * first writes it and restored when the Factory variable goes away. A refresh\n * that fails is logged and the command runs with the env last applied.\n */\nexport function attachSandboxEnvRefresh(\n sandbox: RefreshableSandbox,\n options: {\n initial: Pick<SandboxEnv, 'runtime' | 'revision'>;\n revision: () => Promise<string>;\n load: () => Promise<Pick<SandboxEnv, 'runtime' | 'revision'>>;\n onError?: (error: unknown) => void;\n },\n): void {\n const setEnv = sandbox.setEnv?.bind(sandbox);\n if (!setEnv) return;\n // Values the overlay held under a key before Factory first wrote it.\n const shadowed = new Map<string, string | undefined>();\n let applied: Record<string, string> = {};\n let appliedRevision = options.initial.revision;\n\n const apply = (next: Record<string, string>) => {\n setEnv(env => {\n const out = { ...env };\n for (const key of Object.keys(applied)) {\n if (Object.hasOwn(next, key)) continue;\n const previous = shadowed.get(key);\n shadowed.delete(key);\n if (previous === undefined) delete out[key];\n else out[key] = previous;\n }\n for (const [key, value] of Object.entries(next)) {\n if (!Object.hasOwn(applied, key)) shadowed.set(key, env[key]);\n out[key] = value;\n }\n return out;\n });\n applied = { ...next };\n };\n apply(options.initial.runtime);\n appliedBySandbox.set(sandbox, () => applied);\n\n const original = sandbox.ensureRunning?.bind(sandbox);\n if (!original) return;\n let inFlight: Promise<void> | undefined;\n // Never calls ensureRunning itself, so a command inside `onStart` can't wait on its own start.\n const refresh = async () => {\n if ((await options.revision()) === appliedRevision) return;\n const next = await options.load();\n apply(next.runtime);\n appliedRevision = next.revision;\n };\n sandbox.ensureRunning = async () => {\n await original();\n inFlight ??= refresh()\n .catch(error => {\n if (options.onError) options.onError(error);\n else warnReadFailed('Could not refresh sandbox environment variables; using the last applied', error);\n })\n .finally(() => {\n inFlight = undefined;\n });\n await inFlight;\n };\n}\n"],"mappings":";;;;;;AAwBA,eAAsB,kBACpB,OACA,OACqB;CACrB,MAAM,EAAE,SAAS,OAAO,UAAU,kBAAkB,MAAM,MAAM,QAAQ,MAAM,OAAO,MAAM,SAAS;CACpG,OAAO;EAAE;EAAS;EAAO;EAAU;CAAc;AACnD;AAEA,SAAS,eAAe,SAAiB,OAAgB;CACvD,QAAQ,KAAK,oBAAoB,WAAW,EAE1C,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,EAC9D,CAAC;AACH;;;;;;;AAQA,eAAsB,yBACpB,OACA,OACqB;CACrB,IAAI;EACF,OAAO,MAAM,kBAAkB,OAAO,KAAK;CAC7C,SAAS,OAAO;EACd,eAAe,uEAAuE,KAAK;EAC3F,OAAO;GAAE,SAAS,CAAC;GAAG,OAAO,CAAC;GAAG,UAAU;GAAI,eAAe;EAAG;CACnE;AACF;;;;;;AAOA,SAAgB,oBACd,KAC8D;CAC9D,IAAI,CAAC,OAAO,OAAO,KAAK,IAAI,KAAK,CAAC,CAAC,WAAW,GAAG,OAAO,CAAC;CACzD,OAAO;EAAE,UAAU,IAAI;EAAO,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E,GAAG,KAAK;CACtB;CACA,MAAM,QAAQ,QAAQ,OAAO;CAC7B,iBAAiB,IAAI,eAAe,OAAO;CAE3C,MAAM,WAAW,QAAQ,eAAe,KAAK,OAAO;CACpD,IAAI,CAAC,UAAU;CACf,IAAI;CAEJ,MAAM,UAAU,YAAY;EAC1B,IAAK,MAAM,QAAQ,SAAS,MAAO,iBAAiB;EACpD,MAAM,OAAO,MAAM,QAAQ,KAAK;EAChC,MAAM,KAAK,OAAO;EAClB,kBAAkB,KAAK;CACzB;CACA,QAAQ,gBAAgB,YAAY;EAClC,MAAM,SAAS;EACf,aAAa,QAAQ,CAAC,CACnB,OAAM,UAAS;GACd,IAAI,QAAQ,SAAS,QAAQ,QAAQ,KAAK;QACrC,eAAe,2EAA2E,KAAK;EACtG,CAAC,CAAC,CACD,cAAc;GACb,WAAW,KAAA;EACb,CAAC;EACH,MAAM;CACR;AACF"}
@@ -3,7 +3,7 @@
3
3
  * WorkOS dashboard under Audit Logs → Events before the mirror accepts them.
4
4
  */
5
5
  export declare const AUDIT_ACTIONS: {
6
- readonly work_item: readonly ['created', 'updated', 'deleted', 'stage_moved', 'transition_rejected', 'comment_created', 'comment_edited', 'comment_deleted', 'comment_mentioned', 'labels_reconciled'];
6
+ readonly work_item: readonly ['created', 'updated', 'deleted', 'stage_moved', 'transition_rejected', 'labels_reconciled'];
7
7
  readonly run: readonly ['started', 'ended', 'approved', 'dismissed', 'retry', 'queued', 'rejected'];
8
8
  readonly git: readonly ['commit', 'push', 'pr_opened'];
9
9
  readonly agent: readonly ['commit', 'push', 'pr_opened', 'signaled'];
@@ -12,6 +12,7 @@ export declare const AUDIT_ACTIONS: {
12
12
  readonly board: readonly ['created', 'updated', 'deleted', 'reset'];
13
13
  readonly skill: readonly ['updated', 'reverted'];
14
14
  readonly intake_route: readonly ['created', 'updated', 'deleted', 'reordered'];
15
+ readonly sandbox_env: readonly ['set', 'updated', 'deleted'];
15
16
  };
16
17
  export type AuditNamespace = keyof typeof AUDIT_ACTIONS;
17
18
  export type AuditAction = {
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/audit/actions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,aAAa;aACxB,SAAS,YACP,SAAS,EACT,SAAS,EACT,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB;aAErB,GAAG,YAAG,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU;aAChF,GAAG,YAAG,QAAQ,EAAE,MAAM,EAAE,WAAW;aACnC,KAAK,YAAG,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU;aACjD,MAAM,YAAG,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB;aACnE,OAAO,YAAG,mBAAmB;aAC7B,KAAK,YAAG,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO;aAChD,KAAK,YAAG,SAAS,EAAE,UAAU;aAC7B,YAAY,YAAG,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW;CACnD,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,aAAa,CAAC;AAExD,MAAM,MAAM,WAAW,GAAG;KACvB,SAAS,IAAI,cAAc,GAAG,WAAW,SAAS,IAAI,CAAC,OAAO,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAAE;CACnG,CAAC,cAAc,CAAC,CAAC;AAElB,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,cAAc,CAEvE;AAED,wBAAgB,eAAe,IAAI,cAAc,EAAE,CAElD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,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c,EAAE,CAElD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAIxG;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,WAAW,CAGjE;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,EAAE,CAExF"}
@@ -10,10 +10,6 @@ const AUDIT_ACTIONS = {
10
10
  "deleted",
11
11
  "stage_moved",
12
12
  "transition_rejected",
13
- "comment_created",
14
- "comment_edited",
15
- "comment_deleted",
16
- "comment_mentioned",
17
13
  "labels_reconciled"
18
14
  ],
19
15
  run: [
@@ -54,6 +50,11 @@ const AUDIT_ACTIONS = {
54
50
  "updated",
55
51
  "deleted",
56
52
  "reordered"
53
+ ],
54
+ sandbox_env: [
55
+ "set",
56
+ "updated",
57
+ "deleted"
57
58
  ]
58
59
  };
59
60
  function isAuditNamespace(value) {
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","names":[],"sources":["../../../../src/storage/domains/audit/actions.ts"],"sourcesContent":["/**\n * Every action the trail can hold, by namespace. Register new ones in the\n * WorkOS dashboard under Audit Logs → Events before the mirror accepts them.\n */\nexport const AUDIT_ACTIONS = {\n work_item: [\n 'created',\n 'updated',\n 'deleted',\n 'stage_moved',\n 'transition_rejected',\n 'comment_created',\n 'comment_edited',\n 'comment_deleted',\n 'comment_mentioned',\n 'labels_reconciled',\n ],\n run: ['started', 'ended', 'approved', 'dismissed', 'retry', 'queued', 'rejected'],\n git: ['commit', 'push', 'pr_opened'],\n agent: ['commit', 'push', 'pr_opened', 'signaled'],\n intake: ['config_updated', 'binding_updated', 'label_route_updated'],\n session: ['owner_transferred'],\n board: ['created', 'updated', 'deleted', 'reset'],\n skill: ['updated', 'reverted'],\n intake_route: ['created', 'updated', 'deleted', 'reordered'],\n} as const;\n\nexport type AuditNamespace = keyof typeof AUDIT_ACTIONS;\n\nexport type AuditAction = {\n [Namespace in AuditNamespace]: `factory.${Namespace}.${(typeof AUDIT_ACTIONS)[Namespace][number]}`;\n}[AuditNamespace];\n\nexport function isAuditNamespace(value: string): value is AuditNamespace {\n return Object.hasOwn(AUDIT_ACTIONS, value);\n}\n\nexport function auditNamespaces(): AuditNamespace[] {\n return Object.keys(AUDIT_ACTIONS).filter(isAuditNamespace);\n}\n\nexport function parseAuditAction(action: string): { namespace: AuditNamespace; leaf: string } | undefined {\n const [prefix, namespace, leaf, ...rest] = action.split('.');\n if (prefix !== 'factory' || namespace === undefined || leaf === undefined || rest.length > 0) return undefined;\n return isAuditNamespace(namespace) ? { namespace, leaf } : undefined;\n}\n\nexport function isAuditAction(value: string): value is AuditAction {\n const parsed = parseAuditAction(value);\n return parsed !== undefined && AUDIT_ACTIONS[parsed.namespace].some(leaf => leaf === parsed.leaf);\n}\n\nexport function auditActionsInNamespaces(namespaces: readonly AuditNamespace[]): string[] {\n return namespaces.flatMap(namespace => AUDIT_ACTIONS[namespace].map(leaf => `factory.${namespace}.${leaf}`));\n}\n"],"mappings":";;;;;AAIA,MAAa,gBAAgB;CAC3B,WAAW;EACT;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CACA,KAAK;EAAC;EAAW;EAAS;EAAY;EAAa;EAAS;EAAU;CAAU;CAChF,KAAK;EAAC;EAAU;EAAQ;CAAW;CACnC,OAAO;EAAC;EAAU;EAAQ;EAAa;CAAU;CACjD,QAAQ;EAAC;EAAkB;EAAmB;CAAqB;CACnE,SAAS,CAAC,mBAAmB;CAC7B,OAAO;EAAC;EAAW;EAAW;EAAW;CAAO;CAChD,OAAO,CAAC,WAAW,UAAU;CAC7B,cAAc;EAAC;EAAW;EAAW;EAAW;CAAW;AAC7D;AAQA,SAAgB,iBAAiB,OAAwC;CACvE,OAAO,OAAO,OAAO,eAAe,KAAK;AAC3C;AAEA,SAAgB,kBAAoC;CAClD,OAAO,OAAO,KAAK,aAAa,CAAC,CAAC,OAAO,gBAAgB;AAC3D;AAEA,SAAgB,iBAAiB,QAAyE;CACxG,MAAM,CAAC,QAAQ,WAAW,MAAM,GAAG,QAAQ,OAAO,MAAM,GAAG;CAC3D,IAAI,WAAW,aAAa,cAAc,KAAA,KAAa,SAAS,KAAA,KAAa,KAAK,SAAS,GAAG,OAAO,KAAA;CACrG,OAAO,iBAAiB,SAAS,IAAI;EAAE;EAAW;CAAK,IAAI,KAAA;AAC7D;AAEA,SAAgB,cAAc,OAAqC;CACjE,MAAM,SAAS,iBAAiB,KAAK;CACrC,OAAO,WAAW,KAAA,KAAa,cAAc,OAAO,UAAU,CAAC,MAAK,SAAQ,SAAS,OAAO,IAAI;AAClG;AAEA,SAAgB,yBAAyB,YAAiD;CACxF,OAAO,WAAW,SAAQ,cAAa,cAAc,UAAU,CAAC,KAAI,SAAQ,WAAW,UAAU,GAAG,MAAM,CAAC;AAC7G"}
1
+ {"version":3,"file":"actions.js","names":[],"sources":["../../../../src/storage/domains/audit/actions.ts"],"sourcesContent":["/**\n * Every action the trail can hold, by namespace. Register new ones in the\n * WorkOS dashboard under Audit Logs → Events before the mirror accepts them.\n */\nexport const AUDIT_ACTIONS = {\n work_item: ['created', 'updated', 'deleted', 'stage_moved', 'transition_rejected', 'labels_reconciled'],\n run: ['started', 'ended', 'approved', 'dismissed', 'retry', 'queued', 'rejected'],\n git: ['commit', 'push', 'pr_opened'],\n agent: ['commit', 'push', 'pr_opened', 'signaled'],\n intake: ['config_updated', 'binding_updated', 'label_route_updated'],\n session: ['owner_transferred'],\n board: ['created', 'updated', 'deleted', 'reset'],\n skill: ['updated', 'reverted'],\n intake_route: ['created', 'updated', 'deleted', 'reordered'],\n sandbox_env: ['set', 'updated', 'deleted'],\n} as const;\n\nexport type AuditNamespace = keyof typeof AUDIT_ACTIONS;\n\nexport type AuditAction = {\n [Namespace in AuditNamespace]: `factory.${Namespace}.${(typeof AUDIT_ACTIONS)[Namespace][number]}`;\n}[AuditNamespace];\n\nexport function isAuditNamespace(value: string): value is AuditNamespace {\n return Object.hasOwn(AUDIT_ACTIONS, value);\n}\n\nexport function auditNamespaces(): AuditNamespace[] {\n return Object.keys(AUDIT_ACTIONS).filter(isAuditNamespace);\n}\n\nexport function parseAuditAction(action: string): { namespace: AuditNamespace; leaf: string } | undefined {\n const [prefix, namespace, leaf, ...rest] = action.split('.');\n if (prefix !== 'factory' || namespace === undefined || leaf === undefined || rest.length > 0) return undefined;\n return isAuditNamespace(namespace) ? { namespace, leaf } : undefined;\n}\n\nexport function isAuditAction(value: string): value is AuditAction {\n const parsed = parseAuditAction(value);\n return parsed !== undefined && AUDIT_ACTIONS[parsed.namespace].some(leaf => leaf === parsed.leaf);\n}\n\nexport function auditActionsInNamespaces(namespaces: readonly AuditNamespace[]): string[] {\n return namespaces.flatMap(namespace => AUDIT_ACTIONS[namespace].map(leaf => `factory.${namespace}.${leaf}`));\n}\n"],"mappings":";;;;;AAIA,MAAa,gBAAgB;CAC3B,WAAW;EAAC;EAAW;EAAW;EAAW;EAAe;EAAuB;CAAmB;CACtG,KAAK;EAAC;EAAW;EAAS;EAAY;EAAa;EAAS;EAAU;CAAU;CAChF,KAAK;EAAC;EAAU;EAAQ;CAAW;CACnC,OAAO;EAAC;EAAU;EAAQ;EAAa;CAAU;CACjD,QAAQ;EAAC;EAAkB;EAAmB;CAAqB;CACnE,SAAS,CAAC,mBAAmB;CAC7B,OAAO;EAAC;EAAW;EAAW;EAAW;CAAO;CAChD,OAAO,CAAC,WAAW,UAAU;CAC7B,cAAc;EAAC;EAAW;EAAW;EAAW;CAAW;CAC3D,aAAa;EAAC;EAAO;EAAW;CAAS;AAC3C;AAQA,SAAgB,iBAAiB,OAAwC;CACvE,OAAO,OAAO,OAAO,eAAe,KAAK;AAC3C;AAEA,SAAgB,kBAAoC;CAClD,OAAO,OAAO,KAAK,aAAa,CAAC,CAAC,OAAO,gBAAgB;AAC3D;AAEA,SAAgB,iBAAiB,QAAyE;CACxG,MAAM,CAAC,QAAQ,WAAW,MAAM,GAAG,QAAQ,OAAO,MAAM,GAAG;CAC3D,IAAI,WAAW,aAAa,cAAc,KAAA,KAAa,SAAS,KAAA,KAAa,KAAK,SAAS,GAAG,OAAO,KAAA;CACrG,OAAO,iBAAiB,SAAS,IAAI;EAAE;EAAW;CAAK,IAAI,KAAA;AAC7D;AAEA,SAAgB,cAAc,OAAqC;CACjE,MAAM,SAAS,iBAAiB,KAAK;CACrC,OAAO,WAAW,KAAA,KAAa,cAAc,OAAO,UAAU,CAAC,MAAK,SAAQ,SAAS,OAAO,IAAI;AAClG;AAEA,SAAgB,yBAAyB,YAAiD;CACxF,OAAO,WAAW,SAAQ,cAAa,cAAc,UAAU,CAAC,KAAI,SAAQ,WAAW,UAAU,GAAG,MAAM,CAAC;AAC7G"}
@@ -197,8 +197,22 @@ export declare class StoredBoardsStorage extends FactoryStorageDomain {
197
197
  * project has had before is skipped even if its board was deleted since, and a stored board is
198
198
  * never rewritten. A project stored before the list was kept counts the boards it has as stored.
199
199
  * Reads one row when every key was stored before. Returns the keys it inserted.
200
+ *
201
+ * A key in `onlyIntoEmpty` is inserted only into a project that has no boards at all: one that
202
+ * already has any board, such as one an app stored under that key, is left as it is. The key
203
+ * is still recorded as stored, so it never goes in later, even after the project's boards are
204
+ * deleted: that project chose its boards, and Work is never added beside or after them. The
205
+ * `intoEmpty` boards (an app's, for every project) go first into a project with no boards, so
206
+ * Factory's own under the same key, or in `onlyIntoEmpty`, then stay out. `actor` is recorded
207
+ * as the inserted boards' creator.
200
208
  */
201
- seedBoards(scope: StoredBoardScope, boards: readonly StoredBoardInput[]): Promise<string[]>;
209
+ seedBoards(scope: StoredBoardScope, boards: readonly StoredBoardInput[], options?: {
210
+ actor?: string;
211
+ onlyIntoEmpty?: readonly string[];
212
+ intoEmpty?: readonly StoredBoardInput[];
213
+ }): Promise<string[]>;
214
+ /** The keys of the boards Factory stored in the project; null before it kept the list. */
215
+ seededBoardKeys(scope: StoredBoardScope): Promise<string[] | null>;
202
216
  /**
203
217
  * Inserts a board into the project unless one is stored under its key, and records the key as
204
218
  * stored, so seeding never adds it again. Unlike seeding, it inserts a key the project deleted.
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/base.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AASrE,sCAAsC;AACtC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;AAEjE,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,IAAI,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAChD;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,SAAS,CAAC;CAC7B;AAED,oEAAoE;AACpE,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,I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CAuBlC;IAED,gFAAgF;IAC1E,iBAAiB,CACrB,KAAK,EAAE,gBAAgB,EACvB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,OAAO,CAAC,sBAAsB,CAAC,EACtC,OAAO,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GACnD,OAAO,CAAC,uBAAuB,CAAC,CAmBlC;IAED,8DAA8D;IACxD,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAejH;IAED,iGAAiG;IAC3F,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAkBnH;CAoFF"}
@@ -175,15 +175,29 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
175
175
  * project has had before is skipped even if its board was deleted since, and a stored board is
176
176
  * never rewritten. A project stored before the list was kept counts the boards it has as stored.
177
177
  * Reads one row when every key was stored before. Returns the keys it inserted.
178
+ *
179
+ * A key in `onlyIntoEmpty` is inserted only into a project that has no boards at all: one that
180
+ * already has any board, such as one an app stored under that key, is left as it is. The key
181
+ * is still recorded as stored, so it never goes in later, even after the project's boards are
182
+ * deleted: that project chose its boards, and Work is never added beside or after them. The
183
+ * `intoEmpty` boards (an app's, for every project) go first into a project with no boards, so
184
+ * Factory's own under the same key, or in `onlyIntoEmpty`, then stay out. `actor` is recorded
185
+ * as the inserted boards' creator.
178
186
  */
179
- async seedBoards(scope, boards) {
187
+ async seedBoards(scope, boards, options = {}) {
180
188
  const marker = await this.ops.findOne(VERSIONS, scopeWhere(scope));
181
189
  if (marker?.seeded_boards && boards.every((board) => marker.seeded_boards.includes(board.key))) return [];
182
190
  return this.#insertOnce(scope, boards, {
183
- actor: DEFAULT_INTAKE_ROUTE_ACTOR,
184
- skipSeeded: true
191
+ actor: options.actor ?? "factory",
192
+ skipSeeded: true,
193
+ onlyIntoEmpty: options.onlyIntoEmpty ?? [],
194
+ intoEmpty: options.intoEmpty ?? []
185
195
  });
186
196
  }
197
+ /** The keys of the boards Factory stored in the project; null before it kept the list. */
198
+ async seededBoardKeys(scope) {
199
+ return (await this.ops.findOne(VERSIONS, scopeWhere(scope)))?.seeded_boards ?? null;
200
+ }
187
201
  /**
188
202
  * Inserts a board into the project unless one is stored under its key, and records the key as
189
203
  * stored, so seeding never adds it again. Unlike seeding, it inserts a key the project deleted.
@@ -202,10 +216,12 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
202
216
  const rows = await ops.findMany(BOARDS, scopeWhere(scope));
203
217
  const present = new Set(rows.map((row) => row.board_key));
204
218
  const seeded = new Set(marker.seeded_boards ?? present);
219
+ const candidates = [...rows.length === 0 ? options.intoEmpty ?? [] : [], ...boards];
205
220
  let position = nextPosition(rows);
206
221
  const inserted = [];
207
- for (const board of boards) {
222
+ for (const board of candidates) {
208
223
  if (present.has(board.key) || options.skipSeeded && seeded.has(board.key)) continue;
224
+ if (present.size > 0 && options.onlyIntoEmpty?.includes(board.key)) continue;
209
225
  await insertBoard(ops, scope, board, {
210
226
  position: position++,
211
227
  actor: options.actor
@@ -213,7 +229,7 @@ var StoredBoardsStorage = class extends FactoryStorageDomain {
213
229
  present.add(board.key);
214
230
  inserted.push(board.key);
215
231
  }
216
- const next = [.../* @__PURE__ */ new Set([...seeded, ...boards.map((board) => board.key)])];
232
+ const next = [.../* @__PURE__ */ new Set([...seeded, ...candidates.map((board) => board.key)])];
217
233
  const unchanged = marker.seeded_boards !== null && next.length === marker.seeded_boards.length;
218
234
  if (inserted.length === 0 && unchanged) return inserted;
219
235
  if (await ops.updateMany(VERSIONS, {