@mastra/factory 0.0.0 → 0.1.0-alpha.3

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 (287) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE.md +30 -0
  3. package/dist/auth.d.ts +181 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +370 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/capabilities/connection.d.ts +9 -0
  8. package/dist/capabilities/connection.d.ts.map +1 -0
  9. package/dist/capabilities/connection.js +1 -0
  10. package/dist/capabilities/connection.js.map +1 -0
  11. package/dist/capabilities/intake.d.ts +93 -0
  12. package/dist/capabilities/intake.d.ts.map +1 -0
  13. package/dist/capabilities/intake.js +1 -0
  14. package/dist/capabilities/intake.js.map +1 -0
  15. package/dist/capabilities/version-control.d.ts +239 -0
  16. package/dist/capabilities/version-control.d.ts.map +1 -0
  17. package/dist/capabilities/version-control.js +1 -0
  18. package/dist/capabilities/version-control.js.map +1 -0
  19. package/dist/factory.d.ts +145 -0
  20. package/dist/factory.d.ts.map +1 -0
  21. package/dist/factory.js +38245 -0
  22. package/dist/factory.js.map +1 -0
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +38245 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/integrations/base.d.ts +197 -0
  28. package/dist/integrations/base.d.ts.map +1 -0
  29. package/dist/integrations/base.js +1 -0
  30. package/dist/integrations/base.js.map +1 -0
  31. package/dist/integrations/github/config.d.ts +60 -0
  32. package/dist/integrations/github/config.d.ts.map +1 -0
  33. package/dist/integrations/github/config.js +28 -0
  34. package/dist/integrations/github/config.js.map +1 -0
  35. package/dist/integrations/github/factory-session.d.ts +12 -0
  36. package/dist/integrations/github/factory-session.d.ts.map +1 -0
  37. package/dist/integrations/github/factory-session.js +41 -0
  38. package/dist/integrations/github/factory-session.js.map +1 -0
  39. package/dist/integrations/github/integration.d.ts +191 -0
  40. package/dist/integrations/github/integration.d.ts.map +1 -0
  41. package/dist/integrations/github/integration.js +3001 -0
  42. package/dist/integrations/github/integration.js.map +1 -0
  43. package/dist/integrations/github/issue-triage.d.ts +27 -0
  44. package/dist/integrations/github/issue-triage.d.ts.map +1 -0
  45. package/dist/integrations/github/issue-triage.js +82 -0
  46. package/dist/integrations/github/issue-triage.js.map +1 -0
  47. package/dist/integrations/github/project-lock.d.ts +78 -0
  48. package/dist/integrations/github/project-lock.d.ts.map +1 -0
  49. package/dist/integrations/github/project-lock.js +70 -0
  50. package/dist/integrations/github/project-lock.js.map +1 -0
  51. package/dist/integrations/github/provenance.d.ts +27 -0
  52. package/dist/integrations/github/provenance.d.ts.map +1 -0
  53. package/dist/integrations/github/provenance.js +104 -0
  54. package/dist/integrations/github/provenance.js.map +1 -0
  55. package/dist/integrations/github/routes.d.ts +72 -0
  56. package/dist/integrations/github/routes.d.ts.map +1 -0
  57. package/dist/integrations/github/routes.js +1834 -0
  58. package/dist/integrations/github/routes.js.map +1 -0
  59. package/dist/integrations/github/sandbox.d.ts +268 -0
  60. package/dist/integrations/github/sandbox.d.ts.map +1 -0
  61. package/dist/integrations/github/sandbox.js +381 -0
  62. package/dist/integrations/github/sandbox.js.map +1 -0
  63. package/dist/integrations/github/session-subscriptions.d.ts +23 -0
  64. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -0
  65. package/dist/integrations/github/session-subscriptions.js +190 -0
  66. package/dist/integrations/github/session-subscriptions.js.map +1 -0
  67. package/dist/integrations/github/subscriptions.d.ts +54 -0
  68. package/dist/integrations/github/subscriptions.d.ts.map +1 -0
  69. package/dist/integrations/github/subscriptions.js +70 -0
  70. package/dist/integrations/github/subscriptions.js.map +1 -0
  71. package/dist/integrations/github/webhook.d.ts +87 -0
  72. package/dist/integrations/github/webhook.d.ts.map +1 -0
  73. package/dist/integrations/github/webhook.js +381 -0
  74. package/dist/integrations/github/webhook.js.map +1 -0
  75. package/dist/integrations/linear/agent-tools.d.ts +34 -0
  76. package/dist/integrations/linear/agent-tools.d.ts.map +1 -0
  77. package/dist/integrations/linear/agent-tools.js +108 -0
  78. package/dist/integrations/linear/agent-tools.js.map +1 -0
  79. package/dist/integrations/linear/integration.d.ts +233 -0
  80. package/dist/integrations/linear/integration.d.ts.map +1 -0
  81. package/dist/integrations/linear/integration.js +962 -0
  82. package/dist/integrations/linear/integration.js.map +1 -0
  83. package/dist/integrations/linear/routes.d.ts +61 -0
  84. package/dist/integrations/linear/routes.d.ts.map +1 -0
  85. package/dist/integrations/linear/routes.js +242 -0
  86. package/dist/integrations/linear/routes.js.map +1 -0
  87. package/dist/integrations/linear/storage.d.ts +65 -0
  88. package/dist/integrations/linear/storage.d.ts.map +1 -0
  89. package/dist/integrations/linear/storage.js +1 -0
  90. package/dist/integrations/linear/storage.js.map +1 -0
  91. package/dist/integrations/platform/api-client.d.ts +24 -0
  92. package/dist/integrations/platform/api-client.d.ts.map +1 -0
  93. package/dist/integrations/platform/api-client.js +153 -0
  94. package/dist/integrations/platform/api-client.js.map +1 -0
  95. package/dist/integrations/platform/github/event-worker.d.ts +44 -0
  96. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -0
  97. package/dist/integrations/platform/github/event-worker.js +585 -0
  98. package/dist/integrations/platform/github/event-worker.js.map +1 -0
  99. package/dist/integrations/platform/github/integration.d.ts +36 -0
  100. package/dist/integrations/platform/github/integration.d.ts.map +1 -0
  101. package/dist/integrations/platform/github/integration.js +3253 -0
  102. package/dist/integrations/platform/github/integration.js.map +1 -0
  103. package/dist/integrations/platform/linear/integration.d.ts +46 -0
  104. package/dist/integrations/platform/linear/integration.d.ts.map +1 -0
  105. package/dist/integrations/platform/linear/integration.js +891 -0
  106. package/dist/integrations/platform/linear/integration.js.map +1 -0
  107. package/dist/integrations/workos/integration.d.ts +39 -0
  108. package/dist/integrations/workos/integration.d.ts.map +1 -0
  109. package/dist/integrations/workos/integration.js +96 -0
  110. package/dist/integrations/workos/integration.js.map +1 -0
  111. package/dist/routes/config.d.ts +220 -0
  112. package/dist/routes/config.d.ts.map +1 -0
  113. package/dist/routes/config.js +770 -0
  114. package/dist/routes/config.js.map +1 -0
  115. package/dist/routes/fs.d.ts +105 -0
  116. package/dist/routes/fs.d.ts.map +1 -0
  117. package/dist/routes/fs.js +294 -0
  118. package/dist/routes/fs.js.map +1 -0
  119. package/dist/routes/intake.d.ts +23 -0
  120. package/dist/routes/intake.d.ts.map +1 -0
  121. package/dist/routes/intake.js +179 -0
  122. package/dist/routes/intake.js.map +1 -0
  123. package/dist/routes/oauth.d.ts +43 -0
  124. package/dist/routes/oauth.d.ts.map +1 -0
  125. package/dist/routes/oauth.js +25058 -0
  126. package/dist/routes/oauth.js.map +1 -0
  127. package/dist/routes/projects.d.ts +19 -0
  128. package/dist/routes/projects.d.ts.map +1 -0
  129. package/dist/routes/projects.js +395 -0
  130. package/dist/routes/projects.js.map +1 -0
  131. package/dist/routes/provider-credentials.d.ts +81 -0
  132. package/dist/routes/provider-credentials.d.ts.map +1 -0
  133. package/dist/routes/provider-credentials.js +68 -0
  134. package/dist/routes/provider-credentials.js.map +1 -0
  135. package/dist/routes/route.d.ts +48 -0
  136. package/dist/routes/route.d.ts.map +1 -0
  137. package/dist/routes/route.js +11 -0
  138. package/dist/routes/route.js.map +1 -0
  139. package/dist/routes/skills.d.ts +30 -0
  140. package/dist/routes/skills.d.ts.map +1 -0
  141. package/dist/routes/skills.js +181 -0
  142. package/dist/routes/skills.js.map +1 -0
  143. package/dist/routes/surface.d.ts +83 -0
  144. package/dist/routes/surface.d.ts.map +1 -0
  145. package/dist/routes/surface.js +28519 -0
  146. package/dist/routes/surface.js.map +1 -0
  147. package/dist/routes/tenant-credentials.d.ts +74 -0
  148. package/dist/routes/tenant-credentials.d.ts.map +1 -0
  149. package/dist/routes/tenant-credentials.js +181 -0
  150. package/dist/routes/tenant-credentials.js.map +1 -0
  151. package/dist/routes/work-items.d.ts +40 -0
  152. package/dist/routes/work-items.d.ts.map +1 -0
  153. package/dist/routes/work-items.js +902 -0
  154. package/dist/routes/work-items.js.map +1 -0
  155. package/dist/rules/binding-context.d.ts +5 -0
  156. package/dist/rules/binding-context.d.ts.map +1 -0
  157. package/dist/rules/binding-context.js +40 -0
  158. package/dist/rules/binding-context.js.map +1 -0
  159. package/dist/rules/defaults.d.ts +9 -0
  160. package/dist/rules/defaults.d.ts.map +1 -0
  161. package/dist/rules/defaults.js +334 -0
  162. package/dist/rules/defaults.js.map +1 -0
  163. package/dist/rules/dispatcher.d.ts +40 -0
  164. package/dist/rules/dispatcher.d.ts.map +1 -0
  165. package/dist/rules/dispatcher.js +695 -0
  166. package/dist/rules/dispatcher.js.map +1 -0
  167. package/dist/rules/github-service.d.ts +29 -0
  168. package/dist/rules/github-service.d.ts.map +1 -0
  169. package/dist/rules/github-service.js +474 -0
  170. package/dist/rules/github-service.js.map +1 -0
  171. package/dist/rules/index.d.ts +7 -0
  172. package/dist/rules/index.d.ts.map +1 -0
  173. package/dist/rules/index.js +583 -0
  174. package/dist/rules/index.js.map +1 -0
  175. package/dist/rules/linear-service.d.ts +27 -0
  176. package/dist/rules/linear-service.d.ts.map +1 -0
  177. package/dist/rules/linear-service.js +343 -0
  178. package/dist/rules/linear-service.js.map +1 -0
  179. package/dist/rules/processor.d.ts +54 -0
  180. package/dist/rules/processor.d.ts.map +1 -0
  181. package/dist/rules/processor.js +629 -0
  182. package/dist/rules/processor.js.map +1 -0
  183. package/dist/rules/resolve.d.ts +17 -0
  184. package/dist/rules/resolve.d.ts.map +1 -0
  185. package/dist/rules/resolve.js +27 -0
  186. package/dist/rules/resolve.js.map +1 -0
  187. package/dist/rules/start-coordinator.d.ts +58 -0
  188. package/dist/rules/start-coordinator.d.ts.map +1 -0
  189. package/dist/rules/start-coordinator.js +136 -0
  190. package/dist/rules/start-coordinator.js.map +1 -0
  191. package/dist/rules/tools.d.ts +10 -0
  192. package/dist/rules/tools.d.ts.map +1 -0
  193. package/dist/rules/tools.js +93 -0
  194. package/dist/rules/tools.js.map +1 -0
  195. package/dist/rules/transition-service.d.ts +32 -0
  196. package/dist/rules/transition-service.d.ts.map +1 -0
  197. package/dist/rules/transition-service.js +474 -0
  198. package/dist/rules/transition-service.js.map +1 -0
  199. package/dist/rules/types.d.ts +225 -0
  200. package/dist/rules/types.d.ts.map +1 -0
  201. package/dist/rules/types.js +33 -0
  202. package/dist/rules/types.js.map +1 -0
  203. package/dist/rules/validation.d.ts +11 -0
  204. package/dist/rules/validation.d.ts.map +1 -0
  205. package/dist/rules/validation.js +310 -0
  206. package/dist/rules/validation.js.map +1 -0
  207. package/dist/sandbox/fleet.d.ts +208 -0
  208. package/dist/sandbox/fleet.d.ts.map +1 -0
  209. package/dist/sandbox/fleet.js +259 -0
  210. package/dist/sandbox/fleet.js.map +1 -0
  211. package/dist/sandbox/reattach.d.ts +3 -0
  212. package/dist/sandbox/reattach.d.ts.map +1 -0
  213. package/dist/sandbox/reattach.js +9 -0
  214. package/dist/sandbox/reattach.js.map +1 -0
  215. package/dist/server-error.d.ts +12 -0
  216. package/dist/server-error.d.ts.map +1 -0
  217. package/dist/server-error.js +20 -0
  218. package/dist/server-error.js.map +1 -0
  219. package/dist/skills/service.d.ts +48 -0
  220. package/dist/skills/service.d.ts.map +1 -0
  221. package/dist/skills/service.js +45 -0
  222. package/dist/skills/service.js.map +1 -0
  223. package/dist/spa-static.d.ts +34 -0
  224. package/dist/spa-static.d.ts.map +1 -0
  225. package/dist/spa-static.js +73 -0
  226. package/dist/spa-static.js.map +1 -0
  227. package/dist/state-signing.d.ts +48 -0
  228. package/dist/state-signing.d.ts.map +1 -0
  229. package/dist/state-signing.js +48 -0
  230. package/dist/state-signing.js.map +1 -0
  231. package/dist/storage/domains/audit/agent-audit.d.ts +27 -0
  232. package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -0
  233. package/dist/storage/domains/audit/agent-audit.js +65 -0
  234. package/dist/storage/domains/audit/agent-audit.js.map +1 -0
  235. package/dist/storage/domains/audit/base.d.ts +140 -0
  236. package/dist/storage/domains/audit/base.d.ts.map +1 -0
  237. package/dist/storage/domains/audit/base.js +127 -0
  238. package/dist/storage/domains/audit/base.js.map +1 -0
  239. package/dist/storage/domains/audit/domain.d.ts +69 -0
  240. package/dist/storage/domains/audit/domain.d.ts.map +1 -0
  241. package/dist/storage/domains/audit/domain.js +165 -0
  242. package/dist/storage/domains/audit/domain.js.map +1 -0
  243. package/dist/storage/domains/credentials/base.d.ts +134 -0
  244. package/dist/storage/domains/credentials/base.d.ts.map +1 -0
  245. package/dist/storage/domains/credentials/base.js +257 -0
  246. package/dist/storage/domains/credentials/base.js.map +1 -0
  247. package/dist/storage/domains/intake/base.d.ts +38 -0
  248. package/dist/storage/domains/intake/base.d.ts.map +1 -0
  249. package/dist/storage/domains/intake/base.js +62 -0
  250. package/dist/storage/domains/intake/base.js.map +1 -0
  251. package/dist/storage/domains/integrations/base.d.ts +126 -0
  252. package/dist/storage/domains/integrations/base.d.ts.map +1 -0
  253. package/dist/storage/domains/integrations/base.js +252 -0
  254. package/dist/storage/domains/integrations/base.js.map +1 -0
  255. package/dist/storage/domains/model-packs/base.d.ts +49 -0
  256. package/dist/storage/domains/model-packs/base.d.ts.map +1 -0
  257. package/dist/storage/domains/model-packs/base.js +95 -0
  258. package/dist/storage/domains/model-packs/base.js.map +1 -0
  259. package/dist/storage/domains/projects/base.d.ts +55 -0
  260. package/dist/storage/domains/projects/base.d.ts.map +1 -0
  261. package/dist/storage/domains/projects/base.js +99 -0
  262. package/dist/storage/domains/projects/base.js.map +1 -0
  263. package/dist/storage/domains/queue-health/base.d.ts +52 -0
  264. package/dist/storage/domains/queue-health/base.d.ts.map +1 -0
  265. package/dist/storage/domains/queue-health/base.js +87 -0
  266. package/dist/storage/domains/queue-health/base.js.map +1 -0
  267. package/dist/storage/domains/source-control/base.d.ts +288 -0
  268. package/dist/storage/domains/source-control/base.d.ts.map +1 -0
  269. package/dist/storage/domains/source-control/base.js +722 -0
  270. package/dist/storage/domains/source-control/base.js.map +1 -0
  271. package/dist/storage/domains/source-control/inmemory.d.ts +158 -0
  272. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -0
  273. package/dist/storage/domains/source-control/inmemory.js +348 -0
  274. package/dist/storage/domains/source-control/inmemory.js.map +1 -0
  275. package/dist/storage/domains/work-items/base.d.ts +412 -0
  276. package/dist/storage/domains/work-items/base.d.ts.map +1 -0
  277. package/dist/storage/domains/work-items/base.js +1174 -0
  278. package/dist/storage/domains/work-items/base.js.map +1 -0
  279. package/dist/storage/domains/work-items/metrics.d.ts +101 -0
  280. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -0
  281. package/dist/storage/domains/work-items/metrics.js +203 -0
  282. package/dist/storage/domains/work-items/metrics.js.map +1 -0
  283. package/dist/workspace.d.ts +20 -0
  284. package/dist/workspace.d.ts.map +1 -0
  285. package/dist/workspace.js +364 -0
  286. package/dist/workspace.js.map +1 -0
  287. package/package.json +19 -19
@@ -0,0 +1,19 @@
1
+ import type { ApiRoute } from '@mastra/core/server';
2
+ import type { FactoryProjectsStorage } from '../storage/domains/projects/base.js';
3
+ import type { SourceControlStorage } from '../storage/domains/source-control/base.js';
4
+ import type { RouteDependencies } from './route.js';
5
+ import { Route } from './route.js';
6
+ export interface ProjectRoutesDeps extends RouteDependencies {
7
+ /** Factory projects domain backing the CRUD surface. */
8
+ projects: FactoryProjectsStorage;
9
+ /** Source-control domain the connection/repository routes fan out over. */
10
+ sourceControl: SourceControlStorage;
11
+ /** Integration ids allowed as source-control connection targets. */
12
+ versionControlIntegrationIds?: string[];
13
+ }
14
+ export declare class ProjectRoutes extends Route<ProjectRoutesDeps> {
15
+ #private;
16
+ constructor(deps: ProjectRoutesDeps);
17
+ routes(): ApiRoute[];
18
+ }
19
+ //# sourceMappingURL=projects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projects.d.ts","sourceRoot":"","sources":["../../src/routes/projects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIpD,OAAO,KAAK,EAEV,sBAAsB,EAEvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAEV,oBAAoB,EAGrB,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAuInC,MAAM,WAAW,iBAAkB,SAAQ,iBAAiB;IAC1D,wDAAwD;IACxD,QAAQ,EAAE,sBAAsB,CAAC;IACjC,2EAA2E;IAC3E,aAAa,EAAE,oBAAoB,CAAC;IACpC,oEAAoE;IACpE,4BAA4B,CAAC,EAAE,MAAM,EAAE,CAAC;CACzC;AAED,qBAAa,aAAc,SAAQ,KAAK,CAAC,iBAAiB,CAAC;;gBAG7C,IAAI,EAAE,iBAAiB;IA8DnC,MAAM,IAAI,QAAQ,EAAE;CA4NrB"}
@@ -0,0 +1,395 @@
1
+ // src/routes/projects.ts
2
+ import { registerApiRoute } from "@mastra/core/server";
3
+
4
+ // src/routes/route.ts
5
+ var Route = class {
6
+ deps;
7
+ constructor(deps) {
8
+ this.deps = deps;
9
+ }
10
+ };
11
+
12
+ // src/routes/projects.ts
13
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
14
+ var MAX_NAME_LENGTH = 200;
15
+ var MAX_DESCRIPTION_LENGTH = 2e3;
16
+ var MAX_SETUP_COMMAND_LENGTH = 2e3;
17
+ var MAX_BRANCH_LENGTH = 255;
18
+ var MAX_SANDBOX_PROVIDER_LENGTH = 100;
19
+ var MAX_SANDBOX_WORKDIR_LENGTH = 1e3;
20
+ var CONTROL_CHAR_RE = /[\0-\x08\x0b\x0c\x0e-\x1f\x7f]/;
21
+ function loose(context) {
22
+ return context;
23
+ }
24
+ async function readJson(context) {
25
+ try {
26
+ return await context.req.json();
27
+ } catch {
28
+ return void 0;
29
+ }
30
+ }
31
+ function parseCreateInput(value) {
32
+ if (!value || typeof value !== "object") return null;
33
+ const input = value;
34
+ if (typeof input.name !== "string") return null;
35
+ const name = input.name.trim();
36
+ if (!name || name.length > MAX_NAME_LENGTH) return null;
37
+ if (input.description !== void 0 && input.description !== null && typeof input.description !== "string")
38
+ return null;
39
+ const description = typeof input.description === "string" ? input.description.trim() || null : null;
40
+ if (description && description.length > MAX_DESCRIPTION_LENGTH) return null;
41
+ return { name, description };
42
+ }
43
+ function parseUpdateInput(value) {
44
+ if (!value || typeof value !== "object") return null;
45
+ const input = value;
46
+ const patch = {};
47
+ if (input.name !== void 0) {
48
+ if (typeof input.name !== "string") return null;
49
+ const name = input.name.trim();
50
+ if (!name || name.length > MAX_NAME_LENGTH) return null;
51
+ patch.name = name;
52
+ }
53
+ if (input.description !== void 0) {
54
+ if (input.description !== null && typeof input.description !== "string") return null;
55
+ const description = typeof input.description === "string" ? input.description.trim() || null : null;
56
+ if (description && description.length > MAX_DESCRIPTION_LENGTH) return null;
57
+ patch.description = description;
58
+ }
59
+ if (input.defaultModelId !== void 0) {
60
+ const defaultModelId = parseOptionalString(input.defaultModelId, { maxLength: MAX_NAME_LENGTH, nullable: true });
61
+ if (defaultModelId === false) return null;
62
+ patch.defaultModelId = defaultModelId ?? null;
63
+ }
64
+ return Object.keys(patch).length > 0 ? patch : null;
65
+ }
66
+ function parseConnectionInput(value) {
67
+ if (!value || typeof value !== "object") return null;
68
+ const input = value;
69
+ if (typeof input.integrationId !== "string" || !input.integrationId.trim()) return null;
70
+ if (typeof input.installationId !== "string" || !UUID_RE.test(input.installationId)) return null;
71
+ return { integrationId: input.integrationId.trim(), installationId: input.installationId };
72
+ }
73
+ function parseOptionalString(value, { maxLength, nullable = false }) {
74
+ if (value === void 0) return void 0;
75
+ if (value === null) return nullable ? null : false;
76
+ if (typeof value !== "string") return false;
77
+ const normalized = value.trim();
78
+ if (!normalized) return nullable ? null : false;
79
+ if (normalized.length > maxLength || CONTROL_CHAR_RE.test(normalized)) return false;
80
+ return normalized;
81
+ }
82
+ function parseRepositoryLinkInput(value) {
83
+ if (!value || typeof value !== "object") return null;
84
+ const input = value;
85
+ if (typeof input.repositoryId !== "string" || !UUID_RE.test(input.repositoryId)) return null;
86
+ const branch = parseOptionalString(input.branch, { maxLength: MAX_BRANCH_LENGTH, nullable: true });
87
+ const sandboxProvider = parseOptionalString(input.sandboxProvider, { maxLength: MAX_SANDBOX_PROVIDER_LENGTH });
88
+ const sandboxWorkdir = parseOptionalString(input.sandboxWorkdir, { maxLength: MAX_SANDBOX_WORKDIR_LENGTH });
89
+ const setupCommand = parseOptionalString(input.setupCommand, { maxLength: MAX_SETUP_COMMAND_LENGTH, nullable: true });
90
+ if (branch === false || typeof sandboxProvider !== "string" || typeof sandboxWorkdir !== "string" || setupCommand === false)
91
+ return null;
92
+ return {
93
+ repositoryId: input.repositoryId,
94
+ branch: branch ?? null,
95
+ sandboxProvider,
96
+ sandboxWorkdir,
97
+ setupCommand: setupCommand ?? null
98
+ };
99
+ }
100
+ function parseRepositoryUpdateInput(value) {
101
+ if (!value || typeof value !== "object") return null;
102
+ const input = value;
103
+ const patch = {};
104
+ const branch = parseOptionalString(input.branch, { maxLength: MAX_BRANCH_LENGTH, nullable: true });
105
+ const sandboxProvider = parseOptionalString(input.sandboxProvider, { maxLength: MAX_SANDBOX_PROVIDER_LENGTH });
106
+ const sandboxWorkdir = parseOptionalString(input.sandboxWorkdir, { maxLength: MAX_SANDBOX_WORKDIR_LENGTH });
107
+ const setupCommand = parseOptionalString(input.setupCommand, { maxLength: MAX_SETUP_COMMAND_LENGTH, nullable: true });
108
+ if (branch === false || sandboxProvider === false || sandboxProvider === null || sandboxWorkdir === false || sandboxWorkdir === null || setupCommand === false)
109
+ return null;
110
+ if (branch !== void 0) patch.branch = branch;
111
+ if (sandboxProvider !== void 0) patch.sandboxProvider = sandboxProvider;
112
+ if (sandboxWorkdir !== void 0) patch.sandboxWorkdir = sandboxWorkdir;
113
+ if (setupCommand !== void 0) patch.setupCommand = setupCommand;
114
+ return Object.keys(patch).length > 0 ? patch : null;
115
+ }
116
+ var ProjectRoutes = class extends Route {
117
+ #versionControlIntegrationIds;
118
+ constructor(deps) {
119
+ super(deps);
120
+ this.#versionControlIntegrationIds = new Set(deps.versionControlIntegrationIds ?? []);
121
+ }
122
+ async #projects() {
123
+ await this.deps.projects.ensureReady();
124
+ return this.deps.projects;
125
+ }
126
+ async #sourceControl() {
127
+ await this.deps.sourceControl.ensureReady();
128
+ return this.deps.sourceControl;
129
+ }
130
+ async #handles() {
131
+ const storage = await this.#sourceControl();
132
+ return [...this.#versionControlIntegrationIds].map((integrationId) => storage.forIntegration(integrationId));
133
+ }
134
+ async #project(orgId, id) {
135
+ return (await this.#projects()).get({ orgId, id });
136
+ }
137
+ async #findConnection({ orgId, projectId, id }) {
138
+ for (const handle of await this.#handles()) {
139
+ const connection = await handle.connections.get({ orgId, id });
140
+ if (connection?.factoryProjectId === projectId) return { handle, connection };
141
+ }
142
+ return null;
143
+ }
144
+ async #findProjectRepository({ orgId, projectId, id }) {
145
+ for (const handle of await this.#handles()) {
146
+ const projectRepository = await handle.projectRepositories.get({ orgId, id });
147
+ if (!projectRepository) continue;
148
+ const connection = await handle.connections.get({ orgId, id: projectRepository.connectionId });
149
+ if (connection?.factoryProjectId === projectId) return { handle, connection, projectRepository };
150
+ }
151
+ return null;
152
+ }
153
+ async #repositoryPayload(handle, orgId, projectRepository) {
154
+ const repository = await handle.repositories.get({ orgId, id: projectRepository.repositoryId });
155
+ return { ...projectRepository, repository };
156
+ }
157
+ async #resolveTenant(context) {
158
+ await this.deps.auth.ensureUser(context);
159
+ const tenant = this.deps.auth.tenant(context);
160
+ if (!tenant) return { response: context.json({ error: "unauthorized" }, 401) };
161
+ if (!tenant.orgId) {
162
+ return {
163
+ response: context.json(
164
+ { error: "organization_required", message: "Factory projects require an organization." },
165
+ 403
166
+ )
167
+ };
168
+ }
169
+ return { orgId: tenant.orgId, userId: tenant.userId };
170
+ }
171
+ routes() {
172
+ return [
173
+ registerApiRoute("/web/factory/projects", {
174
+ method: "GET",
175
+ requiresAuth: false,
176
+ handler: async (routeContext) => {
177
+ const context = loose(routeContext);
178
+ const tenant = await this.#resolveTenant(context);
179
+ if ("response" in tenant) return tenant.response;
180
+ return context.json({ projects: await (await this.#projects()).list({ orgId: tenant.orgId }) });
181
+ }
182
+ }),
183
+ registerApiRoute("/web/factory/projects", {
184
+ method: "POST",
185
+ requiresAuth: false,
186
+ handler: async (routeContext) => {
187
+ const context = loose(routeContext);
188
+ const tenant = await this.#resolveTenant(context);
189
+ if ("response" in tenant) return tenant.response;
190
+ const input = parseCreateInput(await readJson(context));
191
+ if (!input) return context.json({ error: "invalid_project" }, 400);
192
+ const project = await (await this.#projects()).create({ orgId: tenant.orgId, userId: tenant.userId, input });
193
+ return context.json({ project }, 201);
194
+ }
195
+ }),
196
+ registerApiRoute("/web/factory/projects/:id", {
197
+ method: "GET",
198
+ requiresAuth: false,
199
+ handler: async (routeContext) => {
200
+ const context = loose(routeContext);
201
+ const tenant = await this.#resolveTenant(context);
202
+ if ("response" in tenant) return tenant.response;
203
+ const id = context.req.param("id");
204
+ if (!id || !UUID_RE.test(id)) return context.json({ error: "Project not found" }, 404);
205
+ const project = await this.#project(tenant.orgId, id);
206
+ return project ? context.json({ project }) : context.json({ error: "Project not found" }, 404);
207
+ }
208
+ }),
209
+ registerApiRoute("/web/factory/projects/:id", {
210
+ method: "PATCH",
211
+ requiresAuth: false,
212
+ handler: async (routeContext) => {
213
+ const context = loose(routeContext);
214
+ const tenant = await this.#resolveTenant(context);
215
+ if ("response" in tenant) return tenant.response;
216
+ const id = context.req.param("id");
217
+ if (!id || !UUID_RE.test(id)) return context.json({ error: "Project not found" }, 404);
218
+ const input = parseUpdateInput(await readJson(context));
219
+ if (!input) return context.json({ error: "invalid_project" }, 400);
220
+ const project = await (await this.#projects()).update({ orgId: tenant.orgId, id, input });
221
+ return project ? context.json({ project }) : context.json({ error: "Project not found" }, 404);
222
+ }
223
+ }),
224
+ registerApiRoute("/web/factory/projects/:id", {
225
+ method: "DELETE",
226
+ requiresAuth: false,
227
+ handler: async (routeContext) => {
228
+ const context = loose(routeContext);
229
+ const tenant = await this.#resolveTenant(context);
230
+ if ("response" in tenant) return tenant.response;
231
+ const id = context.req.param("id");
232
+ if (!id || !UUID_RE.test(id)) return context.json({ error: "Project not found" }, 404);
233
+ if (!await this.#project(tenant.orgId, id)) return context.json({ error: "Project not found" }, 404);
234
+ for (const handle of await this.#handles()) {
235
+ for (const connection of await handle.connections.list({ orgId: tenant.orgId, factoryProjectId: id })) {
236
+ await handle.connections.delete({ orgId: tenant.orgId, id: connection.id });
237
+ }
238
+ }
239
+ await (await this.#projects()).delete({ orgId: tenant.orgId, id });
240
+ return context.body(null, 204);
241
+ }
242
+ }),
243
+ registerApiRoute("/web/factory/projects/:id/source-control-connections", {
244
+ method: "GET",
245
+ requiresAuth: false,
246
+ handler: async (routeContext) => {
247
+ const context = loose(routeContext);
248
+ const tenant = await this.#resolveTenant(context);
249
+ if ("response" in tenant) return tenant.response;
250
+ const projectId = context.req.param("id");
251
+ if (!projectId || !UUID_RE.test(projectId) || !await this.#project(tenant.orgId, projectId))
252
+ return context.json({ error: "Project not found" }, 404);
253
+ const connections = [];
254
+ for (const handle of await this.#handles()) {
255
+ for (const connection of await handle.connections.list({
256
+ orgId: tenant.orgId,
257
+ factoryProjectId: projectId
258
+ })) {
259
+ const installation = await handle.installations.get({
260
+ orgId: tenant.orgId,
261
+ id: connection.installationId
262
+ });
263
+ const links = await handle.projectRepositories.list({ orgId: tenant.orgId, connectionId: connection.id });
264
+ connections.push({
265
+ ...connection,
266
+ installation,
267
+ repositories: await Promise.all(links.map((link) => this.#repositoryPayload(handle, tenant.orgId, link)))
268
+ });
269
+ }
270
+ }
271
+ return context.json({ connections });
272
+ }
273
+ }),
274
+ registerApiRoute("/web/factory/projects/:id/source-control-connections", {
275
+ method: "POST",
276
+ requiresAuth: false,
277
+ handler: async (routeContext) => {
278
+ const context = loose(routeContext);
279
+ const tenant = await this.#resolveTenant(context);
280
+ if ("response" in tenant) return tenant.response;
281
+ const projectId = context.req.param("id");
282
+ if (!projectId || !UUID_RE.test(projectId) || !await this.#project(tenant.orgId, projectId))
283
+ return context.json({ error: "Project not found" }, 404);
284
+ const input = parseConnectionInput(await readJson(context));
285
+ if (!input) return context.json({ error: "invalid_source_control_connection" }, 400);
286
+ if (!this.#versionControlIntegrationIds.has(input.integrationId))
287
+ return context.json({ error: "Source-control integration not found" }, 404);
288
+ const handle = (await this.#sourceControl()).forIntegration(input.integrationId);
289
+ if (!await handle.installations.get({ orgId: tenant.orgId, id: input.installationId }))
290
+ return context.json({ error: "Source-control installation not found" }, 404);
291
+ const connection = await handle.connections.create({
292
+ orgId: tenant.orgId,
293
+ factoryProjectId: projectId,
294
+ installationId: input.installationId,
295
+ createdByUserId: tenant.userId
296
+ });
297
+ return context.json({ connection }, 201);
298
+ }
299
+ }),
300
+ registerApiRoute("/web/factory/projects/:id/source-control-connections/:connectionId", {
301
+ method: "DELETE",
302
+ requiresAuth: false,
303
+ handler: async (routeContext) => {
304
+ const context = loose(routeContext);
305
+ const tenant = await this.#resolveTenant(context);
306
+ if ("response" in tenant) return tenant.response;
307
+ const projectId = context.req.param("id");
308
+ const connectionId = context.req.param("connectionId");
309
+ if (!projectId || !UUID_RE.test(projectId) || !connectionId || !UUID_RE.test(connectionId))
310
+ return context.json({ error: "Source-control connection not found" }, 404);
311
+ const found = await this.#findConnection({ orgId: tenant.orgId, projectId, id: connectionId });
312
+ if (!found) return context.json({ error: "Source-control connection not found" }, 404);
313
+ await found.handle.connections.delete({ orgId: tenant.orgId, id: connectionId });
314
+ return context.body(null, 204);
315
+ }
316
+ }),
317
+ registerApiRoute("/web/factory/projects/:id/source-control-connections/:connectionId/repositories", {
318
+ method: "POST",
319
+ requiresAuth: false,
320
+ handler: async (routeContext) => {
321
+ const context = loose(routeContext);
322
+ const tenant = await this.#resolveTenant(context);
323
+ if ("response" in tenant) return tenant.response;
324
+ const projectId = context.req.param("id");
325
+ const connectionId = context.req.param("connectionId");
326
+ if (!projectId || !UUID_RE.test(projectId) || !connectionId || !UUID_RE.test(connectionId))
327
+ return context.json({ error: "Source-control connection not found" }, 404);
328
+ const found = await this.#findConnection({ orgId: tenant.orgId, projectId, id: connectionId });
329
+ if (!found) return context.json({ error: "Source-control connection not found" }, 404);
330
+ const input = parseRepositoryLinkInput(await readJson(context));
331
+ if (!input) return context.json({ error: "invalid_project_repository" }, 400);
332
+ const repository = await found.handle.repositories.get({ orgId: tenant.orgId, id: input.repositoryId });
333
+ if (!repository || repository.installationId !== found.connection.installationId)
334
+ return context.json({ error: "Source-control repository not found" }, 404);
335
+ const projectRepository = await found.handle.projectRepositories.link({
336
+ orgId: tenant.orgId,
337
+ connectionId,
338
+ createdByUserId: tenant.userId,
339
+ ...input
340
+ });
341
+ return context.json(
342
+ { projectRepository: await this.#repositoryPayload(found.handle, tenant.orgId, projectRepository) },
343
+ 201
344
+ );
345
+ }
346
+ }),
347
+ registerApiRoute("/web/factory/projects/:id/repositories/:projectRepositoryId", {
348
+ method: "PATCH",
349
+ requiresAuth: false,
350
+ handler: async (routeContext) => {
351
+ const context = loose(routeContext);
352
+ const tenant = await this.#resolveTenant(context);
353
+ if ("response" in tenant) return tenant.response;
354
+ const projectId = context.req.param("id");
355
+ const projectRepositoryId = context.req.param("projectRepositoryId");
356
+ if (!projectId || !UUID_RE.test(projectId) || !projectRepositoryId || !UUID_RE.test(projectRepositoryId))
357
+ return context.json({ error: "Project repository not found" }, 404);
358
+ const found = await this.#findProjectRepository({ orgId: tenant.orgId, projectId, id: projectRepositoryId });
359
+ if (!found) return context.json({ error: "Project repository not found" }, 404);
360
+ const input = parseRepositoryUpdateInput(await readJson(context));
361
+ if (!input) return context.json({ error: "invalid_project_repository" }, 400);
362
+ const projectRepository = await found.handle.projectRepositories.update({
363
+ orgId: tenant.orgId,
364
+ id: projectRepositoryId,
365
+ input
366
+ });
367
+ return context.json({
368
+ projectRepository: await this.#repositoryPayload(found.handle, tenant.orgId, projectRepository)
369
+ });
370
+ }
371
+ }),
372
+ registerApiRoute("/web/factory/projects/:id/repositories/:projectRepositoryId", {
373
+ method: "DELETE",
374
+ requiresAuth: false,
375
+ handler: async (routeContext) => {
376
+ const context = loose(routeContext);
377
+ const tenant = await this.#resolveTenant(context);
378
+ if ("response" in tenant) return tenant.response;
379
+ const projectId = context.req.param("id");
380
+ const projectRepositoryId = context.req.param("projectRepositoryId");
381
+ if (!projectId || !UUID_RE.test(projectId) || !projectRepositoryId || !UUID_RE.test(projectRepositoryId))
382
+ return context.json({ error: "Project repository not found" }, 404);
383
+ const found = await this.#findProjectRepository({ orgId: tenant.orgId, projectId, id: projectRepositoryId });
384
+ if (!found) return context.json({ error: "Project repository not found" }, 404);
385
+ await found.handle.projectRepositories.unlink({ orgId: tenant.orgId, id: projectRepositoryId });
386
+ return context.body(null, 204);
387
+ }
388
+ })
389
+ ];
390
+ }
391
+ };
392
+ export {
393
+ ProjectRoutes
394
+ };
395
+ //# sourceMappingURL=projects.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/routes/projects.ts","../../src/routes/route.ts"],"sourcesContent":["import type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\n\nimport type {\n CreateFactoryProjectInput,\n FactoryProjectsStorage,\n UpdateFactoryProjectInput,\n} from '../storage/domains/projects/base.js';\nimport type {\n ProjectRepository,\n SourceControlStorage,\n SourceControlStorageHandle,\n UpdateProjectRepositoryInput,\n} from '../storage/domains/source-control/base.js';\nimport type { RouteDependencies } from './route.js';\nimport { Route } from './route.js';\n\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nconst MAX_NAME_LENGTH = 200;\nconst MAX_DESCRIPTION_LENGTH = 2_000;\nconst MAX_SETUP_COMMAND_LENGTH = 2_000;\nconst MAX_BRANCH_LENGTH = 255;\nconst MAX_SANDBOX_PROVIDER_LENGTH = 100;\nconst MAX_SANDBOX_WORKDIR_LENGTH = 1_000;\nconst CONTROL_CHAR_RE = /[\\0-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/;\n\nfunction loose(context: unknown): Context {\n return context as Context;\n}\n\nasync function readJson(context: Context): Promise<unknown | undefined> {\n try {\n return await context.req.json();\n } catch {\n return undefined;\n }\n}\n\nfunction parseCreateInput(value: unknown): CreateFactoryProjectInput | null {\n if (!value || typeof value !== 'object') return null;\n const input = value as Record<string, unknown>;\n if (typeof input.name !== 'string') return null;\n const name = input.name.trim();\n if (!name || name.length > MAX_NAME_LENGTH) return null;\n if (input.description !== undefined && input.description !== null && typeof input.description !== 'string')\n return null;\n const description = typeof input.description === 'string' ? input.description.trim() || null : null;\n if (description && description.length > MAX_DESCRIPTION_LENGTH) return null;\n return { name, description };\n}\n\nfunction parseUpdateInput(value: unknown): UpdateFactoryProjectInput | null {\n if (!value || typeof value !== 'object') return null;\n const input = value as Record<string, unknown>;\n const patch: UpdateFactoryProjectInput = {};\n if (input.name !== undefined) {\n if (typeof input.name !== 'string') return null;\n const name = input.name.trim();\n if (!name || name.length > MAX_NAME_LENGTH) return null;\n patch.name = name;\n }\n if (input.description !== undefined) {\n if (input.description !== null && typeof input.description !== 'string') return null;\n const description = typeof input.description === 'string' ? input.description.trim() || null : null;\n if (description && description.length > MAX_DESCRIPTION_LENGTH) return null;\n patch.description = description;\n }\n if (input.defaultModelId !== undefined) {\n const defaultModelId = parseOptionalString(input.defaultModelId, { maxLength: MAX_NAME_LENGTH, nullable: true });\n if (defaultModelId === false) return null;\n patch.defaultModelId = defaultModelId ?? null;\n }\n return Object.keys(patch).length > 0 ? patch : null;\n}\n\nfunction parseConnectionInput(value: unknown): { integrationId: string; installationId: string } | null {\n if (!value || typeof value !== 'object') return null;\n const input = value as Record<string, unknown>;\n if (typeof input.integrationId !== 'string' || !input.integrationId.trim()) return null;\n if (typeof input.installationId !== 'string' || !UUID_RE.test(input.installationId)) return null;\n return { integrationId: input.integrationId.trim(), installationId: input.installationId };\n}\n\nfunction parseOptionalString(\n value: unknown,\n { maxLength, nullable = false }: { maxLength: number; nullable?: boolean },\n): string | null | undefined | false {\n if (value === undefined) return undefined;\n if (value === null) return nullable ? null : false;\n if (typeof value !== 'string') return false;\n const normalized = value.trim();\n if (!normalized) return nullable ? null : false;\n if (normalized.length > maxLength || CONTROL_CHAR_RE.test(normalized)) return false;\n return normalized;\n}\n\nfunction parseRepositoryLinkInput(value: unknown): {\n repositoryId: string;\n branch: string | null;\n sandboxProvider: string;\n sandboxWorkdir: string;\n setupCommand: string | null;\n} | null {\n if (!value || typeof value !== 'object') return null;\n const input = value as Record<string, unknown>;\n if (typeof input.repositoryId !== 'string' || !UUID_RE.test(input.repositoryId)) return null;\n const branch = parseOptionalString(input.branch, { maxLength: MAX_BRANCH_LENGTH, nullable: true });\n const sandboxProvider = parseOptionalString(input.sandboxProvider, { maxLength: MAX_SANDBOX_PROVIDER_LENGTH });\n const sandboxWorkdir = parseOptionalString(input.sandboxWorkdir, { maxLength: MAX_SANDBOX_WORKDIR_LENGTH });\n const setupCommand = parseOptionalString(input.setupCommand, { maxLength: MAX_SETUP_COMMAND_LENGTH, nullable: true });\n if (\n branch === false ||\n typeof sandboxProvider !== 'string' ||\n typeof sandboxWorkdir !== 'string' ||\n setupCommand === false\n )\n return null;\n return {\n repositoryId: input.repositoryId,\n branch: branch ?? null,\n sandboxProvider,\n sandboxWorkdir,\n setupCommand: setupCommand ?? null,\n };\n}\n\nfunction parseRepositoryUpdateInput(value: unknown): UpdateProjectRepositoryInput | null {\n if (!value || typeof value !== 'object') return null;\n const input = value as Record<string, unknown>;\n const patch: UpdateProjectRepositoryInput = {};\n const branch = parseOptionalString(input.branch, { maxLength: MAX_BRANCH_LENGTH, nullable: true });\n const sandboxProvider = parseOptionalString(input.sandboxProvider, { maxLength: MAX_SANDBOX_PROVIDER_LENGTH });\n const sandboxWorkdir = parseOptionalString(input.sandboxWorkdir, { maxLength: MAX_SANDBOX_WORKDIR_LENGTH });\n const setupCommand = parseOptionalString(input.setupCommand, { maxLength: MAX_SETUP_COMMAND_LENGTH, nullable: true });\n if (\n branch === false ||\n sandboxProvider === false ||\n sandboxProvider === null ||\n sandboxWorkdir === false ||\n sandboxWorkdir === null ||\n setupCommand === false\n )\n return null;\n if (branch !== undefined) patch.branch = branch;\n if (sandboxProvider !== undefined) patch.sandboxProvider = sandboxProvider;\n if (sandboxWorkdir !== undefined) patch.sandboxWorkdir = sandboxWorkdir;\n if (setupCommand !== undefined) patch.setupCommand = setupCommand;\n return Object.keys(patch).length > 0 ? patch : null;\n}\n\nexport interface ProjectRoutesDeps extends RouteDependencies {\n /** Factory projects domain backing the CRUD surface. */\n projects: FactoryProjectsStorage;\n /** Source-control domain the connection/repository routes fan out over. */\n sourceControl: SourceControlStorage;\n /** Integration ids allowed as source-control connection targets. */\n versionControlIntegrationIds?: string[];\n}\n\nexport class ProjectRoutes extends Route<ProjectRoutesDeps> {\n readonly #versionControlIntegrationIds: Set<string>;\n\n constructor(deps: ProjectRoutesDeps) {\n super(deps);\n this.#versionControlIntegrationIds = new Set(deps.versionControlIntegrationIds ?? []);\n }\n\n async #projects(): Promise<FactoryProjectsStorage> {\n await this.deps.projects.ensureReady();\n return this.deps.projects;\n }\n\n async #sourceControl(): Promise<SourceControlStorage> {\n await this.deps.sourceControl.ensureReady();\n return this.deps.sourceControl;\n }\n\n async #handles(): Promise<SourceControlStorageHandle[]> {\n const storage = await this.#sourceControl();\n return [...this.#versionControlIntegrationIds].map(integrationId => storage.forIntegration(integrationId));\n }\n\n async #project(orgId: string, id: string) {\n return (await this.#projects()).get({ orgId, id });\n }\n\n async #findConnection({ orgId, projectId, id }: { orgId: string; projectId: string; id: string }) {\n for (const handle of await this.#handles()) {\n const connection = await handle.connections.get({ orgId, id });\n if (connection?.factoryProjectId === projectId) return { handle, connection };\n }\n return null;\n }\n\n async #findProjectRepository({ orgId, projectId, id }: { orgId: string; projectId: string; id: string }) {\n for (const handle of await this.#handles()) {\n const projectRepository = await handle.projectRepositories.get({ orgId, id });\n if (!projectRepository) continue;\n const connection = await handle.connections.get({ orgId, id: projectRepository.connectionId });\n if (connection?.factoryProjectId === projectId) return { handle, connection, projectRepository };\n }\n return null;\n }\n\n async #repositoryPayload(handle: SourceControlStorageHandle, orgId: string, projectRepository: ProjectRepository) {\n const repository = await handle.repositories.get({ orgId, id: projectRepository.repositoryId });\n return { ...projectRepository, repository };\n }\n\n async #resolveTenant(context: Context): Promise<{ orgId: string; userId: string } | { response: Response }> {\n await this.deps.auth.ensureUser(context);\n const tenant = this.deps.auth.tenant(context);\n if (!tenant) return { response: context.json({ error: 'unauthorized' }, 401) };\n if (!tenant.orgId) {\n return {\n response: context.json(\n { error: 'organization_required', message: 'Factory projects require an organization.' },\n 403,\n ),\n };\n }\n return { orgId: tenant.orgId, userId: tenant.userId };\n }\n\n routes(): ApiRoute[] {\n return [\n registerApiRoute('/web/factory/projects', {\n method: 'GET',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n return context.json({ projects: await (await this.#projects()).list({ orgId: tenant.orgId }) });\n },\n }),\n registerApiRoute('/web/factory/projects', {\n method: 'POST',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const input = parseCreateInput(await readJson(context));\n if (!input) return context.json({ error: 'invalid_project' }, 400);\n const project = await (await this.#projects()).create({ orgId: tenant.orgId, userId: tenant.userId, input });\n return context.json({ project }, 201);\n },\n }),\n registerApiRoute('/web/factory/projects/:id', {\n method: 'GET',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const id = context.req.param('id');\n if (!id || !UUID_RE.test(id)) return context.json({ error: 'Project not found' }, 404);\n const project = await this.#project(tenant.orgId, id);\n return project ? context.json({ project }) : context.json({ error: 'Project not found' }, 404);\n },\n }),\n registerApiRoute('/web/factory/projects/:id', {\n method: 'PATCH',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const id = context.req.param('id');\n if (!id || !UUID_RE.test(id)) return context.json({ error: 'Project not found' }, 404);\n const input = parseUpdateInput(await readJson(context));\n if (!input) return context.json({ error: 'invalid_project' }, 400);\n const project = await (await this.#projects()).update({ orgId: tenant.orgId, id, input });\n return project ? context.json({ project }) : context.json({ error: 'Project not found' }, 404);\n },\n }),\n registerApiRoute('/web/factory/projects/:id', {\n method: 'DELETE',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const id = context.req.param('id');\n if (!id || !UUID_RE.test(id)) return context.json({ error: 'Project not found' }, 404);\n if (!(await this.#project(tenant.orgId, id))) return context.json({ error: 'Project not found' }, 404);\n for (const handle of await this.#handles()) {\n for (const connection of await handle.connections.list({ orgId: tenant.orgId, factoryProjectId: id })) {\n await handle.connections.delete({ orgId: tenant.orgId, id: connection.id });\n }\n }\n await (await this.#projects()).delete({ orgId: tenant.orgId, id });\n return context.body(null, 204);\n },\n }),\n registerApiRoute('/web/factory/projects/:id/source-control-connections', {\n method: 'GET',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const projectId = context.req.param('id');\n if (!projectId || !UUID_RE.test(projectId) || !(await this.#project(tenant.orgId, projectId)))\n return context.json({ error: 'Project not found' }, 404);\n const connections = [];\n for (const handle of await this.#handles()) {\n for (const connection of await handle.connections.list({\n orgId: tenant.orgId,\n factoryProjectId: projectId,\n })) {\n const installation = await handle.installations.get({\n orgId: tenant.orgId,\n id: connection.installationId,\n });\n const links = await handle.projectRepositories.list({ orgId: tenant.orgId, connectionId: connection.id });\n connections.push({\n ...connection,\n installation,\n repositories: await Promise.all(links.map(link => this.#repositoryPayload(handle, tenant.orgId, link))),\n });\n }\n }\n return context.json({ connections });\n },\n }),\n registerApiRoute('/web/factory/projects/:id/source-control-connections', {\n method: 'POST',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const projectId = context.req.param('id');\n if (!projectId || !UUID_RE.test(projectId) || !(await this.#project(tenant.orgId, projectId)))\n return context.json({ error: 'Project not found' }, 404);\n const input = parseConnectionInput(await readJson(context));\n if (!input) return context.json({ error: 'invalid_source_control_connection' }, 400);\n if (!this.#versionControlIntegrationIds.has(input.integrationId))\n return context.json({ error: 'Source-control integration not found' }, 404);\n const handle = (await this.#sourceControl()).forIntegration(input.integrationId);\n if (!(await handle.installations.get({ orgId: tenant.orgId, id: input.installationId })))\n return context.json({ error: 'Source-control installation not found' }, 404);\n const connection = await handle.connections.create({\n orgId: tenant.orgId,\n factoryProjectId: projectId,\n installationId: input.installationId,\n createdByUserId: tenant.userId,\n });\n return context.json({ connection }, 201);\n },\n }),\n registerApiRoute('/web/factory/projects/:id/source-control-connections/:connectionId', {\n method: 'DELETE',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const projectId = context.req.param('id');\n const connectionId = context.req.param('connectionId');\n if (!projectId || !UUID_RE.test(projectId) || !connectionId || !UUID_RE.test(connectionId))\n return context.json({ error: 'Source-control connection not found' }, 404);\n const found = await this.#findConnection({ orgId: tenant.orgId, projectId, id: connectionId });\n if (!found) return context.json({ error: 'Source-control connection not found' }, 404);\n await found.handle.connections.delete({ orgId: tenant.orgId, id: connectionId });\n return context.body(null, 204);\n },\n }),\n registerApiRoute('/web/factory/projects/:id/source-control-connections/:connectionId/repositories', {\n method: 'POST',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const projectId = context.req.param('id');\n const connectionId = context.req.param('connectionId');\n if (!projectId || !UUID_RE.test(projectId) || !connectionId || !UUID_RE.test(connectionId))\n return context.json({ error: 'Source-control connection not found' }, 404);\n const found = await this.#findConnection({ orgId: tenant.orgId, projectId, id: connectionId });\n if (!found) return context.json({ error: 'Source-control connection not found' }, 404);\n const input = parseRepositoryLinkInput(await readJson(context));\n if (!input) return context.json({ error: 'invalid_project_repository' }, 400);\n const repository = await found.handle.repositories.get({ orgId: tenant.orgId, id: input.repositoryId });\n if (!repository || repository.installationId !== found.connection.installationId)\n return context.json({ error: 'Source-control repository not found' }, 404);\n const projectRepository = await found.handle.projectRepositories.link({\n orgId: tenant.orgId,\n connectionId,\n createdByUserId: tenant.userId,\n ...input,\n });\n return context.json(\n { projectRepository: await this.#repositoryPayload(found.handle, tenant.orgId, projectRepository) },\n 201,\n );\n },\n }),\n registerApiRoute('/web/factory/projects/:id/repositories/:projectRepositoryId', {\n method: 'PATCH',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const projectId = context.req.param('id');\n const projectRepositoryId = context.req.param('projectRepositoryId');\n if (!projectId || !UUID_RE.test(projectId) || !projectRepositoryId || !UUID_RE.test(projectRepositoryId))\n return context.json({ error: 'Project repository not found' }, 404);\n const found = await this.#findProjectRepository({ orgId: tenant.orgId, projectId, id: projectRepositoryId });\n if (!found) return context.json({ error: 'Project repository not found' }, 404);\n const input = parseRepositoryUpdateInput(await readJson(context));\n if (!input) return context.json({ error: 'invalid_project_repository' }, 400);\n const projectRepository = await found.handle.projectRepositories.update({\n orgId: tenant.orgId,\n id: projectRepositoryId,\n input,\n });\n return context.json({\n projectRepository: await this.#repositoryPayload(found.handle, tenant.orgId, projectRepository!),\n });\n },\n }),\n registerApiRoute('/web/factory/projects/:id/repositories/:projectRepositoryId', {\n method: 'DELETE',\n requiresAuth: false,\n handler: async routeContext => {\n const context = loose(routeContext);\n const tenant = await this.#resolveTenant(context);\n if ('response' in tenant) return tenant.response;\n const projectId = context.req.param('id');\n const projectRepositoryId = context.req.param('projectRepositoryId');\n if (!projectId || !UUID_RE.test(projectId) || !projectRepositoryId || !UUID_RE.test(projectRepositoryId))\n return context.json({ error: 'Project repository not found' }, 404);\n const found = await this.#findProjectRepository({ orgId: tenant.orgId, projectId, id: projectRepositoryId });\n if (!found) return context.json({ error: 'Project repository not found' }, 404);\n await found.handle.projectRepositories.unlink({ orgId: tenant.orgId, id: projectRepositoryId });\n return context.body(null, 204);\n },\n }),\n ];\n }\n}\n","/**\n * Base class for factory route modules.\n *\n * Route modules build Mastra `apiRoutes` from injected dependencies instead of\n * reaching into host globals. The host server (e.g. `mastracode/web`) supplies\n * the auth seam and storage domain handles at construction time, so the routes\n * stay portable and testable with fakes.\n */\n\nimport type { ApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\n\n/**\n * The auth surface factory routes need, implemented by the host server.\n *\n * Local (no-auth) deployments implement this with a stub where `enabled()`\n * returns `false` and `tenant()` returns `undefined` — routes then take their\n * single-user local paths.\n */\nexport interface RouteAuth {\n /** Whether an auth provider is active (tenant mode). */\n enabled(): boolean;\n /**\n * Resolve (and cache) the signed-in user for the request, if any. Must be\n * called before `tenant()` so the request context is populated.\n */\n ensureUser(c: Context): Promise<unknown>;\n /** Tenant identity for the request, when signed in. */\n tenant(c: Context): { orgId?: string; userId: string } | undefined;\n /** Fail-closed check that the caller administers the given organization. */\n isOrganizationAdmin(c: Context, organizationId: string): Promise<boolean>;\n}\n\n/** Dependencies shared by every factory route module. */\nexport interface RouteDependencies {\n auth: RouteAuth;\n}\n\n/**\n * A route module: constructed once at boot with its dependencies, then asked\n * for the `ApiRoute[]` it serves.\n */\nexport abstract class Route<TDeps extends RouteDependencies = RouteDependencies> {\n protected readonly deps: TDeps;\n\n constructor(deps: TDeps) {\n this.deps = deps;\n }\n\n /** Build the Mastra `apiRoutes` served by this module. */\n abstract routes(): ApiRoute[];\n}\n"],"mappings":";AACA,SAAS,wBAAwB;;;ACyC1B,IAAe,QAAf,MAA0E;AAAA,EAC5D;AAAA,EAEnB,YAAY,MAAa;AACvB,SAAK,OAAO;AAAA,EACd;AAIF;;;ADjCA,IAAM,UAAU;AAChB,IAAM,kBAAkB;AACxB,IAAM,yBAAyB;AAC/B,IAAM,2BAA2B;AACjC,IAAM,oBAAoB;AAC1B,IAAM,8BAA8B;AACpC,IAAM,6BAA6B;AACnC,IAAM,kBAAkB;AAExB,SAAS,MAAM,SAA2B;AACxC,SAAO;AACT;AAEA,eAAe,SAAS,SAAgD;AACtE,MAAI;AACF,WAAO,MAAM,QAAQ,IAAI,KAAK;AAAA,EAChC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,iBAAiB,OAAkD;AAC1E,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,QAAQ;AACd,MAAI,OAAO,MAAM,SAAS,SAAU,QAAO;AAC3C,QAAM,OAAO,MAAM,KAAK,KAAK;AAC7B,MAAI,CAAC,QAAQ,KAAK,SAAS,gBAAiB,QAAO;AACnD,MAAI,MAAM,gBAAgB,UAAa,MAAM,gBAAgB,QAAQ,OAAO,MAAM,gBAAgB;AAChG,WAAO;AACT,QAAM,cAAc,OAAO,MAAM,gBAAgB,WAAW,MAAM,YAAY,KAAK,KAAK,OAAO;AAC/F,MAAI,eAAe,YAAY,SAAS,uBAAwB,QAAO;AACvE,SAAO,EAAE,MAAM,YAAY;AAC7B;AAEA,SAAS,iBAAiB,OAAkD;AAC1E,MAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;AAChD,QAAM,QAAQ;AACd,QAAM,QAAmC,CAAC;AAC1C,MAAI,MAAM,SAAS,QAAW;A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O,EAAE,OAAO,OAAO,OAAO,IAAI,oBAAoB,CAAC;AAC9F,iBAAO,QAAQ,KAAK,MAAM,GAAG;AAAA,QAC/B;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Per-request model-provider credential context.
3
+ *
4
+ * The provider config/OAuth routes serve two deployment shapes:
5
+ *
6
+ * - **Local** (no web auth adapter): credentials live in the server-global
7
+ * file-backed `AuthStorage` (`auth.json`) — unchanged TUI behavior.
8
+ * - **Tenant** (auth adapter active): credentials live in the
9
+ * `model-credentials` factory storage domain, scoped per `(orgId, userId)`
10
+ * with optional org-wide rows (`userId` absent).
11
+ *
12
+ * `resolveCredentialContext` decides which shape a request is in: an
13
+ * authenticated user always gets the tenant path; an unauthenticated request
14
+ * is rejected when auth is enabled and falls back to local otherwise.
15
+ */
16
+ import type { Context } from 'hono';
17
+ import type { CredentialRecord, LoginSessionKind, ModelCredentialsStorage } from '../storage/domains/credentials/base.js';
18
+ import type { RouteAuth } from './route.js';
19
+ /**
20
+ * OAuth credentials are stored under the auth provider id, which differs from
21
+ * the catalog provider id for OpenAI (stored as `openai-codex`). Tenant rows
22
+ * use the same keying so one lookup serves both OAuth tokens and API keys.
23
+ */
24
+ export declare function getAuthProviderId(provider: string): string;
25
+ /**
26
+ * Providers that support a browser-driven OAuth sign-in flow, keyed by
27
+ * *catalog* provider id (what the routes and settings UI use). All flows need
28
+ * no inbound connection to the server: Anthropic uses paste-code PKCE, the
29
+ * rest use RFC 8628-style device codes.
30
+ */
31
+ export declare const WEB_OAUTH_FLOW_KINDS: Readonly<Record<string, LoginSessionKind>>;
32
+ export type CredentialContext = {
33
+ mode: 'local';
34
+ } | {
35
+ mode: 'tenant';
36
+ storage: ModelCredentialsStorage;
37
+ orgId: string;
38
+ userId: string;
39
+ };
40
+ /**
41
+ * The tenant credentials domain, when registered and ready. `undefined` means
42
+ * the factory never ran (no handle threaded in) or the domain's init failed
43
+ * (fail-soft — callers report the feature unavailable instead of crashing).
44
+ */
45
+ export declare function getTenantCredentialsStorage(credentials: ModelCredentialsStorage | undefined): Promise<ModelCredentialsStorage | undefined>;
46
+ /**
47
+ * Org key for tenant rows. Personal accounts get an org bootstrapped by the
48
+ * auth adapter (`ensureOrg`); if one still isn't present, scope rows under a
49
+ * per-user synthetic org so credentials never become server-global.
50
+ */
51
+ export declare function tenantOrgId(tenant: {
52
+ orgId?: string;
53
+ userId: string;
54
+ }): string;
55
+ /**
56
+ * Resolve the credential context for a request, or a ready-to-return error
57
+ * response. Mutating credential routes call this and hard-fail (401/503)
58
+ * when the tenant path is required but unavailable.
59
+ */
60
+ export declare function resolveCredentialContext({ c, auth, credentials, }: {
61
+ c: Context;
62
+ auth: RouteAuth;
63
+ /** Tenant credential domain handle; absent in local (no-DB) mode. */
64
+ credentials?: ModelCredentialsStorage;
65
+ }): Promise<CredentialContext | {
66
+ response: Response;
67
+ }>;
68
+ /**
69
+ * List the caller's tenant credential records for provider listing, or
70
+ * `undefined` in local mode (caller should fall back to `AuthStorage`).
71
+ * Read-only and degradation-friendly: an authenticated caller with the domain
72
+ * unavailable gets an empty list (sources show `env`/`none`) instead of a 503
73
+ * so the settings page still renders.
74
+ */
75
+ export declare function listTenantCredentialsForRequest({ c, auth, credentials, }: {
76
+ c: Context;
77
+ auth: RouteAuth;
78
+ /** Tenant credential domain handle; absent in local (no-DB) mode. */
79
+ credentials?: ModelCredentialsStorage;
80
+ }): Promise<CredentialRecord[] | undefined>;
81
+ //# sourceMappingURL=provider-credentials.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-credentials.d.ts","sourceRoot":"","sources":["../../src/routes/provider-credentials.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,wCAAwC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CAAC;CACvC,GAAG,OAAO,CAAC,gBAAgB,EAAE,GAAG,SAAS,CAAC,CAO1C"}
@@ -0,0 +1,68 @@
1
+ // src/routes/provider-credentials.ts
2
+ function getAuthProviderId(provider) {
3
+ return provider === "openai" ? "openai-codex" : provider;
4
+ }
5
+ var WEB_OAUTH_FLOW_KINDS = {
6
+ anthropic: "paste-code",
7
+ openai: "device-code",
8
+ "github-copilot": "device-code",
9
+ xai: "device-code"
10
+ };
11
+ async function getTenantCredentialsStorage(credentials) {
12
+ if (!credentials) return void 0;
13
+ try {
14
+ await credentials.ensureReady();
15
+ } catch {
16
+ return void 0;
17
+ }
18
+ return credentials;
19
+ }
20
+ function tenantOrgId(tenant) {
21
+ return tenant.orgId ?? `user:${tenant.userId}`;
22
+ }
23
+ async function resolveCredentialContext({
24
+ c,
25
+ auth,
26
+ credentials
27
+ }) {
28
+ await auth.ensureUser(c);
29
+ const tenant = auth.tenant(c);
30
+ if (!tenant) {
31
+ if (auth.enabled()) return { response: c.json({ error: "unauthorized" }, 401) };
32
+ return { mode: "local" };
33
+ }
34
+ const storage = await getTenantCredentialsStorage(credentials);
35
+ if (!storage) {
36
+ return {
37
+ response: c.json(
38
+ {
39
+ error: "credentials_unavailable",
40
+ message: "Tenant credential storage is unavailable \u2014 the app database is not configured or failed to start."
41
+ },
42
+ 503
43
+ )
44
+ };
45
+ }
46
+ return { mode: "tenant", storage, orgId: tenantOrgId(tenant), userId: tenant.userId };
47
+ }
48
+ async function listTenantCredentialsForRequest({
49
+ c,
50
+ auth,
51
+ credentials
52
+ }) {
53
+ await auth.ensureUser(c);
54
+ const tenant = auth.tenant(c);
55
+ if (!tenant) return auth.enabled() ? [] : void 0;
56
+ const storage = await getTenantCredentialsStorage(credentials);
57
+ if (!storage) return [];
58
+ return storage.listCredentials(tenantOrgId(tenant), tenant.userId);
59
+ }
60
+ export {
61
+ WEB_OAUTH_FLOW_KINDS,
62
+ getAuthProviderId,
63
+ getTenantCredentialsStorage,
64
+ listTenantCredentialsForRequest,
65
+ resolveCredentialContext,
66
+ tenantOrgId
67
+ };
68
+ //# sourceMappingURL=provider-credentials.js.map