@braidhq/server 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (376) hide show
  1. package/README.md +164 -0
  2. package/dist/app.d.ts +12 -3
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/app.js +154 -9
  5. package/dist/app.js.map +1 -1
  6. package/dist/authMode.d.ts +39 -0
  7. package/dist/authMode.d.ts.map +1 -0
  8. package/dist/authMode.js +50 -0
  9. package/dist/authMode.js.map +1 -0
  10. package/dist/composeApp.d.ts +79 -0
  11. package/dist/composeApp.d.ts.map +1 -0
  12. package/dist/composeApp.js +136 -0
  13. package/dist/composeApp.js.map +1 -0
  14. package/dist/composeFsApp.d.ts +27 -0
  15. package/dist/composeFsApp.d.ts.map +1 -0
  16. package/dist/composeFsApp.js +309 -0
  17. package/dist/composeFsApp.js.map +1 -0
  18. package/dist/index.d.ts +3 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +3 -2
  21. package/dist/index.js.map +1 -1
  22. package/dist/infrastructure/_shared/env.d.ts +10 -0
  23. package/dist/infrastructure/_shared/env.d.ts.map +1 -0
  24. package/dist/infrastructure/_shared/env.js +19 -0
  25. package/dist/infrastructure/_shared/env.js.map +1 -0
  26. package/dist/infrastructure/_shared/frontmatter.d.ts +13 -0
  27. package/dist/infrastructure/_shared/frontmatter.d.ts.map +1 -0
  28. package/dist/infrastructure/{fs → _shared}/frontmatter.js +5 -5
  29. package/dist/infrastructure/_shared/frontmatter.js.map +1 -0
  30. package/dist/infrastructure/_shared/jsonFileStore.d.ts.map +1 -0
  31. package/dist/infrastructure/_shared/jsonFileStore.js.map +1 -0
  32. package/dist/infrastructure/_shared/paths.d.ts +43 -0
  33. package/dist/infrastructure/_shared/paths.d.ts.map +1 -0
  34. package/dist/infrastructure/_shared/paths.js +96 -0
  35. package/dist/infrastructure/_shared/paths.js.map +1 -0
  36. package/dist/infrastructure/auth/AccessPolicy.d.ts +87 -0
  37. package/dist/infrastructure/auth/AccessPolicy.d.ts.map +1 -0
  38. package/dist/infrastructure/auth/AccessPolicy.js +177 -0
  39. package/dist/infrastructure/auth/AccessPolicy.js.map +1 -0
  40. package/dist/infrastructure/auth/SessionStore.d.ts +50 -0
  41. package/dist/infrastructure/auth/SessionStore.d.ts.map +1 -0
  42. package/dist/infrastructure/auth/SessionStore.js +104 -0
  43. package/dist/infrastructure/auth/SessionStore.js.map +1 -0
  44. package/dist/infrastructure/batch/FsBatchPlanRepository.d.ts +79 -0
  45. package/dist/infrastructure/batch/FsBatchPlanRepository.d.ts.map +1 -0
  46. package/dist/infrastructure/batch/FsBatchPlanRepository.js +42 -0
  47. package/dist/infrastructure/batch/FsBatchPlanRepository.js.map +1 -0
  48. package/dist/infrastructure/history/GitWorkspaceHistory.d.ts +18 -0
  49. package/dist/infrastructure/history/GitWorkspaceHistory.d.ts.map +1 -0
  50. package/dist/infrastructure/history/GitWorkspaceHistory.js +310 -0
  51. package/dist/infrastructure/history/GitWorkspaceHistory.js.map +1 -0
  52. package/dist/infrastructure/history/commitMessage.d.ts +4 -0
  53. package/dist/infrastructure/history/commitMessage.d.ts.map +1 -0
  54. package/dist/infrastructure/history/commitMessage.js +90 -0
  55. package/dist/infrastructure/history/commitMessage.js.map +1 -0
  56. package/dist/infrastructure/hitl/FsClarificationRepository.d.ts +13 -0
  57. package/dist/infrastructure/hitl/FsClarificationRepository.d.ts.map +1 -0
  58. package/dist/infrastructure/hitl/FsClarificationRepository.js +39 -0
  59. package/dist/infrastructure/hitl/FsClarificationRepository.js.map +1 -0
  60. package/dist/infrastructure/hitl/FsProposalRepository.d.ts.map +1 -0
  61. package/dist/infrastructure/{fs → hitl}/FsProposalRepository.js +10 -3
  62. package/dist/infrastructure/hitl/FsProposalRepository.js.map +1 -0
  63. package/dist/infrastructure/hitl/StatusedJsonStore.d.ts +30 -0
  64. package/dist/infrastructure/hitl/StatusedJsonStore.d.ts.map +1 -0
  65. package/dist/infrastructure/{fs/FsStatusedJsonRepository.js → hitl/StatusedJsonStore.js} +3 -3
  66. package/dist/infrastructure/hitl/StatusedJsonStore.js.map +1 -0
  67. package/dist/infrastructure/model/FsModelSerializer.d.ts +96 -0
  68. package/dist/infrastructure/model/FsModelSerializer.d.ts.map +1 -0
  69. package/dist/infrastructure/model/FsModelSerializer.js +60 -0
  70. package/dist/infrastructure/model/FsModelSerializer.js.map +1 -0
  71. package/dist/infrastructure/oauth/GoogleOAuth.d.ts +43 -14
  72. package/dist/infrastructure/oauth/GoogleOAuth.d.ts.map +1 -1
  73. package/dist/infrastructure/oauth/GoogleOAuth.js +78 -11
  74. package/dist/infrastructure/oauth/GoogleOAuth.js.map +1 -1
  75. package/dist/infrastructure/reactor/FsReactorCycleRepository.d.ts +29 -0
  76. package/dist/infrastructure/reactor/FsReactorCycleRepository.d.ts.map +1 -0
  77. package/dist/infrastructure/reactor/FsReactorCycleRepository.js +94 -0
  78. package/dist/infrastructure/reactor/FsReactorCycleRepository.js.map +1 -0
  79. package/dist/infrastructure/secrets/SecretStore.d.ts +11 -14
  80. package/dist/infrastructure/secrets/SecretStore.d.ts.map +1 -1
  81. package/dist/infrastructure/secrets/SecretStore.js +4 -4
  82. package/dist/infrastructure/secrets/SecretStore.js.map +1 -1
  83. package/dist/infrastructure/{fs → skill}/FsRunRepository.d.ts +9 -4
  84. package/dist/infrastructure/skill/FsRunRepository.d.ts.map +1 -0
  85. package/dist/infrastructure/skill/FsRunRepository.js +162 -0
  86. package/dist/infrastructure/skill/FsRunRepository.js.map +1 -0
  87. package/dist/infrastructure/{fs → skill}/FsSkillRegistry.d.ts +4 -13
  88. package/dist/infrastructure/skill/FsSkillRegistry.d.ts.map +1 -0
  89. package/dist/infrastructure/{fs → skill}/FsSkillRegistry.js +38 -18
  90. package/dist/infrastructure/skill/FsSkillRegistry.js.map +1 -0
  91. package/dist/infrastructure/{agent → skill}/SubprocessSkillRunner.d.ts +13 -15
  92. package/dist/infrastructure/skill/SubprocessSkillRunner.d.ts.map +1 -0
  93. package/dist/infrastructure/{agent → skill}/SubprocessSkillRunner.js +124 -40
  94. package/dist/infrastructure/skill/SubprocessSkillRunner.js.map +1 -0
  95. package/dist/infrastructure/skill/asyncQueue.d.ts +20 -0
  96. package/dist/infrastructure/skill/asyncQueue.d.ts.map +1 -0
  97. package/dist/infrastructure/{agent → skill}/asyncQueue.js +2 -3
  98. package/dist/infrastructure/{agent → skill}/asyncQueue.js.map +1 -1
  99. package/dist/infrastructure/skill/lineBuffer.d.ts +15 -0
  100. package/dist/infrastructure/skill/lineBuffer.d.ts.map +1 -0
  101. package/dist/infrastructure/{agent/streamJsonParser.js → skill/lineBuffer.js} +5 -17
  102. package/dist/infrastructure/skill/lineBuffer.js.map +1 -0
  103. package/dist/infrastructure/skill/orphanReaper.d.ts +20 -0
  104. package/dist/infrastructure/skill/orphanReaper.d.ts.map +1 -0
  105. package/dist/infrastructure/{orphanReaper.js → skill/orphanReaper.js} +7 -5
  106. package/dist/infrastructure/skill/orphanReaper.js.map +1 -0
  107. package/dist/infrastructure/skill/subprocessEventStream.d.ts +16 -0
  108. package/dist/infrastructure/skill/subprocessEventStream.d.ts.map +1 -0
  109. package/dist/infrastructure/skill/subprocessEventStream.js +29 -0
  110. package/dist/infrastructure/skill/subprocessEventStream.js.map +1 -0
  111. package/dist/infrastructure/source/FsSourceUnitDigest.d.ts +19 -0
  112. package/dist/infrastructure/source/FsSourceUnitDigest.d.ts.map +1 -0
  113. package/dist/infrastructure/source/FsSourceUnitDigest.js +58 -0
  114. package/dist/infrastructure/source/FsSourceUnitDigest.js.map +1 -0
  115. package/dist/infrastructure/source/FsSourceUnitObservationRepository.d.ts +31 -0
  116. package/dist/infrastructure/source/FsSourceUnitObservationRepository.d.ts.map +1 -0
  117. package/dist/infrastructure/source/FsSourceUnitObservationRepository.js +88 -0
  118. package/dist/infrastructure/source/FsSourceUnitObservationRepository.js.map +1 -0
  119. package/dist/infrastructure/source/intentScan.d.ts +13 -0
  120. package/dist/infrastructure/source/intentScan.d.ts.map +1 -0
  121. package/dist/infrastructure/source/intentScan.js +137 -0
  122. package/dist/infrastructure/source/intentScan.js.map +1 -0
  123. package/dist/infrastructure/users/UserDirectoryFromRegistry.d.ts +14 -0
  124. package/dist/infrastructure/users/UserDirectoryFromRegistry.d.ts.map +1 -0
  125. package/dist/infrastructure/users/UserDirectoryFromRegistry.js +21 -0
  126. package/dist/infrastructure/users/UserDirectoryFromRegistry.js.map +1 -0
  127. package/dist/infrastructure/users/UserRegistryFile.d.ts +22 -0
  128. package/dist/infrastructure/users/UserRegistryFile.d.ts.map +1 -0
  129. package/dist/infrastructure/users/UserRegistryFile.js +89 -0
  130. package/dist/infrastructure/users/UserRegistryFile.js.map +1 -0
  131. package/dist/infrastructure/users/ensureWorkspaceOwners.d.ts +12 -0
  132. package/dist/infrastructure/users/ensureWorkspaceOwners.d.ts.map +1 -0
  133. package/dist/infrastructure/users/ensureWorkspaceOwners.js +25 -0
  134. package/dist/infrastructure/users/ensureWorkspaceOwners.js.map +1 -0
  135. package/dist/infrastructure/workspace/FsWorkspaceRepository.d.ts.map +1 -0
  136. package/dist/infrastructure/{fs → workspace}/FsWorkspaceRepository.js +15 -5
  137. package/dist/infrastructure/workspace/FsWorkspaceRepository.js.map +1 -0
  138. package/dist/infrastructure/workspace/WorkspaceDiscovery.d.ts +18 -0
  139. package/dist/infrastructure/workspace/WorkspaceDiscovery.d.ts.map +1 -0
  140. package/dist/infrastructure/workspace/WorkspaceDiscovery.js +50 -0
  141. package/dist/infrastructure/workspace/WorkspaceDiscovery.js.map +1 -0
  142. package/dist/infrastructure/workspace/WorkspaceRegistryFile.d.ts +42 -0
  143. package/dist/infrastructure/workspace/WorkspaceRegistryFile.d.ts.map +1 -0
  144. package/dist/infrastructure/workspace/WorkspaceRegistryFile.js +160 -0
  145. package/dist/infrastructure/workspace/WorkspaceRegistryFile.js.map +1 -0
  146. package/dist/infrastructure/workspace/productManifestWriter.d.ts +24 -0
  147. package/dist/infrastructure/workspace/productManifestWriter.d.ts.map +1 -0
  148. package/dist/infrastructure/{fs → workspace}/productManifestWriter.js +14 -28
  149. package/dist/infrastructure/workspace/productManifestWriter.js.map +1 -0
  150. package/dist/middleware/auth.d.ts +39 -0
  151. package/dist/middleware/auth.d.ts.map +1 -0
  152. package/dist/middleware/auth.js +87 -0
  153. package/dist/middleware/auth.js.map +1 -0
  154. package/dist/middleware/cors.d.ts.map +1 -1
  155. package/dist/middleware/cors.js +5 -2
  156. package/dist/middleware/cors.js.map +1 -1
  157. package/dist/middleware/error.d.ts.map +1 -1
  158. package/dist/middleware/error.js +15 -13
  159. package/dist/middleware/error.js.map +1 -1
  160. package/dist/middleware/workspaceAccess.d.ts +51 -0
  161. package/dist/middleware/workspaceAccess.d.ts.map +1 -0
  162. package/dist/middleware/workspaceAccess.js +91 -0
  163. package/dist/middleware/workspaceAccess.js.map +1 -0
  164. package/dist/policy/CapabilityCheck.d.ts +14 -0
  165. package/dist/policy/CapabilityCheck.d.ts.map +1 -0
  166. package/dist/policy/CapabilityCheck.js +2 -0
  167. package/dist/policy/CapabilityCheck.js.map +1 -0
  168. package/dist/policy/PermissionRegistry.d.ts +25 -0
  169. package/dist/policy/PermissionRegistry.d.ts.map +1 -0
  170. package/dist/policy/PermissionRegistry.js +29 -0
  171. package/dist/policy/PermissionRegistry.js.map +1 -0
  172. package/dist/policy/ViewerContext.d.ts +29 -0
  173. package/dist/policy/ViewerContext.d.ts.map +1 -0
  174. package/dist/policy/ViewerContext.js +2 -0
  175. package/dist/policy/ViewerContext.js.map +1 -0
  176. package/dist/policy/checks.d.ts +15 -0
  177. package/dist/policy/checks.d.ts.map +1 -0
  178. package/dist/policy/checks.js +55 -0
  179. package/dist/policy/checks.js.map +1 -0
  180. package/dist/policy/defaultRegistry.d.ts +9 -0
  181. package/dist/policy/defaultRegistry.d.ts.map +1 -0
  182. package/dist/policy/defaultRegistry.js +15 -0
  183. package/dist/policy/defaultRegistry.js.map +1 -0
  184. package/dist/policy/index.d.ts +8 -0
  185. package/dist/policy/index.d.ts.map +1 -0
  186. package/dist/policy/index.js +5 -0
  187. package/dist/policy/index.js.map +1 -0
  188. package/dist/policy/resolveViewer.d.ts +16 -0
  189. package/dist/policy/resolveViewer.d.ts.map +1 -0
  190. package/dist/policy/resolveViewer.js +37 -0
  191. package/dist/policy/resolveViewer.js.map +1 -0
  192. package/dist/routes/_shared.d.ts +138 -0
  193. package/dist/routes/_shared.d.ts.map +1 -0
  194. package/dist/routes/_shared.js +33 -0
  195. package/dist/routes/_shared.js.map +1 -0
  196. package/dist/routes/admin.d.ts +13 -0
  197. package/dist/routes/admin.d.ts.map +1 -0
  198. package/dist/routes/admin.js +228 -0
  199. package/dist/routes/admin.js.map +1 -0
  200. package/dist/routes/auth.d.ts +35 -0
  201. package/dist/routes/auth.d.ts.map +1 -0
  202. package/dist/routes/auth.js +168 -0
  203. package/dist/routes/auth.js.map +1 -0
  204. package/dist/routes/batch.d.ts +7 -0
  205. package/dist/routes/batch.d.ts.map +1 -0
  206. package/dist/routes/batch.js +47 -0
  207. package/dist/routes/batch.js.map +1 -0
  208. package/dist/routes/clarifications.d.ts +8 -0
  209. package/dist/routes/clarifications.d.ts.map +1 -0
  210. package/dist/routes/clarifications.js +243 -0
  211. package/dist/routes/clarifications.js.map +1 -0
  212. package/dist/routes/edges.d.ts +2 -2
  213. package/dist/routes/edges.d.ts.map +1 -1
  214. package/dist/routes/edges.js +34 -16
  215. package/dist/routes/edges.js.map +1 -1
  216. package/dist/routes/health.d.ts +2 -2
  217. package/dist/routes/health.d.ts.map +1 -1
  218. package/dist/routes/health.js +21 -3
  219. package/dist/routes/health.js.map +1 -1
  220. package/dist/routes/history.d.ts +7 -0
  221. package/dist/routes/history.d.ts.map +1 -0
  222. package/dist/routes/history.js +90 -0
  223. package/dist/routes/history.js.map +1 -0
  224. package/dist/routes/model.d.ts +2 -2
  225. package/dist/routes/model.d.ts.map +1 -1
  226. package/dist/routes/model.js +20 -4
  227. package/dist/routes/model.js.map +1 -1
  228. package/dist/routes/nodes.d.ts +2 -2
  229. package/dist/routes/nodes.d.ts.map +1 -1
  230. package/dist/routes/nodes.js +77 -25
  231. package/dist/routes/nodes.js.map +1 -1
  232. package/dist/routes/oauth.d.ts +6 -7
  233. package/dist/routes/oauth.d.ts.map +1 -1
  234. package/dist/routes/oauth.js +6 -7
  235. package/dist/routes/oauth.js.map +1 -1
  236. package/dist/routes/ontology.d.ts +2 -2
  237. package/dist/routes/ontology.d.ts.map +1 -1
  238. package/dist/routes/ontology.js +22 -5
  239. package/dist/routes/ontology.js.map +1 -1
  240. package/dist/routes/proposals.d.ts +5 -4
  241. package/dist/routes/proposals.d.ts.map +1 -1
  242. package/dist/routes/proposals.js +176 -45
  243. package/dist/routes/proposals.js.map +1 -1
  244. package/dist/routes/reactorCycles.d.ts +7 -0
  245. package/dist/routes/reactorCycles.d.ts.map +1 -0
  246. package/dist/routes/reactorCycles.js +60 -0
  247. package/dist/routes/reactorCycles.js.map +1 -0
  248. package/dist/routes/runs.d.ts.map +1 -1
  249. package/dist/routes/runs.js +66 -12
  250. package/dist/routes/runs.js.map +1 -1
  251. package/dist/routes/skillInputOptions.d.ts +10 -0
  252. package/dist/routes/skillInputOptions.d.ts.map +1 -0
  253. package/dist/routes/skillInputOptions.js +159 -0
  254. package/dist/routes/skillInputOptions.js.map +1 -0
  255. package/dist/routes/skills.d.ts +21 -3
  256. package/dist/routes/skills.d.ts.map +1 -1
  257. package/dist/routes/skills.js +223 -21
  258. package/dist/routes/skills.js.map +1 -1
  259. package/dist/routes/sourceLoaders.d.ts +7 -0
  260. package/dist/routes/sourceLoaders.d.ts.map +1 -0
  261. package/dist/routes/sourceLoaders.js +30 -0
  262. package/dist/routes/sourceLoaders.js.map +1 -0
  263. package/dist/routes/sourceUnitObservations.d.ts +20 -0
  264. package/dist/routes/sourceUnitObservations.d.ts.map +1 -0
  265. package/dist/routes/sourceUnitObservations.js +80 -0
  266. package/dist/routes/sourceUnitObservations.js.map +1 -0
  267. package/dist/routes/sourceWebhooks.d.ts +26 -0
  268. package/dist/routes/sourceWebhooks.d.ts.map +1 -0
  269. package/dist/routes/sourceWebhooks.js +301 -0
  270. package/dist/routes/sourceWebhooks.js.map +1 -0
  271. package/dist/routes/users.d.ts +7 -0
  272. package/dist/routes/users.d.ts.map +1 -0
  273. package/dist/routes/users.js +109 -0
  274. package/dist/routes/users.js.map +1 -0
  275. package/dist/routes/workspaceEvents.d.ts +5 -4
  276. package/dist/routes/workspaceEvents.d.ts.map +1 -1
  277. package/dist/routes/workspaceEvents.js +7 -6
  278. package/dist/routes/workspaceEvents.js.map +1 -1
  279. package/dist/routes/workspaceMembers.d.ts +11 -0
  280. package/dist/routes/workspaceMembers.d.ts.map +1 -0
  281. package/dist/routes/workspaceMembers.js +81 -0
  282. package/dist/routes/workspaceMembers.js.map +1 -0
  283. package/dist/routes/workspaces.d.ts +30 -1
  284. package/dist/routes/workspaces.d.ts.map +1 -1
  285. package/dist/routes/workspaces.js +207 -63
  286. package/dist/routes/workspaces.js.map +1 -1
  287. package/dist/server.js +9 -29
  288. package/dist/server.js.map +1 -1
  289. package/dist/startServer.d.ts +17 -0
  290. package/dist/startServer.d.ts.map +1 -0
  291. package/dist/startServer.js +81 -0
  292. package/dist/startServer.js.map +1 -0
  293. package/dist/startup.d.ts +28 -0
  294. package/dist/startup.d.ts.map +1 -0
  295. package/dist/startup.js +94 -0
  296. package/dist/startup.js.map +1 -0
  297. package/package.json +49 -32
  298. package/LICENSE +0 -21
  299. package/dist/composeFs.d.ts +0 -20
  300. package/dist/composeFs.d.ts.map +0 -1
  301. package/dist/composeFs.js +0 -134
  302. package/dist/composeFs.js.map +0 -1
  303. package/dist/composition.d.ts +0 -49
  304. package/dist/composition.d.ts.map +0 -1
  305. package/dist/composition.js +0 -43
  306. package/dist/composition.js.map +0 -1
  307. package/dist/infrastructure/agent/ClaudeCodeAgentBinding.d.ts +0 -8
  308. package/dist/infrastructure/agent/ClaudeCodeAgentBinding.d.ts.map +0 -1
  309. package/dist/infrastructure/agent/ClaudeCodeAgentBinding.js +0 -62
  310. package/dist/infrastructure/agent/ClaudeCodeAgentBinding.js.map +0 -1
  311. package/dist/infrastructure/agent/SubprocessSkillRunner.d.ts.map +0 -1
  312. package/dist/infrastructure/agent/SubprocessSkillRunner.js.map +0 -1
  313. package/dist/infrastructure/agent/asyncQueue.d.ts +0 -22
  314. package/dist/infrastructure/agent/asyncQueue.d.ts.map +0 -1
  315. package/dist/infrastructure/agent/mcpConfig.d.ts +0 -18
  316. package/dist/infrastructure/agent/mcpConfig.d.ts.map +0 -1
  317. package/dist/infrastructure/agent/mcpConfig.js +0 -47
  318. package/dist/infrastructure/agent/mcpConfig.js.map +0 -1
  319. package/dist/infrastructure/agent/streamJsonParser.d.ts +0 -20
  320. package/dist/infrastructure/agent/streamJsonParser.d.ts.map +0 -1
  321. package/dist/infrastructure/agent/streamJsonParser.js.map +0 -1
  322. package/dist/infrastructure/agent/subprocessEventStream.d.ts +0 -26
  323. package/dist/infrastructure/agent/subprocessEventStream.d.ts.map +0 -1
  324. package/dist/infrastructure/agent/subprocessEventStream.js +0 -112
  325. package/dist/infrastructure/agent/subprocessEventStream.js.map +0 -1
  326. package/dist/infrastructure/fs/FsClarifyTicketRepository.d.ts +0 -13
  327. package/dist/infrastructure/fs/FsClarifyTicketRepository.d.ts.map +0 -1
  328. package/dist/infrastructure/fs/FsClarifyTicketRepository.js +0 -33
  329. package/dist/infrastructure/fs/FsClarifyTicketRepository.js.map +0 -1
  330. package/dist/infrastructure/fs/FsDecisionRepository.d.ts +0 -13
  331. package/dist/infrastructure/fs/FsDecisionRepository.d.ts.map +0 -1
  332. package/dist/infrastructure/fs/FsDecisionRepository.js +0 -56
  333. package/dist/infrastructure/fs/FsDecisionRepository.js.map +0 -1
  334. package/dist/infrastructure/fs/FsProposalRepository.d.ts.map +0 -1
  335. package/dist/infrastructure/fs/FsProposalRepository.js.map +0 -1
  336. package/dist/infrastructure/fs/FsRunRepository.d.ts.map +0 -1
  337. package/dist/infrastructure/fs/FsRunRepository.js +0 -88
  338. package/dist/infrastructure/fs/FsRunRepository.js.map +0 -1
  339. package/dist/infrastructure/fs/FsSkillRegistry.d.ts.map +0 -1
  340. package/dist/infrastructure/fs/FsSkillRegistry.js.map +0 -1
  341. package/dist/infrastructure/fs/FsStatusedJsonRepository.d.ts +0 -35
  342. package/dist/infrastructure/fs/FsStatusedJsonRepository.d.ts.map +0 -1
  343. package/dist/infrastructure/fs/FsStatusedJsonRepository.js.map +0 -1
  344. package/dist/infrastructure/fs/FsWorkspaceRepository.d.ts.map +0 -1
  345. package/dist/infrastructure/fs/FsWorkspaceRepository.js.map +0 -1
  346. package/dist/infrastructure/fs/WorkspaceRegistryFile.d.ts +0 -17
  347. package/dist/infrastructure/fs/WorkspaceRegistryFile.d.ts.map +0 -1
  348. package/dist/infrastructure/fs/WorkspaceRegistryFile.js +0 -58
  349. package/dist/infrastructure/fs/WorkspaceRegistryFile.js.map +0 -1
  350. package/dist/infrastructure/fs/frontmatter.d.ts +0 -13
  351. package/dist/infrastructure/fs/frontmatter.d.ts.map +0 -1
  352. package/dist/infrastructure/fs/frontmatter.js.map +0 -1
  353. package/dist/infrastructure/fs/jsonFileStore.d.ts.map +0 -1
  354. package/dist/infrastructure/fs/jsonFileStore.js.map +0 -1
  355. package/dist/infrastructure/fs/paths.d.ts +0 -22
  356. package/dist/infrastructure/fs/paths.d.ts.map +0 -1
  357. package/dist/infrastructure/fs/paths.js +0 -46
  358. package/dist/infrastructure/fs/paths.js.map +0 -1
  359. package/dist/infrastructure/fs/productManifestWriter.d.ts +0 -22
  360. package/dist/infrastructure/fs/productManifestWriter.d.ts.map +0 -1
  361. package/dist/infrastructure/fs/productManifestWriter.js.map +0 -1
  362. package/dist/infrastructure/orphanReaper.d.ts +0 -18
  363. package/dist/infrastructure/orphanReaper.d.ts.map +0 -1
  364. package/dist/infrastructure/orphanReaper.js.map +0 -1
  365. package/dist/routes/clarify.d.ts +0 -8
  366. package/dist/routes/clarify.d.ts.map +0 -1
  367. package/dist/routes/clarify.js +0 -84
  368. package/dist/routes/clarify.js.map +0 -1
  369. package/dist/routes/decisions.d.ts +0 -7
  370. package/dist/routes/decisions.d.ts.map +0 -1
  371. package/dist/routes/decisions.js +0 -30
  372. package/dist/routes/decisions.js.map +0 -1
  373. /package/dist/infrastructure/{fs → _shared}/jsonFileStore.d.ts +0 -0
  374. /package/dist/infrastructure/{fs → _shared}/jsonFileStore.js +0 -0
  375. /package/dist/infrastructure/{fs → hitl}/FsProposalRepository.d.ts +0 -0
  376. /package/dist/infrastructure/{fs → workspace}/FsWorkspaceRepository.d.ts +0 -0
@@ -0,0 +1,228 @@
1
+ import { NotFoundError } from '@braidhq/core';
2
+ import { ServerRole, User, UserId, WorkspaceId, WorkspaceRole } from '@braidhq/schema';
3
+ import { createRoute, OpenAPIHono, z } from '@hono/zod-openapi';
4
+ import { getUserId } from '../middleware/auth.js';
5
+ import { requireServerCapability } from '../middleware/workspaceAccess.js';
6
+ import { NotFoundResponse, ValidationFailureResponse } from './_shared.js';
7
+ const Invite = z.object({
8
+ email: z.string().email(),
9
+ invitedAt: z.string().datetime({ offset: true }),
10
+ serverRole: ServerRole,
11
+ }).openapi('Invite');
12
+ const InviteListResponse = z.object({
13
+ items: z.array(Invite),
14
+ }).openapi('InviteListResponse');
15
+ const InviteDraft = z.object({
16
+ email: z.string().email(),
17
+ serverRole: ServerRole.optional(),
18
+ }).openapi('InviteDraft');
19
+ const EmailParam = z.object({
20
+ email: z.string().email().openapi({ param: { name: 'email', in: 'path' } }),
21
+ });
22
+ const UserIdParam = z.object({
23
+ userId: UserId.openapi({ param: { name: 'userId', in: 'path' } }),
24
+ });
25
+ const AdminUserPatch = z.object({
26
+ serverRole: ServerRole,
27
+ }).openapi('AdminUserPatch');
28
+ const AdminUserWorkspace = z.object({
29
+ workspaceId: WorkspaceId,
30
+ role: WorkspaceRole,
31
+ }).openapi('AdminUserWorkspace');
32
+ const AdminUserView = User.extend({
33
+ workspaces: z.array(AdminUserWorkspace),
34
+ }).openapi('AdminUserView');
35
+ const UserListResponse = z.object({
36
+ items: z.array(AdminUserView),
37
+ }).openapi('AdminUserListResponse');
38
+ const listInvitesRoute = createRoute({
39
+ method: 'get',
40
+ path: '/invites',
41
+ operationId: 'listInvites',
42
+ summary: 'List pending invites. Admin only.',
43
+ tags: ['admin'],
44
+ responses: {
45
+ 200: {
46
+ description: 'A list of invites.',
47
+ content: { 'application/json': { schema: InviteListResponse } },
48
+ },
49
+ 403: {
50
+ description: 'Caller is not an admin.',
51
+ content: { 'application/problem+json': { schema: z.object({}).passthrough() } },
52
+ },
53
+ },
54
+ });
55
+ const addInviteRoute = createRoute({
56
+ method: 'post',
57
+ path: '/invites',
58
+ operationId: 'addInvite',
59
+ summary: 'Invite an email to sign in via Google OAuth. Admin only.',
60
+ tags: ['admin'],
61
+ request: { body: { content: { 'application/json': { schema: InviteDraft } } } },
62
+ responses: {
63
+ 201: {
64
+ description: 'The created invite.',
65
+ content: { 'application/json': { schema: Invite } },
66
+ },
67
+ 400: ValidationFailureResponse,
68
+ 403: {
69
+ description: 'Caller is not an admin.',
70
+ content: { 'application/problem+json': { schema: z.object({}).passthrough() } },
71
+ },
72
+ },
73
+ });
74
+ const revokeInviteRoute = createRoute({
75
+ method: 'delete',
76
+ path: '/invites/{email}',
77
+ operationId: 'revokeInvite',
78
+ summary: 'Revoke a pending invite. Admin only. Idempotent.',
79
+ tags: ['admin'],
80
+ request: { params: EmailParam },
81
+ responses: {
82
+ 204: { description: 'Invite removed (or never existed).' },
83
+ 403: {
84
+ description: 'Caller is not an admin.',
85
+ content: { 'application/problem+json': { schema: z.object({}).passthrough() } },
86
+ },
87
+ },
88
+ });
89
+ const listUsersRoute = createRoute({
90
+ method: 'get',
91
+ path: '/users',
92
+ operationId: 'listUsersAdmin',
93
+ summary: 'List all users on this server. Admin only.',
94
+ tags: ['admin'],
95
+ responses: {
96
+ 200: {
97
+ description: 'A list of users.',
98
+ content: { 'application/json': { schema: UserListResponse } },
99
+ },
100
+ 403: {
101
+ description: 'Caller is not an admin.',
102
+ content: { 'application/problem+json': { schema: z.object({}).passthrough() } },
103
+ },
104
+ },
105
+ });
106
+ const updateUserRoute = createRoute({
107
+ method: 'patch',
108
+ path: '/users/{userId}',
109
+ operationId: 'updateUserAdmin',
110
+ summary: 'Flip a user\'s server role. Admin only.',
111
+ tags: ['admin'],
112
+ request: {
113
+ params: UserIdParam,
114
+ body: { content: { 'application/json': { schema: AdminUserPatch } } },
115
+ },
116
+ responses: {
117
+ 200: {
118
+ description: 'The updated user.',
119
+ content: { 'application/json': { schema: User } },
120
+ },
121
+ 404: NotFoundResponse,
122
+ 403: {
123
+ description: 'Caller is not an admin.',
124
+ content: { 'application/problem+json': { schema: z.object({}).passthrough() } },
125
+ },
126
+ },
127
+ });
128
+ const deleteUserRoute = createRoute({
129
+ method: 'delete',
130
+ path: '/users/{userId}',
131
+ operationId: 'deleteUserAdmin',
132
+ summary: 'Delete a user record. Admin only. Idempotent. Does NOT clean up workspace memberships referencing this userId. Those rows become orphans.',
133
+ tags: ['admin'],
134
+ request: { params: UserIdParam },
135
+ responses: {
136
+ 204: { description: 'User removed (or never existed).' },
137
+ 400: {
138
+ description: 'Caller attempted to delete themselves.',
139
+ content: { 'application/problem+json': { schema: z.object({}).passthrough() } },
140
+ },
141
+ 403: {
142
+ description: 'Caller is not an admin.',
143
+ content: { 'application/problem+json': { schema: z.object({}).passthrough() } },
144
+ },
145
+ },
146
+ });
147
+ export function createAdminRouter(deps) {
148
+ const router = new OpenAPIHono();
149
+ router.use('*', requireServerCapability('server.admin', deps.userRegistry));
150
+ router.openapi(listInvitesRoute, async (context) => {
151
+ const items = await deps.accessPolicy.listInvites();
152
+ return context.json({ items }, 200);
153
+ });
154
+ router.openapi(addInviteRoute, async (context) => {
155
+ const draft = context.req.valid('json');
156
+ const created = await deps.accessPolicy.addInvite({
157
+ email: draft.email,
158
+ ...(draft.serverRole ? { serverRole: draft.serverRole } : {}),
159
+ });
160
+ return context.json(created, 201);
161
+ });
162
+ router.openapi(revokeInviteRoute, async (context) => {
163
+ const { email } = context.req.valid('param');
164
+ await deps.accessPolicy.removeInvite(email);
165
+ return context.body(null, 204);
166
+ });
167
+ router.openapi(listUsersRoute, async (context) => {
168
+ const [users, workspaces, entries] = await Promise.all([
169
+ deps.userRegistry.list(),
170
+ deps.workspaceService.list(),
171
+ deps.workspaceRegistry.listAllWithMembers(),
172
+ ]);
173
+ // Map rootPath to workspaceId so each membership carries a human id,
174
+ // without exposing rootPath to the client.
175
+ const idByRoot = new Map(workspaces.map(w => [w.rootPath, w.id]));
176
+ const membershipByUser = new Map();
177
+ for (const entry of entries) {
178
+ const workspaceId = idByRoot.get(entry.rootPath);
179
+ if (!workspaceId)
180
+ continue;
181
+ for (const member of entry.members) {
182
+ const list = membershipByUser.get(member.userId) ?? [];
183
+ list.push({ workspaceId, role: member.role });
184
+ membershipByUser.set(member.userId, list);
185
+ }
186
+ }
187
+ const items = users.map(u => ({
188
+ ...u,
189
+ workspaces: membershipByUser.get(u.id) ?? [],
190
+ }));
191
+ return context.json({ items }, 200);
192
+ });
193
+ router.openapi(updateUserRoute, async (context) => {
194
+ const { userId } = context.req.valid('param');
195
+ const patch = context.req.valid('json');
196
+ const existing = await deps.userRegistry.get(userId);
197
+ if (!existing)
198
+ throw new NotFoundError(`User "${userId}" not found`);
199
+ const updated = await deps.userRegistry.update(userId, { serverRole: patch.serverRole });
200
+ return context.json(updated, 200);
201
+ });
202
+ router.openapi(deleteUserRoute, async (context) => {
203
+ const { userId } = context.req.valid('param');
204
+ const callerId = getUserId(context);
205
+ // Don't let an admin delete themselves,
206
+ // a single-admin server would lock itself out otherwise.
207
+ if (userId === callerId) {
208
+ return context.json({
209
+ type: 'about:blank',
210
+ title: 'Bad Request',
211
+ status: 400,
212
+ detail: 'You cannot delete your own user record.',
213
+ }, 400, { 'Content-Type': 'application/problem+json' });
214
+ }
215
+ // Revoke persistent sign-in approval alongside the user record,
216
+ // so the same email can't sneak back in at the next /auth/google,
217
+ // without a fresh invite from an admin.
218
+ // Read the user first to grab their email,
219
+ // tolerated when missing for idempotency.
220
+ const existing = await deps.userRegistry.get(userId);
221
+ if (existing?.email)
222
+ await deps.accessPolicy.revokeApproval(existing.email);
223
+ await deps.userRegistry.delete(userId);
224
+ return context.body(null, 204);
225
+ });
226
+ return router;
227
+ }
228
+ //# sourceMappingURL=admin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin.js","sourceRoot":"","sources":["../../src/routes/admin.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACtF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAE1E,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE;IACzB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAChD,UAAU,EAAE,UAAU;CACvB,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;AAEpB,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;CACvB,CAAC,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;AAEhC,MAAM,WAAW,GAAG,CAAC,CAAC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IAAI,QAAQ,EAAE,KAAK;YACjB,MAAM,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QACxD,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QACtC,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAChC,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { Clock } from '@braidhq/core';
2
+ import type { AccessPolicy } from '../infrastructure/auth/AccessPolicy.js';
3
+ import type { SessionStore } from '../infrastructure/auth/SessionStore.js';
4
+ import type { GoogleOAuth } from '../infrastructure/oauth/GoogleOAuth.js';
5
+ import type { UserRegistryFile } from '../infrastructure/users/UserRegistryFile.js';
6
+ import { Hono } from 'hono';
7
+ export interface AuthRouterDeps {
8
+ clock: Clock;
9
+ sessionStore: SessionStore;
10
+ accessPolicy: AccessPolicy;
11
+ userRegistry: UserRegistryFile;
12
+ /**
13
+ * When undefined, `/auth/google/*` respond with 503,
14
+ * so the operator knows the server is missing OAuth env config,
15
+ * rather than failing silently mid-flow.
16
+ */
17
+ googleOAuth?: GoogleOAuth;
18
+ /**
19
+ * Where the Studio bundle is served from.
20
+ * Login redirects land here, with `#token=...` in the fragment.
21
+ * Studio reads, stores, navigates.
22
+ * Defaults to the Vite dev server origin when unset.
23
+ */
24
+ studioUrl: string;
25
+ /**
26
+ * Whether a caller must authenticate.
27
+ * Mirrored into `/auth/config.requiresAuth`,
28
+ * telling the Studio whether to gate behind the Login page.
29
+ * When false, anonymous sessions fall through, fine for a sidecar or dev.
30
+ * When true, the Login page is mandatory.
31
+ */
32
+ requiresAuth: boolean;
33
+ }
34
+ export declare function createAuthRouter(deps: AuthRouterDeps): Hono;
35
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/routes/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAG1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAA;AAEnF,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAY3B,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,KAAK,CAAA;IACZ,YAAY,EAAE,YAAY,CAAA;IAC1B,YAAY,EAAE,YAAY,CAAA;IAC1B,YAAY,EAAE,gBAAgB,CAAA;IAC9B;;;;OAIG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB;;;;;OAKG;IACH,SAAS,EAAE,MAAM,CAAA;IACjB;;;;;;OAMG;IACH,YAAY,EAAE,OAAO,CAAA;CACtB;AAaD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAuJ3D"}
@@ -0,0 +1,168 @@
1
+ import { newUserId, NotFoundError, ServiceUnavailableError, ValidationError } from '@braidhq/core';
2
+ import { Hono } from 'hono';
3
+ import { z } from 'zod';
4
+ import { createOAuthState, createPkceVerifier } from '../infrastructure/oauth/GoogleOAuth.js';
5
+ const PENDING_TTL_MS = 10 * 60 * 1000;
6
+ const StartQuery = z.object({
7
+ returnTo: z.string().url().optional(),
8
+ });
9
+ const CallbackQuery = z.object({
10
+ code: z.string().min(1).optional(),
11
+ state: z.string().min(1).optional(),
12
+ error: z.string().optional(),
13
+ error_description: z.string().optional(),
14
+ });
15
+ export function createAuthRouter(deps) {
16
+ const router = new Hono();
17
+ // In-memory pending flows.
18
+ // A single-process server is the only supported topology in v0.2.
19
+ // HA or multi-process would need a shared store,
20
+ // but that's well past current scope.
21
+ const pending = new Map();
22
+ function reapExpired() {
23
+ const cutoff = Date.now() - PENDING_TTL_MS;
24
+ for (const [state, flow] of pending) {
25
+ if (flow.createdAt < cutoff)
26
+ pending.delete(state);
27
+ }
28
+ }
29
+ router.get('/google/start', async (context) => {
30
+ if (!deps.googleOAuth)
31
+ throw new ServiceUnavailableError('Server is missing BRAID_GOOGLE_CLIENT_ID / BRAID_GOOGLE_CLIENT_SECRET. Ask the admin to configure them.');
32
+ reapExpired();
33
+ const parsed = StartQuery.safeParse({
34
+ returnTo: context.req.query('returnTo'),
35
+ });
36
+ if (!parsed.success)
37
+ throw new ValidationError('Invalid returnTo query parameter.');
38
+ const state = createOAuthState();
39
+ const codeVerifier = createPkceVerifier();
40
+ pending.set(state, {
41
+ codeVerifier,
42
+ returnTo: parsed.data.returnTo ?? deps.studioUrl,
43
+ createdAt: Date.now(),
44
+ });
45
+ const url = deps.googleOAuth.buildLoginUrl({ state, codeVerifier });
46
+ return context.json({ authorizationUrl: url });
47
+ });
48
+ router.get('/google/callback', async (context) => {
49
+ if (!deps.googleOAuth)
50
+ throw new ServiceUnavailableError('Google sign-in is not configured on this server.');
51
+ const parsed = CallbackQuery.safeParse({
52
+ code: context.req.query('code'),
53
+ state: context.req.query('state'),
54
+ error: context.req.query('error'),
55
+ error_description: context.req.query('error_description'),
56
+ });
57
+ if (!parsed.success)
58
+ throw new ValidationError('Invalid callback parameters.');
59
+ const { code, state, error, error_description: errorDescription } = parsed.data;
60
+ if (error || !code || !state)
61
+ return redirectWithError(context, deps.studioUrl, error_description_or_default(error, errorDescription));
62
+ const flow = pending.get(state);
63
+ if (!flow)
64
+ return redirectWithError(context, deps.studioUrl, 'Session expired before sign-in completed. Try again.');
65
+ pending.delete(state);
66
+ let profile;
67
+ try {
68
+ profile = await deps.googleOAuth.loginWithCode({ code, codeVerifier: flow.codeVerifier });
69
+ }
70
+ catch (err) {
71
+ return redirectWithError(context, flow.returnTo, err instanceof Error ? err.message : String(err));
72
+ }
73
+ const decision = await deps.accessPolicy.decide(profile.email);
74
+ if (!decision.allow)
75
+ return redirectWithError(context, flow.returnTo, decision.reason ?? 'Not authorized.');
76
+ // Resolve or create the user record. Google `sub` survives an email change,
77
+ // so prefer it as the join key,
78
+ // falling back to email for invited users new to login.
79
+ const isAdmin = deps.accessPolicy.isAdmin(profile.email);
80
+ let user = await deps.userRegistry.getByGoogleSub(profile.sub);
81
+ if (!user) {
82
+ const inviteRole = decision.viaInvite?.serverRole;
83
+ user = await deps.userRegistry.create({
84
+ id: newUserId(),
85
+ googleSub: profile.sub,
86
+ email: profile.email,
87
+ displayName: profile.displayName,
88
+ serverRole: isAdmin ? 'admin' : inviteRole ?? 'user',
89
+ createdAt: deps.clock.now(),
90
+ });
91
+ if (decision.viaInvite)
92
+ await deps.accessPolicy.consumeInvite(profile.email);
93
+ }
94
+ else if (isAdmin && user.serverRole !== 'admin') {
95
+ // BRAID_ADMIN_EMAILS was edited after this user was created.
96
+ // Promote on next login, so re-deploying with a new admin list,
97
+ // never needs manual user-table surgery.
98
+ user = await deps.userRegistry.update(user.id, { serverRole: 'admin' });
99
+ }
100
+ const session = await deps.sessionStore.issue(user.id);
101
+ const target = `${flow.returnTo}#token=${encodeURIComponent(session.token)}`;
102
+ return context.redirect(target, 302);
103
+ });
104
+ router.post('/logout', async (context) => {
105
+ const header = context.req.header('Authorization');
106
+ const token = header?.startsWith('Bearer ') ? header.slice('Bearer '.length).trim() : null;
107
+ if (token)
108
+ await deps.sessionStore.revoke(token);
109
+ return context.body(null, 204);
110
+ });
111
+ router.get('/whoami', async (context) => {
112
+ // `/auth/*` is in the auth middleware's PUBLIC_PATH_PREFIXES,
113
+ // so the Bearer header isn't validated upstream.
114
+ // Whoami exists precisely to identify the caller,
115
+ // so resolve the Bearer token here directly,
116
+ // rather than trusting the auth middleware's local-user fallback.
117
+ // An absent or invalid token yields `{ user: null }`.
118
+ const header = context.req.header('Authorization');
119
+ const token = header?.startsWith('Bearer ') ? header.slice('Bearer '.length).trim() : null;
120
+ let userId;
121
+ if (token) {
122
+ const session = await deps.sessionStore.resolve(token);
123
+ userId = session?.userId;
124
+ }
125
+ // A deployment without enforced auth doesn't issue tokens,
126
+ // so fall back to the context userId, keeping /whoami working there.
127
+ // authMiddleware wouldn't have rejected the request anyway.
128
+ if (!userId && !deps.requiresAuth)
129
+ userId = context.get('userId');
130
+ if (!userId)
131
+ return context.json({ user: null });
132
+ try {
133
+ const user = await deps.userRegistry.get(userId);
134
+ return context.json({ user: user ?? null });
135
+ }
136
+ catch (err) {
137
+ if (err instanceof NotFoundError)
138
+ return context.json({ user: null });
139
+ throw err;
140
+ }
141
+ });
142
+ // Hint at the configured studio URL and auth mode,
143
+ // so the Login page can decide whether to gate at all,
144
+ // single-tenant skips it, and whether Google is configured,
145
+ // since otherwise the Sign-in button leads to a 503.
146
+ router.get('/config', (context) => {
147
+ return context.json({
148
+ googleEnabled: deps.googleOAuth !== undefined,
149
+ studioUrl: deps.studioUrl,
150
+ requiresAuth: deps.requiresAuth,
151
+ });
152
+ });
153
+ return router;
154
+ }
155
+ function redirectWithError(context, target, reason) {
156
+ // Use a clearly named hash key.
157
+ // The Studio side pulls the error out and shows it on the Login page.
158
+ const url = `${target}#auth-error=${encodeURIComponent(reason)}`;
159
+ return context.redirect(url, 302);
160
+ }
161
+ function error_description_or_default(error, description) {
162
+ if (description && description.length > 0)
163
+ return description;
164
+ if (error && error.length > 0)
165
+ return error;
166
+ return 'Google sign-in failed.';
167
+ }
168
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/routes/auth.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAClG,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAA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AO,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AACnC,CAAC;AAED,SAAS,4BAA4B,CAAC,KAAyB,EAAE,WAA+B;IAC9F,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;QACvC,OAAO,WAAW,CAAA;IACpB,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAC3B,OAAO,KAAK,CAAA;IACd,OAAO,wBAAwB,CAAA;AACjC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { BatchService } from '@braidhq/core';
2
+ import { Hono } from 'hono';
3
+ export interface BatchRouterDeps {
4
+ batchService: BatchService;
5
+ }
6
+ export declare function createBatchRouter(deps: BatchRouterDeps): Hono;
7
+ //# sourceMappingURL=batch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../src/routes/batch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAGjD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAS3B,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,YAAY,CAAA;CAC3B;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CA0C7D"}
@@ -0,0 +1,47 @@
1
+ import { NotFoundError } from '@braidhq/core';
2
+ import { zValidator } from '@hono/zod-validator';
3
+ import { Hono } from 'hono';
4
+ import { z } from 'zod';
5
+ import { extractBearerToken } from '../middleware/auth.js';
6
+ import { getWorkspaceId } from '../middleware/workspaceId.js';
7
+ const StartBody = z.object({
8
+ autoApply: z.boolean(),
9
+ });
10
+ export function createBatchRouter(deps) {
11
+ const router = new Hono();
12
+ router.post('/', zValidator('json', StartBody), async (context) => {
13
+ const workspaceId = getWorkspaceId(context);
14
+ const { autoApply } = context.req.valid('json');
15
+ const callerToken = extractBearerToken(context);
16
+ const plan = await deps.batchService.start(workspaceId, {
17
+ autoApply,
18
+ ...(callerToken ? { callerToken } : {}),
19
+ });
20
+ return context.json(plan.toData(), 202);
21
+ });
22
+ router.get('/', async (context) => {
23
+ const workspaceId = getWorkspaceId(context);
24
+ const plan = await deps.batchService.getStatus(workspaceId);
25
+ if (!plan)
26
+ throw new NotFoundError(`No batch plan for workspace ${workspaceId}`);
27
+ return context.json(plan.toData());
28
+ });
29
+ router.post('/stop', async (context) => {
30
+ const workspaceId = getWorkspaceId(context);
31
+ await deps.batchService.stop(workspaceId);
32
+ return context.body(null, 204);
33
+ });
34
+ router.post('/resume', async (context) => {
35
+ const workspaceId = getWorkspaceId(context);
36
+ const callerToken = extractBearerToken(context);
37
+ const plan = await deps.batchService.resume(workspaceId, callerToken ? { callerToken } : {});
38
+ return context.json(plan.toData(), 202);
39
+ });
40
+ router.post('/archive', async (context) => {
41
+ const workspaceId = getWorkspaceId(context);
42
+ const plan = await deps.batchService.archive(workspaceId);
43
+ return context.json(plan.toData());
44
+ });
45
+ return router;
46
+ }
47
+ //# sourceMappingURL=batch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batch.js","sourceRoot":"","sources":["../../src/routes/batch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAE7D,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IACzB,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE;CACvB,CAAC,CAAA;AAMF,MAAM,UAAU,iBAAiB,CAAC,IAAqB;IACrD,MAAM,MAAM,GAAG,IAAI,IAAI,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AAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;IAChC,CAAC,CAAC,CAAA;IAEF,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACvC,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;QAC3C,MAAM,WAAW,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;QAC/C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QAC5F,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,CAAC,CAAA;IACzC,CAAC,CAAC,CAAA;IAEF,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACxC,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;QAC3C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QACzD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ClarificationRepository, HITLService } from '@braidhq/core';
2
+ import { OpenAPIHono } from '@hono/zod-openapi';
3
+ export interface ClarificationRouterDeps {
4
+ hitlService: HITLService;
5
+ clarificationRepository: ClarificationRepository;
6
+ }
7
+ export declare function createClarificationRouter(deps: ClarificationRouterDeps): OpenAPIHono;
8
+ //# sourceMappingURL=clarifications.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clarifications.d.ts","sourceRoot":"","sources":["../../src/routes/clarifications.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAGzE,OAAO,EAAe,WAAW,EAAK,MAAM,mBAAmB,CAAA;AAiE/D,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,WAAW,CAAA;IACxB,uBAAuB,EAAE,uBAAuB,CAAA;CACjD;AAiHD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,uBAAuB,GAAG,WAAW,CAuFpF"}