@decionis/agentsafe 0.1.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 (436) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +909 -0
  4. package/dist/Cli.d.ts +3 -0
  5. package/dist/Cli.d.ts.map +1 -0
  6. package/dist/Cli.js +150 -0
  7. package/dist/Cli.js.map +1 -0
  8. package/dist/Index.d.ts +104 -0
  9. package/dist/Index.d.ts.map +1 -0
  10. package/dist/Index.js +102 -0
  11. package/dist/Index.js.map +1 -0
  12. package/dist/Serve.d.ts +26 -0
  13. package/dist/Serve.d.ts.map +1 -0
  14. package/dist/Serve.js +143 -0
  15. package/dist/Serve.js.map +1 -0
  16. package/dist/TrustedExecutor.d.ts +66 -0
  17. package/dist/TrustedExecutor.d.ts.map +1 -0
  18. package/dist/TrustedExecutor.js +170 -0
  19. package/dist/TrustedExecutor.js.map +1 -0
  20. package/dist/Version.d.ts +6 -0
  21. package/dist/Version.d.ts.map +1 -0
  22. package/dist/Version.js +21 -0
  23. package/dist/Version.js.map +1 -0
  24. package/dist/adapters/AdapterActionHandler.d.ts +48 -0
  25. package/dist/adapters/AdapterActionHandler.d.ts.map +1 -0
  26. package/dist/adapters/AdapterActionHandler.js +148 -0
  27. package/dist/adapters/AdapterActionHandler.js.map +1 -0
  28. package/dist/adapters/EffectAdapter.d.ts +96 -0
  29. package/dist/adapters/EffectAdapter.d.ts.map +1 -0
  30. package/dist/adapters/EffectAdapter.js +16 -0
  31. package/dist/adapters/EffectAdapter.js.map +1 -0
  32. package/dist/adapters/EffectAwareGrantVerifier.d.ts +30 -0
  33. package/dist/adapters/EffectAwareGrantVerifier.d.ts.map +1 -0
  34. package/dist/adapters/EffectAwareGrantVerifier.js +38 -0
  35. package/dist/adapters/EffectAwareGrantVerifier.js.map +1 -0
  36. package/dist/adapters/EffectComparison.d.ts +20 -0
  37. package/dist/adapters/EffectComparison.d.ts.map +1 -0
  38. package/dist/adapters/EffectComparison.js +48 -0
  39. package/dist/adapters/EffectComparison.js.map +1 -0
  40. package/dist/adapters/EffectEvidenceBuilder.d.ts +60 -0
  41. package/dist/adapters/EffectEvidenceBuilder.d.ts.map +1 -0
  42. package/dist/adapters/EffectEvidenceBuilder.js +127 -0
  43. package/dist/adapters/EffectEvidenceBuilder.js.map +1 -0
  44. package/dist/adapters/EffectEvidenceRegister.d.ts +31 -0
  45. package/dist/adapters/EffectEvidenceRegister.d.ts.map +1 -0
  46. package/dist/adapters/EffectEvidenceRegister.js +21 -0
  47. package/dist/adapters/EffectEvidenceRegister.js.map +1 -0
  48. package/dist/adapters/JcsDigest.d.ts +43 -0
  49. package/dist/adapters/JcsDigest.d.ts.map +1 -0
  50. package/dist/adapters/JcsDigest.js +86 -0
  51. package/dist/adapters/JcsDigest.js.map +1 -0
  52. package/dist/adapters/banking/BankingAction.d.ts +146 -0
  53. package/dist/adapters/banking/BankingAction.d.ts.map +1 -0
  54. package/dist/adapters/banking/BankingAction.js +102 -0
  55. package/dist/adapters/banking/BankingAction.js.map +1 -0
  56. package/dist/adapters/banking/BankingAdapter.d.ts +60 -0
  57. package/dist/adapters/banking/BankingAdapter.d.ts.map +1 -0
  58. package/dist/adapters/banking/BankingAdapter.js +107 -0
  59. package/dist/adapters/banking/BankingAdapter.js.map +1 -0
  60. package/dist/adapters/banking/BankingHandlers.d.ts +24 -0
  61. package/dist/adapters/banking/BankingHandlers.d.ts.map +1 -0
  62. package/dist/adapters/banking/BankingHandlers.js +47 -0
  63. package/dist/adapters/banking/BankingHandlers.js.map +1 -0
  64. package/dist/adapters/banking/BankingIntentBinder.d.ts +47 -0
  65. package/dist/adapters/banking/BankingIntentBinder.d.ts.map +1 -0
  66. package/dist/adapters/banking/BankingIntentBinder.js +64 -0
  67. package/dist/adapters/banking/BankingIntentBinder.js.map +1 -0
  68. package/dist/adapters/banking/CoreBankingHttpAdapter.d.ts +55 -0
  69. package/dist/adapters/banking/CoreBankingHttpAdapter.d.ts.map +1 -0
  70. package/dist/adapters/banking/CoreBankingHttpAdapter.js +248 -0
  71. package/dist/adapters/banking/CoreBankingHttpAdapter.js.map +1 -0
  72. package/dist/adapters/banking/Currency.d.ts +10 -0
  73. package/dist/adapters/banking/Currency.d.ts.map +1 -0
  74. package/dist/adapters/banking/Currency.js +91 -0
  75. package/dist/adapters/banking/Currency.js.map +1 -0
  76. package/dist/adapters/banking/EffectProjections.d.ts +52 -0
  77. package/dist/adapters/banking/EffectProjections.d.ts.map +1 -0
  78. package/dist/adapters/banking/EffectProjections.js +140 -0
  79. package/dist/adapters/banking/EffectProjections.js.map +1 -0
  80. package/dist/adapters/banking/Iban.d.ts +18 -0
  81. package/dist/adapters/banking/Iban.d.ts.map +1 -0
  82. package/dist/adapters/banking/Iban.js +38 -0
  83. package/dist/adapters/banking/Iban.js.map +1 -0
  84. package/dist/adapters/banking/Money.d.ts +32 -0
  85. package/dist/adapters/banking/Money.d.ts.map +1 -0
  86. package/dist/adapters/banking/Money.js +81 -0
  87. package/dist/adapters/banking/Money.js.map +1 -0
  88. package/dist/adapters/banking/ReasonCodes.d.ts +19 -0
  89. package/dist/adapters/banking/ReasonCodes.d.ts.map +1 -0
  90. package/dist/adapters/banking/ReasonCodes.js +35 -0
  91. package/dist/adapters/banking/ReasonCodes.js.map +1 -0
  92. package/dist/audit/ChainJournal.d.ts +38 -0
  93. package/dist/audit/ChainJournal.d.ts.map +1 -0
  94. package/dist/audit/ChainJournal.js +97 -0
  95. package/dist/audit/ChainJournal.js.map +1 -0
  96. package/dist/audit/HashChain.d.ts +39 -0
  97. package/dist/audit/HashChain.d.ts.map +1 -0
  98. package/dist/audit/HashChain.js +63 -0
  99. package/dist/audit/HashChain.js.map +1 -0
  100. package/dist/audit/HashChainedAuditSink.d.ts +22 -0
  101. package/dist/audit/HashChainedAuditSink.d.ts.map +1 -0
  102. package/dist/audit/HashChainedAuditSink.js +26 -0
  103. package/dist/audit/HashChainedAuditSink.js.map +1 -0
  104. package/dist/audit/LineAuditSink.d.ts +19 -0
  105. package/dist/audit/LineAuditSink.d.ts.map +1 -0
  106. package/dist/audit/LineAuditSink.js +35 -0
  107. package/dist/audit/LineAuditSink.js.map +1 -0
  108. package/dist/cli/Arguments.d.ts +26 -0
  109. package/dist/cli/Arguments.d.ts.map +1 -0
  110. package/dist/cli/Arguments.js +66 -0
  111. package/dist/cli/Arguments.js.map +1 -0
  112. package/dist/cli/CliProcess.d.ts +29 -0
  113. package/dist/cli/CliProcess.d.ts.map +1 -0
  114. package/dist/cli/CliProcess.js +78 -0
  115. package/dist/cli/CliProcess.js.map +1 -0
  116. package/dist/cli/Commands.d.ts +8 -0
  117. package/dist/cli/Commands.d.ts.map +1 -0
  118. package/dist/cli/Commands.js +67 -0
  119. package/dist/cli/Commands.js.map +1 -0
  120. package/dist/cli/ConfigCommand.d.ts +7 -0
  121. package/dist/cli/ConfigCommand.d.ts.map +1 -0
  122. package/dist/cli/ConfigCommand.js +77 -0
  123. package/dist/cli/ConfigCommand.js.map +1 -0
  124. package/dist/cli/ConfigFile.d.ts +21 -0
  125. package/dist/cli/ConfigFile.d.ts.map +1 -0
  126. package/dist/cli/ConfigFile.js +57 -0
  127. package/dist/cli/ConfigFile.js.map +1 -0
  128. package/dist/cli/Credentials.d.ts +15 -0
  129. package/dist/cli/Credentials.d.ts.map +1 -0
  130. package/dist/cli/Credentials.js +51 -0
  131. package/dist/cli/Credentials.js.map +1 -0
  132. package/dist/cli/Doctor.d.ts +25 -0
  133. package/dist/cli/Doctor.d.ts.map +1 -0
  134. package/dist/cli/Doctor.js +211 -0
  135. package/dist/cli/Doctor.js.map +1 -0
  136. package/dist/cli/Help.d.ts +3 -0
  137. package/dist/cli/Help.d.ts.map +1 -0
  138. package/dist/cli/Help.js +38 -0
  139. package/dist/cli/Help.js.map +1 -0
  140. package/dist/cli/Init.d.ts +32 -0
  141. package/dist/cli/Init.d.ts.map +1 -0
  142. package/dist/cli/Init.js +163 -0
  143. package/dist/cli/Init.js.map +1 -0
  144. package/dist/cli/Login.d.ts +16 -0
  145. package/dist/cli/Login.d.ts.map +1 -0
  146. package/dist/cli/Login.js +74 -0
  147. package/dist/cli/Login.js.map +1 -0
  148. package/dist/cli/Proxy.d.ts +41 -0
  149. package/dist/cli/Proxy.d.ts.map +1 -0
  150. package/dist/cli/Proxy.js +161 -0
  151. package/dist/cli/Proxy.js.map +1 -0
  152. package/dist/cli/Status.d.ts +7 -0
  153. package/dist/cli/Status.d.ts.map +1 -0
  154. package/dist/cli/Status.js +64 -0
  155. package/dist/cli/Status.js.map +1 -0
  156. package/dist/cli/TestCommand.d.ts +36 -0
  157. package/dist/cli/TestCommand.d.ts.map +1 -0
  158. package/dist/cli/TestCommand.js +173 -0
  159. package/dist/cli/TestCommand.js.map +1 -0
  160. package/dist/config/ConfigKeys.d.ts +10 -0
  161. package/dist/config/ConfigKeys.d.ts.map +1 -0
  162. package/dist/config/ConfigKeys.js +105 -0
  163. package/dist/config/ConfigKeys.js.map +1 -0
  164. package/dist/config/ExecutorConfig.d.ts +254 -0
  165. package/dist/config/ExecutorConfig.d.ts.map +1 -0
  166. package/dist/config/ExecutorConfig.js +637 -0
  167. package/dist/config/ExecutorConfig.js.map +1 -0
  168. package/dist/containment/ContainmentProbe.d.ts +87 -0
  169. package/dist/containment/ContainmentProbe.d.ts.map +1 -0
  170. package/dist/containment/ContainmentProbe.js +103 -0
  171. package/dist/containment/ContainmentProbe.js.map +1 -0
  172. package/dist/credential/CredentialError.d.ts +6 -0
  173. package/dist/credential/CredentialError.d.ts.map +1 -0
  174. package/dist/credential/CredentialError.js +10 -0
  175. package/dist/credential/CredentialError.js.map +1 -0
  176. package/dist/credential/DownstreamCredential.d.ts +38 -0
  177. package/dist/credential/DownstreamCredential.d.ts.map +1 -0
  178. package/dist/credential/DownstreamCredential.js +2 -0
  179. package/dist/credential/DownstreamCredential.js.map +1 -0
  180. package/dist/credential/GrantOf.d.ts +10 -0
  181. package/dist/credential/GrantOf.d.ts.map +1 -0
  182. package/dist/credential/GrantOf.js +16 -0
  183. package/dist/credential/GrantOf.js.map +1 -0
  184. package/dist/credential/PrivateKeyJwtCredential.d.ts +43 -0
  185. package/dist/credential/PrivateKeyJwtCredential.d.ts.map +1 -0
  186. package/dist/credential/PrivateKeyJwtCredential.js +126 -0
  187. package/dist/credential/PrivateKeyJwtCredential.js.map +1 -0
  188. package/dist/credential/SignedRequestCredential.d.ts +112 -0
  189. package/dist/credential/SignedRequestCredential.d.ts.map +1 -0
  190. package/dist/credential/SignedRequestCredential.js +255 -0
  191. package/dist/credential/SignedRequestCredential.js.map +1 -0
  192. package/dist/credential/StaticHeaderCredential.d.ts +16 -0
  193. package/dist/credential/StaticHeaderCredential.d.ts.map +1 -0
  194. package/dist/credential/StaticHeaderCredential.js +21 -0
  195. package/dist/credential/StaticHeaderCredential.js.map +1 -0
  196. package/dist/egress/EgressError.d.ts +13 -0
  197. package/dist/egress/EgressError.d.ts.map +1 -0
  198. package/dist/egress/EgressError.js +16 -0
  199. package/dist/egress/EgressError.js.map +1 -0
  200. package/dist/egress/EgressPolicy.d.ts +55 -0
  201. package/dist/egress/EgressPolicy.d.ts.map +1 -0
  202. package/dist/egress/EgressPolicy.js +137 -0
  203. package/dist/egress/EgressPolicy.js.map +1 -0
  204. package/dist/egress/GlobalFetchLock.d.ts +16 -0
  205. package/dist/egress/GlobalFetchLock.d.ts.map +1 -0
  206. package/dist/egress/GlobalFetchLock.js +34 -0
  207. package/dist/egress/GlobalFetchLock.js.map +1 -0
  208. package/dist/egress/GuardedFetch.d.ts +56 -0
  209. package/dist/egress/GuardedFetch.d.ts.map +1 -0
  210. package/dist/egress/GuardedFetch.js +300 -0
  211. package/dist/egress/GuardedFetch.js.map +1 -0
  212. package/dist/egress/TcpProbe.d.ts +35 -0
  213. package/dist/egress/TcpProbe.d.ts.map +1 -0
  214. package/dist/egress/TcpProbe.js +45 -0
  215. package/dist/egress/TcpProbe.js.map +1 -0
  216. package/dist/gateway/Activation.d.ts +39 -0
  217. package/dist/gateway/Activation.d.ts.map +1 -0
  218. package/dist/gateway/Activation.js +61 -0
  219. package/dist/gateway/Activation.js.map +1 -0
  220. package/dist/gateway/BoundaryTest.d.ts +92 -0
  221. package/dist/gateway/BoundaryTest.d.ts.map +1 -0
  222. package/dist/gateway/BoundaryTest.js +349 -0
  223. package/dist/gateway/BoundaryTest.js.map +1 -0
  224. package/dist/gateway/DemoAuthority.d.ts +41 -0
  225. package/dist/gateway/DemoAuthority.d.ts.map +1 -0
  226. package/dist/gateway/DemoAuthority.js +66 -0
  227. package/dist/gateway/DemoAuthority.js.map +1 -0
  228. package/dist/gateway/ForwardHandler.d.ts +56 -0
  229. package/dist/gateway/ForwardHandler.d.ts.map +1 -0
  230. package/dist/gateway/ForwardHandler.js +111 -0
  231. package/dist/gateway/ForwardHandler.js.map +1 -0
  232. package/dist/gateway/Gateway.d.ts +142 -0
  233. package/dist/gateway/Gateway.d.ts.map +1 -0
  234. package/dist/gateway/Gateway.js +819 -0
  235. package/dist/gateway/Gateway.js.map +1 -0
  236. package/dist/gateway/GatewayConfig.d.ts +237 -0
  237. package/dist/gateway/GatewayConfig.d.ts.map +1 -0
  238. package/dist/gateway/GatewayConfig.js +706 -0
  239. package/dist/gateway/GatewayConfig.js.map +1 -0
  240. package/dist/gateway/GatewayMetrics.d.ts +26 -0
  241. package/dist/gateway/GatewayMetrics.d.ts.map +1 -0
  242. package/dist/gateway/GatewayMetrics.js +28 -0
  243. package/dist/gateway/GatewayMetrics.js.map +1 -0
  244. package/dist/gateway/GatewayReport.d.ts +74 -0
  245. package/dist/gateway/GatewayReport.d.ts.map +1 -0
  246. package/dist/gateway/GatewayReport.js +109 -0
  247. package/dist/gateway/GatewayReport.js.map +1 -0
  248. package/dist/gateway/InterceptedRequest.d.ts +53 -0
  249. package/dist/gateway/InterceptedRequest.d.ts.map +1 -0
  250. package/dist/gateway/InterceptedRequest.js +80 -0
  251. package/dist/gateway/InterceptedRequest.js.map +1 -0
  252. package/dist/gateway/RouteTable.d.ts +28 -0
  253. package/dist/gateway/RouteTable.d.ts.map +1 -0
  254. package/dist/gateway/RouteTable.js +72 -0
  255. package/dist/gateway/RouteTable.js.map +1 -0
  256. package/dist/gateway/Upstream.d.ts +46 -0
  257. package/dist/gateway/Upstream.d.ts.map +1 -0
  258. package/dist/gateway/Upstream.js +158 -0
  259. package/dist/gateway/Upstream.js.map +1 -0
  260. package/dist/handlers/ForwardRequestHandler.d.ts +26 -0
  261. package/dist/handlers/ForwardRequestHandler.d.ts.map +1 -0
  262. package/dist/handlers/ForwardRequestHandler.js +98 -0
  263. package/dist/handlers/ForwardRequestHandler.js.map +1 -0
  264. package/dist/handlers/HandlerRegistration.d.ts +37 -0
  265. package/dist/handlers/HandlerRegistration.d.ts.map +1 -0
  266. package/dist/handlers/HandlerRegistration.js +2 -0
  267. package/dist/handlers/HandlerRegistration.js.map +1 -0
  268. package/dist/handlers/JournaledActionHandler.d.ts +31 -0
  269. package/dist/handlers/JournaledActionHandler.d.ts.map +1 -0
  270. package/dist/handlers/JournaledActionHandler.js +63 -0
  271. package/dist/handlers/JournaledActionHandler.js.map +1 -0
  272. package/dist/http/ExecutorHttpServer.d.ts +33 -0
  273. package/dist/http/ExecutorHttpServer.d.ts.map +1 -0
  274. package/dist/http/ExecutorHttpServer.js +176 -0
  275. package/dist/http/ExecutorHttpServer.js.map +1 -0
  276. package/dist/http/GatewayHttpServer.d.ts +42 -0
  277. package/dist/http/GatewayHttpServer.d.ts.map +1 -0
  278. package/dist/http/GatewayHttpServer.js +195 -0
  279. package/dist/http/GatewayHttpServer.js.map +1 -0
  280. package/dist/http/RecordingTarget.d.ts +18 -0
  281. package/dist/http/RecordingTarget.d.ts.map +1 -0
  282. package/dist/http/RecordingTarget.js +71 -0
  283. package/dist/http/RecordingTarget.js.map +1 -0
  284. package/dist/http/RequestContext.d.ts +17 -0
  285. package/dist/http/RequestContext.d.ts.map +1 -0
  286. package/dist/http/RequestContext.js +19 -0
  287. package/dist/http/RequestContext.js.map +1 -0
  288. package/dist/http/Routes.d.ts +93 -0
  289. package/dist/http/Routes.d.ts.map +1 -0
  290. package/dist/http/Routes.js +46 -0
  291. package/dist/http/Routes.js.map +1 -0
  292. package/dist/http/TlsListener.d.ts +38 -0
  293. package/dist/http/TlsListener.d.ts.map +1 -0
  294. package/dist/http/TlsListener.js +52 -0
  295. package/dist/http/TlsListener.js.map +1 -0
  296. package/dist/identity/Authenticator.d.ts +58 -0
  297. package/dist/identity/Authenticator.d.ts.map +1 -0
  298. package/dist/identity/Authenticator.js +170 -0
  299. package/dist/identity/Authenticator.js.map +1 -0
  300. package/dist/identity/PeerIdentity.d.ts +24 -0
  301. package/dist/identity/PeerIdentity.d.ts.map +1 -0
  302. package/dist/identity/PeerIdentity.js +29 -0
  303. package/dist/identity/PeerIdentity.js.map +1 -0
  304. package/dist/identity/PrincipalRegistry.d.ts +102 -0
  305. package/dist/identity/PrincipalRegistry.d.ts.map +1 -0
  306. package/dist/identity/PrincipalRegistry.js +191 -0
  307. package/dist/identity/PrincipalRegistry.js.map +1 -0
  308. package/dist/identity/PrincipalsFile.d.ts +152 -0
  309. package/dist/identity/PrincipalsFile.d.ts.map +1 -0
  310. package/dist/identity/PrincipalsFile.js +125 -0
  311. package/dist/identity/PrincipalsFile.js.map +1 -0
  312. package/dist/identity/RateLimiter.d.ts +43 -0
  313. package/dist/identity/RateLimiter.d.ts.map +1 -0
  314. package/dist/identity/RateLimiter.js +84 -0
  315. package/dist/identity/RateLimiter.js.map +1 -0
  316. package/dist/identity/SeparationOfDuties.d.ts +11 -0
  317. package/dist/identity/SeparationOfDuties.d.ts.map +1 -0
  318. package/dist/identity/SeparationOfDuties.js +25 -0
  319. package/dist/identity/SeparationOfDuties.js.map +1 -0
  320. package/dist/identity/WorkloadJwtVerifier.d.ts +57 -0
  321. package/dist/identity/WorkloadJwtVerifier.d.ts.map +1 -0
  322. package/dist/identity/WorkloadJwtVerifier.js +145 -0
  323. package/dist/identity/WorkloadJwtVerifier.js.map +1 -0
  324. package/dist/incident/EvidenceExport.d.ts +128 -0
  325. package/dist/incident/EvidenceExport.d.ts.map +1 -0
  326. package/dist/incident/EvidenceExport.js +187 -0
  327. package/dist/incident/EvidenceExport.js.map +1 -0
  328. package/dist/incident/FileProbe.d.ts +22 -0
  329. package/dist/incident/FileProbe.d.ts.map +1 -0
  330. package/dist/incident/FileProbe.js +31 -0
  331. package/dist/incident/FileProbe.js.map +1 -0
  332. package/dist/incident/HaltSwitch.d.ts +95 -0
  333. package/dist/incident/HaltSwitch.d.ts.map +1 -0
  334. package/dist/incident/HaltSwitch.js +171 -0
  335. package/dist/incident/HaltSwitch.js.map +1 -0
  336. package/dist/incident/Metrics.d.ts +71 -0
  337. package/dist/incident/Metrics.d.ts.map +1 -0
  338. package/dist/incident/Metrics.js +146 -0
  339. package/dist/incident/Metrics.js.map +1 -0
  340. package/dist/incident/SecurityEvents.d.ts +182 -0
  341. package/dist/incident/SecurityEvents.d.ts.map +1 -0
  342. package/dist/incident/SecurityEvents.js +167 -0
  343. package/dist/incident/SecurityEvents.js.map +1 -0
  344. package/dist/journal/ExecutionJournal.d.ts +96 -0
  345. package/dist/journal/ExecutionJournal.d.ts.map +1 -0
  346. package/dist/journal/ExecutionJournal.js +100 -0
  347. package/dist/journal/ExecutionJournal.js.map +1 -0
  348. package/dist/journal/FileExecutionJournal.d.ts +38 -0
  349. package/dist/journal/FileExecutionJournal.d.ts.map +1 -0
  350. package/dist/journal/FileExecutionJournal.js +137 -0
  351. package/dist/journal/FileExecutionJournal.js.map +1 -0
  352. package/dist/journal/InMemoryExecutionJournal.d.ts +23 -0
  353. package/dist/journal/InMemoryExecutionJournal.d.ts.map +1 -0
  354. package/dist/journal/InMemoryExecutionJournal.js +47 -0
  355. package/dist/journal/InMemoryExecutionJournal.js.map +1 -0
  356. package/dist/journal/StartupReconciler.d.ts +47 -0
  357. package/dist/journal/StartupReconciler.d.ts.map +1 -0
  358. package/dist/journal/StartupReconciler.js +89 -0
  359. package/dist/journal/StartupReconciler.js.map +1 -0
  360. package/dist/limits/HardLimits.d.ts +63 -0
  361. package/dist/limits/HardLimits.d.ts.map +1 -0
  362. package/dist/limits/HardLimits.js +120 -0
  363. package/dist/limits/HardLimits.js.map +1 -0
  364. package/dist/logging/LineEmitter.d.ts +26 -0
  365. package/dist/logging/LineEmitter.d.ts.map +1 -0
  366. package/dist/logging/LineEmitter.js +36 -0
  367. package/dist/logging/LineEmitter.js.map +1 -0
  368. package/dist/posture/HostPosture.d.ts +60 -0
  369. package/dist/posture/HostPosture.d.ts.map +1 -0
  370. package/dist/posture/HostPosture.js +104 -0
  371. package/dist/posture/HostPosture.js.map +1 -0
  372. package/dist/posture/PostureChecks.d.ts +52 -0
  373. package/dist/posture/PostureChecks.d.ts.map +1 -0
  374. package/dist/posture/PostureChecks.js +172 -0
  375. package/dist/posture/PostureChecks.js.map +1 -0
  376. package/dist/secrets/CompositeSecretStore.d.ts +37 -0
  377. package/dist/secrets/CompositeSecretStore.d.ts.map +1 -0
  378. package/dist/secrets/CompositeSecretStore.js +99 -0
  379. package/dist/secrets/CompositeSecretStore.js.map +1 -0
  380. package/dist/secrets/EnvSecretStore.d.ts +18 -0
  381. package/dist/secrets/EnvSecretStore.d.ts.map +1 -0
  382. package/dist/secrets/EnvSecretStore.js +46 -0
  383. package/dist/secrets/EnvSecretStore.js.map +1 -0
  384. package/dist/secrets/FileSecretStore.d.ts +60 -0
  385. package/dist/secrets/FileSecretStore.d.ts.map +1 -0
  386. package/dist/secrets/FileSecretStore.js +180 -0
  387. package/dist/secrets/FileSecretStore.js.map +1 -0
  388. package/dist/secrets/Redactor.d.ts +32 -0
  389. package/dist/secrets/Redactor.d.ts.map +1 -0
  390. package/dist/secrets/Redactor.js +108 -0
  391. package/dist/secrets/Redactor.js.map +1 -0
  392. package/dist/secrets/SecretHandle.d.ts +34 -0
  393. package/dist/secrets/SecretHandle.d.ts.map +1 -0
  394. package/dist/secrets/SecretHandle.js +71 -0
  395. package/dist/secrets/SecretHandle.js.map +1 -0
  396. package/dist/secrets/SecretStore.d.ts +37 -0
  397. package/dist/secrets/SecretStore.d.ts.map +1 -0
  398. package/dist/secrets/SecretStore.js +12 -0
  399. package/dist/secrets/SecretStore.js.map +1 -0
  400. package/dist/service/AuthorityClients.d.ts +50 -0
  401. package/dist/service/AuthorityClients.d.ts.map +1 -0
  402. package/dist/service/AuthorityClients.js +83 -0
  403. package/dist/service/AuthorityClients.js.map +1 -0
  404. package/dist/service/EscalationResolver.d.ts +97 -0
  405. package/dist/service/EscalationResolver.d.ts.map +1 -0
  406. package/dist/service/EscalationResolver.js +196 -0
  407. package/dist/service/EscalationResolver.js.map +1 -0
  408. package/dist/service/Requests.d.ts +99 -0
  409. package/dist/service/Requests.d.ts.map +1 -0
  410. package/dist/service/Requests.js +42 -0
  411. package/dist/service/Requests.js.map +1 -0
  412. package/dist/service/ServiceError.d.ts +20 -0
  413. package/dist/service/ServiceError.d.ts.map +1 -0
  414. package/dist/service/ServiceError.js +25 -0
  415. package/dist/service/ServiceError.js.map +1 -0
  416. package/dist/service/TrustedExecutorService.d.ts +221 -0
  417. package/dist/service/TrustedExecutorService.d.ts.map +1 -0
  418. package/dist/service/TrustedExecutorService.js +1066 -0
  419. package/dist/service/TrustedExecutorService.js.map +1 -0
  420. package/dist/time/ClockSkewGuard.d.ts +25 -0
  421. package/dist/time/ClockSkewGuard.d.ts.map +1 -0
  422. package/dist/time/ClockSkewGuard.js +35 -0
  423. package/dist/time/ClockSkewGuard.js.map +1 -0
  424. package/dist/time/MonotonicClock.d.ts +35 -0
  425. package/dist/time/MonotonicClock.d.ts.map +1 -0
  426. package/dist/time/MonotonicClock.js +52 -0
  427. package/dist/time/MonotonicClock.js.map +1 -0
  428. package/dist/verify/VerifyAuditChain.d.ts +36 -0
  429. package/dist/verify/VerifyAuditChain.d.ts.map +1 -0
  430. package/dist/verify/VerifyAuditChain.js +109 -0
  431. package/dist/verify/VerifyAuditChain.js.map +1 -0
  432. package/dist/verify/VerifyEvidenceBundle.d.ts +50 -0
  433. package/dist/verify/VerifyEvidenceBundle.d.ts.map +1 -0
  434. package/dist/verify/VerifyEvidenceBundle.js +157 -0
  435. package/dist/verify/VerifyEvidenceBundle.js.map +1 -0
  436. package/package.json +80 -0
@@ -0,0 +1,706 @@
1
+ import { z } from "zod";
2
+ import { ExecutorConfigLoader, } from "../config/ExecutorConfig.js";
3
+ /** The methods a route governs unless it names its own; a safe method is never consequential. */
4
+ export const CONSEQUENTIAL_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
5
+ /** The intent contract's action name: what a route may call the action it governs. */
6
+ export const ACTION_NAME = /^[a-z][a-z0-9._:-]*$/;
7
+ /** The tenant the demo authority evaluates under; a reserved fixture identifier, never an organization. */
8
+ export const LOCAL_TENANT_ID = "00000000-0000-4000-8000-000000000009";
9
+ export const DEFAULT_AUTHORITY_ENDPOINT = "https://api.decionis.com";
10
+ export const DEFAULT_LISTEN = { host: "127.0.0.1", port: 8080 };
11
+ const DEFAULT_TIMEOUT_MS = 4_000;
12
+ const DEFAULT_UPSTREAM_TIMEOUT_MS = 10_000;
13
+ const DEFAULT_MAX_BODY_BYTES = 1024 * 1024;
14
+ const DEFAULT_MAX_EMBEDDED_BODY_BYTES = 64 * 1024;
15
+ const DEFAULT_INTENT_TTL_SECONDS = 120;
16
+ /** The most a body may be, so the bound is a bound and not a suggestion. */
17
+ const MAX_BODY_BYTES = 16 * 1024 * 1024;
18
+ const lowerEnum = (values) => z.preprocess((value) => (typeof value === "string" ? value.trim().toLowerCase() : value), z.enum(values));
19
+ const routePath = z.string().trim().min(1).max(500).regex(/^\//, "a route path starts with /");
20
+ const actionName = z.string().trim().min(1).max(120).regex(ACTION_NAME);
21
+ const method = z.preprocess((value) => (typeof value === "string" ? value.trim().toUpperCase() : value), z.enum(CONSEQUENTIAL_METHODS));
22
+ const positiveInt = z.number().int().positive();
23
+ const url = z.string().trim().min(1).max(500);
24
+ const RouteSchema = z.strictObject({
25
+ path: routePath,
26
+ action: actionName,
27
+ methods: z.array(method).min(1).max(4).optional(),
28
+ });
29
+ const AuthoritySchema = z.strictObject({
30
+ endpoint: z.union([z.literal("local"), url]).optional(),
31
+ mode: lowerEnum(["shadow", "enforcement"]).optional(),
32
+ failurePolicy: lowerEnum(["failclosed", "failopen"]).optional(),
33
+ tenantId: z.string().uuid().optional(),
34
+ timeoutMs: positiveInt.max(15_000).optional(),
35
+ allowInsecureLoopback: z.boolean().optional(),
36
+ });
37
+ const PresenceSchema = z.strictObject({
38
+ managed: z.boolean().optional(),
39
+ approverId: z.string().trim().min(1).max(200).optional(),
40
+ approverRole: z.string().trim().min(1).max(200).optional(),
41
+ level: lowerEnum(["standard", "high_confidence"]).optional(),
42
+ methods: z
43
+ .array(lowerEnum(["webauthn", "active_liveness"]))
44
+ .min(1)
45
+ .max(2)
46
+ .optional(),
47
+ });
48
+ /** The file, `agentsafe.yaml`: `version: 1` and any of these sections; an unknown key is refused by name. */
49
+ export const GatewayFileSchema = z.strictObject({
50
+ version: z.literal(1),
51
+ gateway: z
52
+ .strictObject({
53
+ listen: z.string().trim().min(1).max(64).optional(),
54
+ upstream: url.optional(),
55
+ upstreamInsecure: z.boolean().optional(),
56
+ upstreamTimeoutMs: positiveInt.max(120_000).optional(),
57
+ system: z.string().trim().min(1).max(200).optional(),
58
+ environment: z.string().trim().min(1).max(200).optional(),
59
+ })
60
+ .optional(),
61
+ authority: AuthoritySchema.optional(),
62
+ /** The same section under the name the first quickstart used. */
63
+ decionis: AuthoritySchema.optional(),
64
+ interception: z
65
+ .strictObject({
66
+ http: z.boolean().optional(),
67
+ routes: z.array(RouteSchema).max(200).optional(),
68
+ unmatched: lowerEnum(["govern", "passthrough"]).optional(),
69
+ maxBodyBytes: positiveInt.max(MAX_BODY_BYTES).optional(),
70
+ maxEmbeddedBodyBytes: positiveInt.max(MAX_BODY_BYTES).optional(),
71
+ principalHeader: z
72
+ .string()
73
+ .trim()
74
+ .min(1)
75
+ .max(128)
76
+ .regex(/^[\w!#$%&'*+.^`|~-]+$/)
77
+ .optional(),
78
+ })
79
+ .optional(),
80
+ actor: z
81
+ .strictObject({
82
+ id: z.string().trim().min(1).max(200).optional(),
83
+ type: z.string().trim().min(1).max(200).optional(),
84
+ })
85
+ .optional(),
86
+ intentTtlSeconds: positiveInt.max(300).optional(),
87
+ presence: PresenceSchema.optional(),
88
+ evidence: z
89
+ .strictObject({
90
+ enabled: z.boolean().optional(),
91
+ journalDir: z.string().trim().min(1).max(500).optional(),
92
+ })
93
+ .optional(),
94
+ output: z
95
+ .strictObject({
96
+ format: lowerEnum(["human", "json"]).optional(),
97
+ verbose: z.boolean().optional(),
98
+ })
99
+ .optional(),
100
+ });
101
+ /** A refusal to start that names the setting and never its value. */
102
+ export class GatewayConfigError extends Error {
103
+ code;
104
+ setting;
105
+ constructor(code, setting, detail = null) {
106
+ super(`${code}: ${setting}${detail === null ? "" : ` (${detail})`}`);
107
+ this.code = code;
108
+ this.setting = setting;
109
+ this.name = "GatewayConfigError";
110
+ }
111
+ }
112
+ const ENVIRONMENT = {
113
+ listen: "AGENTSAFE_LISTEN",
114
+ port: "PORT",
115
+ upstream: "AGENTSAFE_UPSTREAM",
116
+ upstreamInsecure: "AGENTSAFE_UPSTREAM_INSECURE",
117
+ upstreamTimeoutMs: "AGENTSAFE_UPSTREAM_TIMEOUT_MS",
118
+ system: "AGENTSAFE_UPSTREAM_SYSTEM",
119
+ environment: "AGENTSAFE_ENVIRONMENT",
120
+ authority: "AGENTSAFE_AUTHORITY",
121
+ mode: "AGENTSAFE_MODE",
122
+ legacyMode: "DECIONIS_MODE",
123
+ failurePolicy: "AGENTSAFE_FAILURE_POLICY",
124
+ unmatched: "AGENTSAFE_UNMATCHED",
125
+ endpoint: "DECIONIS_API_URL",
126
+ tenantId: "DECIONIS_TENANT_ID",
127
+ timeoutMs: "DECIONIS_TIMEOUT_MS",
128
+ allowInsecureLoopback: "DECIONIS_ALLOW_INSECURE_LOOPBACK",
129
+ apiKey: "DECIONIS_API_KEY",
130
+ logLevel: "AGENTSAFE_LOG_LEVEL",
131
+ logFormat: "AGENTSAFE_LOG_FORMAT",
132
+ evidenceDir: "AGENTSAFE_EVIDENCE_DIR",
133
+ actorId: "AGENTSAFE_ACTOR_ID",
134
+ actorType: "AGENTSAFE_ACTOR_TYPE",
135
+ principalHeader: "AGENTSAFE_PRINCIPAL_HEADER",
136
+ presenceApproverId: "PRESENCE_APPROVER_ID",
137
+ presenceApproverRole: "PRESENCE_APPROVER_ROLE",
138
+ presenceLevel: "PRESENCE_VERIFICATION_LEVEL",
139
+ presenceMethods: "PRESENCE_VERIFICATION_METHODS",
140
+ presenceManaged: "AGENTSAFE_PRESENCE_MANAGED",
141
+ };
142
+ /** Variables the commands read outside the loader: the file, the login directory, the metrics token. */
143
+ const COMMAND_ENVIRONMENT = [
144
+ "AGENTSAFE_CONFIG",
145
+ "AGENTSAFE_HOME",
146
+ "AGENTSAFE_METRICS_TOKEN",
147
+ ];
148
+ /** Every variable the gateway and its commands read, for the reference page. */
149
+ export const GATEWAY_ENVIRONMENT = [
150
+ ...Object.values(ENVIRONMENT),
151
+ ...COMMAND_ENVIRONMENT,
152
+ "DECIONIS_API_KEY_FILE",
153
+ "NODE_ENV",
154
+ "NO_COLOR",
155
+ ];
156
+ function pick(layers, fallback) {
157
+ for (const layer of layers) {
158
+ if (layer.raw !== undefined)
159
+ return { value: layer.raw, source: layer.source };
160
+ }
161
+ return { value: fallback, source: "default" };
162
+ }
163
+ function parseListen(value, setting) {
164
+ const trimmed = value.trim();
165
+ const separator = trimmed.lastIndexOf(":");
166
+ const host = separator === -1 ? "" : trimmed.slice(0, separator).replace(/^\[|\]$/g, "");
167
+ const port = Number(separator === -1 ? trimmed : trimmed.slice(separator + 1));
168
+ if (!Number.isInteger(port) || port < 1 || port > 65_535) {
169
+ throw new GatewayConfigError("CONFIG_INVALID", setting, "host:port");
170
+ }
171
+ return { host: host === "" ? "0.0.0.0" : host, port };
172
+ }
173
+ function parseBoolean(value, setting) {
174
+ if (value === undefined)
175
+ return undefined;
176
+ const lower = value.trim().toLowerCase();
177
+ if (lower === "true" || lower === "1" || lower === "yes")
178
+ return true;
179
+ if (lower === "false" || lower === "0" || lower === "no")
180
+ return false;
181
+ throw new GatewayConfigError("CONFIG_INVALID", setting, "true or false");
182
+ }
183
+ function parseInteger(value, setting, max) {
184
+ if (value === undefined)
185
+ return undefined;
186
+ if (!/^\d{1,9}$/.test(value.trim())) {
187
+ throw new GatewayConfigError("CONFIG_INVALID", setting, `an integer up to ${max}`);
188
+ }
189
+ const parsed = Number(value.trim());
190
+ if (parsed < 1 || parsed > max) {
191
+ throw new GatewayConfigError("CONFIG_INVALID", setting, `an integer up to ${max}`);
192
+ }
193
+ return parsed;
194
+ }
195
+ function parseMode(value, setting) {
196
+ if (value === undefined)
197
+ return undefined;
198
+ const upper = value.trim().toUpperCase();
199
+ if (upper === "SHADOW")
200
+ return "SHADOW";
201
+ if (upper === "ENFORCE" || upper === "ENFORCEMENT")
202
+ return "ENFORCEMENT";
203
+ throw new GatewayConfigError("CONFIG_INVALID", setting, "shadow or enforcement");
204
+ }
205
+ function parseFailurePolicy(value, setting) {
206
+ if (value === undefined)
207
+ return undefined;
208
+ const lower = value.trim().toLowerCase().replace(/[_-]/g, "");
209
+ if (lower === "failclosed")
210
+ return "FAIL_CLOSED";
211
+ if (lower === "failopen")
212
+ return "FAIL_OPEN";
213
+ throw new GatewayConfigError("CONFIG_INVALID", setting, "failClosed or failOpen");
214
+ }
215
+ function parseAuthority(value, setting) {
216
+ if (value === undefined)
217
+ return undefined;
218
+ const lower = value.trim().toLowerCase();
219
+ if (lower === "local" || lower === "demo")
220
+ return "LOCAL";
221
+ if (lower === "decionis" || lower === "hosted")
222
+ return "DECIONIS";
223
+ throw new GatewayConfigError("CONFIG_INVALID", setting, "local or decionis");
224
+ }
225
+ function parseUnmatched(value, setting) {
226
+ if (value === undefined)
227
+ return undefined;
228
+ const lower = value.trim().toLowerCase();
229
+ if (lower === "govern")
230
+ return "GOVERN";
231
+ if (lower === "passthrough")
232
+ return "PASSTHROUGH";
233
+ throw new GatewayConfigError("CONFIG_INVALID", setting, "govern or passthrough");
234
+ }
235
+ function parseMethods(value, setting) {
236
+ if (value === undefined)
237
+ return undefined;
238
+ const methods = value
239
+ .split(",")
240
+ .map((entry) => entry.trim().toUpperCase())
241
+ .filter((entry) => entry !== "");
242
+ for (const entry of methods) {
243
+ if (entry !== "WEBAUTHN" && entry !== "ACTIVE_LIVENESS") {
244
+ throw new GatewayConfigError("CONFIG_INVALID", setting, "WEBAUTHN, ACTIVE_LIVENESS");
245
+ }
246
+ }
247
+ if (methods.length === 0)
248
+ throw new GatewayConfigError("CONFIG_INVALID", setting);
249
+ return methods;
250
+ }
251
+ /**
252
+ * Resolves the gateway's configuration. Precedence is the command line,
253
+ * then the environment, then the file, then the stored login for the
254
+ * credential alone, then the defaults; each setting says which layer it
255
+ * came from. Every refusal names the setting and never a value.
256
+ */
257
+ export class GatewayConfigLoader {
258
+ static load(input) {
259
+ const flags = input.flags ?? {};
260
+ const env = input.env;
261
+ const production = env["NODE_ENV"] === "production";
262
+ const file = GatewayConfigLoader.file(input.file);
263
+ const credentials = production ? null : (input.credentials ?? null);
264
+ const sources = {};
265
+ const authoritySection = file?.authority ?? file?.decionis;
266
+ if (file?.authority !== undefined && file.decionis !== undefined) {
267
+ throw new GatewayConfigError("CONFIG_INVALID", "authority", "given twice, as decionis too");
268
+ }
269
+ const resolve = (name, layers, fallback) => {
270
+ const picked = pick(layers, fallback);
271
+ sources[name] = picked.source;
272
+ return picked.value;
273
+ };
274
+ // The listener: a flag names a port, a variable or the file a host:port.
275
+ const listenFromFlag = flags.listen !== undefined
276
+ ? parseListen(flags.listen, "--listen")
277
+ : flags.port !== undefined
278
+ ? { host: DEFAULT_LISTEN.host, port: flags.port }
279
+ : undefined;
280
+ const listenFromEnv = env[ENVIRONMENT.listen] !== undefined
281
+ ? parseListen(env[ENVIRONMENT.listen] ?? "", ENVIRONMENT.listen)
282
+ : env[ENVIRONMENT.port] !== undefined
283
+ ? {
284
+ host: DEFAULT_LISTEN.host,
285
+ port: parseInteger(env[ENVIRONMENT.port], ENVIRONMENT.port, 65_535) ?? 0,
286
+ }
287
+ : undefined;
288
+ const listen = resolve("listen", [
289
+ { source: "flag", raw: listenFromFlag },
290
+ { source: "environment", raw: listenFromEnv },
291
+ {
292
+ source: "file",
293
+ raw: file?.gateway?.listen === undefined
294
+ ? undefined
295
+ : parseListen(file.gateway.listen, "gateway.listen"),
296
+ },
297
+ ], { ...DEFAULT_LISTEN });
298
+ const upstreamRaw = resolve("upstream", [
299
+ { source: "flag", raw: flags.upstream },
300
+ { source: "environment", raw: env[ENVIRONMENT.upstream] },
301
+ { source: "file", raw: file?.gateway?.upstream },
302
+ ], null);
303
+ if (upstreamRaw === null) {
304
+ throw new GatewayConfigError("CONFIG_MISSING", "upstream", "--upstream, AGENTSAFE_UPSTREAM or gateway.upstream");
305
+ }
306
+ const upstreamInsecure = resolve("upstream.insecure", [
307
+ {
308
+ source: "environment",
309
+ raw: parseBoolean(env[ENVIRONMENT.upstreamInsecure], ENVIRONMENT.upstreamInsecure),
310
+ },
311
+ { source: "file", raw: file?.gateway?.upstreamInsecure },
312
+ ], false);
313
+ const upstreamUrl = GatewayConfigLoader.upstreamUrl(upstreamRaw, upstreamInsecure);
314
+ const apiKeyPresent = env[ENVIRONMENT.apiKey] !== undefined ||
315
+ env[`${ENVIRONMENT.apiKey}_FILE`] !== undefined ||
316
+ credentials !== null;
317
+ const endpointGiven = authoritySection?.endpoint !== undefined && authoritySection.endpoint !== "local";
318
+ const kind = resolve("authority.kind", [
319
+ { source: "flag", raw: parseAuthority(flags.authority, "--authority") },
320
+ {
321
+ source: "environment",
322
+ raw: parseAuthority(env[ENVIRONMENT.authority], ENVIRONMENT.authority),
323
+ },
324
+ { source: "file", raw: authoritySection?.endpoint === "local" ? "LOCAL" : undefined },
325
+ {
326
+ source: apiKeyPresent
327
+ ? credentials !== null &&
328
+ env[ENVIRONMENT.apiKey] === undefined &&
329
+ env[`${ENVIRONMENT.apiKey}_FILE`] === undefined
330
+ ? "credentials"
331
+ : "environment"
332
+ : "file",
333
+ raw: apiKeyPresent || endpointGiven ? "DECIONIS" : undefined,
334
+ },
335
+ ], "LOCAL");
336
+ if (kind === "LOCAL" && production) {
337
+ throw new GatewayConfigError("CONFIG_INVALID", "authority", "the local demo authority is refused in production; set DECIONIS_API_KEY");
338
+ }
339
+ // Shadow is the default beside a real authority, because it changes
340
+ // nothing downstream; the demo authority governs nothing real, so it
341
+ // enforces by default and the terminal shows a refusal on the first try.
342
+ const mode = resolve("authority.mode", [
343
+ { source: "flag", raw: parseMode(flags.mode, "--mode") },
344
+ { source: "environment", raw: parseMode(env[ENVIRONMENT.mode], ENVIRONMENT.mode) },
345
+ {
346
+ source: "environment",
347
+ raw: parseMode(env[ENVIRONMENT.legacyMode], ENVIRONMENT.legacyMode),
348
+ },
349
+ { source: "file", raw: parseMode(authoritySection?.mode, "authority.mode") },
350
+ ], kind === "LOCAL" ? "ENFORCEMENT" : "SHADOW");
351
+ const failurePolicy = resolve("authority.failurePolicy", [
352
+ { source: "flag", raw: parseFailurePolicy(flags.failurePolicy, "--failure-policy") },
353
+ {
354
+ source: "environment",
355
+ raw: parseFailurePolicy(env[ENVIRONMENT.failurePolicy], ENVIRONMENT.failurePolicy),
356
+ },
357
+ {
358
+ source: "file",
359
+ raw: parseFailurePolicy(authoritySection?.failurePolicy, "authority.failurePolicy"),
360
+ },
361
+ ], "FAIL_CLOSED");
362
+ const endpointRaw = resolve("authority.endpoint", [
363
+ { source: "environment", raw: env[ENVIRONMENT.endpoint] },
364
+ { source: "file", raw: endpointGiven ? authoritySection?.endpoint : undefined },
365
+ { source: "credentials", raw: credentials?.endpoint ?? undefined },
366
+ ], DEFAULT_AUTHORITY_ENDPOINT);
367
+ const allowInsecureLoopback = resolve("authority.allowInsecureLoopback", [
368
+ {
369
+ source: "environment",
370
+ raw: parseBoolean(env[ENVIRONMENT.allowInsecureLoopback], ENVIRONMENT.allowInsecureLoopback),
371
+ },
372
+ { source: "file", raw: authoritySection?.allowInsecureLoopback },
373
+ ], false);
374
+ if (allowInsecureLoopback && production) {
375
+ throw new GatewayConfigError("CONFIG_INVALID", ENVIRONMENT.allowInsecureLoopback, "forbidden in production");
376
+ }
377
+ const endpoint = kind === "LOCAL"
378
+ ? "local"
379
+ : GatewayConfigLoader.authorityUrl(endpointRaw, "authority.endpoint", allowInsecureLoopback);
380
+ const tenantRaw = resolve("authority.tenantId", [
381
+ { source: "environment", raw: env[ENVIRONMENT.tenantId]?.trim() },
382
+ { source: "file", raw: authoritySection?.tenantId },
383
+ { source: "credentials", raw: credentials?.tenantId ?? undefined },
384
+ ], null);
385
+ if (kind === "DECIONIS" && !apiKeyPresent) {
386
+ throw new GatewayConfigError("CONFIG_MISSING", ENVIRONMENT.apiKey, "a Decionis key, or run agentsafe login");
387
+ }
388
+ if (kind === "DECIONIS" && tenantRaw === null) {
389
+ throw new GatewayConfigError("CONFIG_MISSING", ENVIRONMENT.tenantId, "the key's organization id");
390
+ }
391
+ if (kind === "DECIONIS" && !z.string().uuid().safeParse(tenantRaw).success) {
392
+ throw new GatewayConfigError("CONFIG_INVALID", ENVIRONMENT.tenantId, "a UUID");
393
+ }
394
+ const tenantId = kind === "LOCAL" ? LOCAL_TENANT_ID : (tenantRaw ?? LOCAL_TENANT_ID);
395
+ const timeoutMs = resolve("authority.timeoutMs", [
396
+ {
397
+ source: "environment",
398
+ raw: parseInteger(env[ENVIRONMENT.timeoutMs], ENVIRONMENT.timeoutMs, 15_000),
399
+ },
400
+ { source: "file", raw: authoritySection?.timeoutMs },
401
+ ], DEFAULT_TIMEOUT_MS);
402
+ const routes = (file?.interception?.routes ?? []).map((route) => ({
403
+ path: route.path,
404
+ action: route.action,
405
+ methods: route.methods ?? [...CONSEQUENTIAL_METHODS],
406
+ }));
407
+ sources["interception.routes"] = file?.interception?.routes === undefined ? "default" : "file";
408
+ const unmatched = resolve("interception.unmatched", [
409
+ {
410
+ source: "environment",
411
+ raw: parseUnmatched(env[ENVIRONMENT.unmatched], ENVIRONMENT.unmatched),
412
+ },
413
+ {
414
+ source: "file",
415
+ raw: parseUnmatched(file?.interception?.unmatched, "interception.unmatched"),
416
+ },
417
+ ], "GOVERN");
418
+ const maxBodyBytes = resolve("interception.maxBodyBytes", [{ source: "file", raw: file?.interception?.maxBodyBytes }], DEFAULT_MAX_BODY_BYTES);
419
+ const maxEmbeddedBodyBytes = resolve("interception.maxEmbeddedBodyBytes", [{ source: "file", raw: file?.interception?.maxEmbeddedBodyBytes }], Math.min(DEFAULT_MAX_EMBEDDED_BODY_BYTES, maxBodyBytes));
420
+ if (maxEmbeddedBodyBytes > maxBodyBytes) {
421
+ throw new GatewayConfigError("CONFIG_INVALID", "interception.maxEmbeddedBodyBytes", "at most interception.maxBodyBytes");
422
+ }
423
+ const principalHeader = resolve("interception.principalHeader", [
424
+ { source: "environment", raw: env[ENVIRONMENT.principalHeader]?.trim() },
425
+ { source: "file", raw: file?.interception?.principalHeader },
426
+ ], null);
427
+ const escalation = GatewayConfigLoader.escalation(file, env, mode, kind, resolve);
428
+ const required = [];
429
+ if (kind === "DECIONIS")
430
+ required.push("DECIONIS_API_KEY");
431
+ if (escalation.mode === "DIRECT")
432
+ required.push("PRESENCE_API_KEY");
433
+ const verbose = resolve("output.verbose", [
434
+ { source: "flag", raw: flags.verbose === true ? true : undefined },
435
+ {
436
+ source: "environment",
437
+ raw: env[ENVIRONMENT.logLevel] === undefined
438
+ ? undefined
439
+ : env[ENVIRONMENT.logLevel]?.trim().toLowerCase() === "debug",
440
+ },
441
+ { source: "file", raw: file?.output?.verbose },
442
+ ], false);
443
+ const format = resolve("output.format", [
444
+ { source: "flag", raw: flags.json === true ? "JSON" : undefined },
445
+ {
446
+ source: "environment",
447
+ raw: env[ENVIRONMENT.logFormat] === undefined
448
+ ? undefined
449
+ : env[ENVIRONMENT.logFormat]?.trim().toLowerCase() === "json"
450
+ ? "JSON"
451
+ : "HUMAN",
452
+ },
453
+ {
454
+ source: "file",
455
+ raw: file?.output?.format === undefined
456
+ ? undefined
457
+ : file.output.format === "json"
458
+ ? "JSON"
459
+ : "HUMAN",
460
+ },
461
+ ], production ? "JSON" : "HUMAN");
462
+ return {
463
+ listen,
464
+ upstream: {
465
+ url: upstreamUrl,
466
+ insecure: upstreamInsecure,
467
+ system: resolve("upstream.system", [
468
+ { source: "environment", raw: env[ENVIRONMENT.system]?.trim() },
469
+ { source: "file", raw: file?.gateway?.system },
470
+ ], new URL(upstreamUrl).host),
471
+ environment: resolve("upstream.environment", [
472
+ { source: "environment", raw: env[ENVIRONMENT.environment]?.trim() },
473
+ { source: "file", raw: file?.gateway?.environment },
474
+ ], production ? "production" : "local"),
475
+ timeoutMs: resolve("upstream.timeoutMs", [
476
+ {
477
+ source: "environment",
478
+ raw: parseInteger(env[ENVIRONMENT.upstreamTimeoutMs], ENVIRONMENT.upstreamTimeoutMs, 120_000),
479
+ },
480
+ { source: "file", raw: file?.gateway?.upstreamTimeoutMs },
481
+ ], DEFAULT_UPSTREAM_TIMEOUT_MS),
482
+ maxResponseBytes: MAX_BODY_BYTES,
483
+ },
484
+ authority: {
485
+ kind,
486
+ endpoint,
487
+ mode,
488
+ failurePolicy,
489
+ tenantId,
490
+ timeoutMs,
491
+ allowInsecureLoopback,
492
+ },
493
+ interception: {
494
+ http: resolve("interception.http", [{ source: "file", raw: file?.interception?.http }], true),
495
+ routes,
496
+ unmatched,
497
+ maxBodyBytes,
498
+ maxEmbeddedBodyBytes,
499
+ principalHeader: principalHeader === null ? null : principalHeader.toLowerCase(),
500
+ },
501
+ actor: {
502
+ id: resolve("actor.id", [
503
+ { source: "environment", raw: env[ENVIRONMENT.actorId]?.trim() },
504
+ { source: "file", raw: file?.actor?.id },
505
+ ], "agentsafe-gateway"),
506
+ type: resolve("actor.type", [
507
+ { source: "environment", raw: env[ENVIRONMENT.actorType]?.trim() },
508
+ { source: "file", raw: file?.actor?.type },
509
+ ], "GATEWAY"),
510
+ runtime: `agentsafe/${input.version}`,
511
+ },
512
+ intentTtlSeconds: resolve("intentTtlSeconds", [{ source: "file", raw: file?.intentTtlSeconds }], DEFAULT_INTENT_TTL_SECONDS),
513
+ escalation,
514
+ evidence: {
515
+ enabled: resolve("evidence.enabled", [{ source: "file", raw: file?.evidence?.enabled }], true),
516
+ journalDir: resolve("evidence.journalDir", [
517
+ { source: "environment", raw: env[ENVIRONMENT.evidenceDir]?.trim() },
518
+ { source: "file", raw: file?.evidence?.journalDir },
519
+ ], null),
520
+ },
521
+ output: { format, verbose },
522
+ production,
523
+ secrets: { required },
524
+ sources,
525
+ };
526
+ }
527
+ /** The file's shape, refused by the name of the first key that is wrong. */
528
+ static file(raw) {
529
+ if (raw === null || raw === undefined)
530
+ return null;
531
+ const parsed = GatewayFileSchema.safeParse(raw);
532
+ if (parsed.success)
533
+ return parsed.data;
534
+ const issue = parsed.error.issues[0];
535
+ const path = issue === undefined || issue.path.length === 0 ? "version" : issue.path.join(".");
536
+ throw new GatewayConfigError("CONFIG_INVALID", path, issue?.message ?? null);
537
+ }
538
+ /**
539
+ * The upstream is where authorized requests go. TLS is the default; a
540
+ * loopback address may be plain, and anything else may be plain only when
541
+ * the configuration says the network protects that hop.
542
+ */
543
+ static upstreamUrl(raw, insecure) {
544
+ let parsed;
545
+ try {
546
+ parsed = new URL(raw.trim());
547
+ }
548
+ catch {
549
+ throw new GatewayConfigError("CONFIG_INVALID", "upstream", "an absolute http(s) URL");
550
+ }
551
+ if (parsed.username !== "" || parsed.password !== "") {
552
+ throw new GatewayConfigError("CONFIG_INVALID", "upstream", "credentials in a URL are refused");
553
+ }
554
+ if (parsed.protocol === "https:")
555
+ return parsed.href.replace(/\/$/, "");
556
+ if (parsed.protocol !== "http:") {
557
+ throw new GatewayConfigError("CONFIG_INVALID", "upstream", "http or https");
558
+ }
559
+ const loopback = parsed.hostname === "localhost" ||
560
+ parsed.hostname === "127.0.0.1" ||
561
+ parsed.hostname === "[::1]";
562
+ if (!loopback && !insecure) {
563
+ throw new GatewayConfigError("CONFIG_INVALID", "upstream", "plain http off loopback needs gateway.upstreamInsecure: true");
564
+ }
565
+ return parsed.href.replace(/\/$/, "");
566
+ }
567
+ static authorityUrl(raw, setting, allowInsecureLoopback) {
568
+ let checked;
569
+ try {
570
+ checked = ExecutorConfigLoader.serviceUrl(raw.trim(), setting, allowInsecureLoopback);
571
+ }
572
+ catch (error) {
573
+ // The executor's message is `CONFIG_INVALID: <key> (<detail>)`; the detail is kept.
574
+ const message = error instanceof Error ? error.message : "";
575
+ const open = message.indexOf("(");
576
+ const detail = open === -1 || !message.endsWith(")") ? "an https URL" : message.slice(open + 1, -1);
577
+ throw new GatewayConfigError("CONFIG_INVALID", setting, detail);
578
+ }
579
+ let end = checked.length;
580
+ while (end > 0 && checked.charCodeAt(end - 1) === 47)
581
+ end -= 1;
582
+ return checked.slice(0, end);
583
+ }
584
+ /**
585
+ * How an `ESCALATE` is resolved, in the executor's own shape. Managed is
586
+ * the gateway's default when Presence is configured at all: Decionis
587
+ * orchestrates the ceremony and this process holds no Presence credential.
588
+ * Direct is available for a deployment that already holds one.
589
+ */
590
+ static escalation(file, env, mode, kind, resolve) {
591
+ const managed = resolve("presence.managed", [
592
+ {
593
+ source: "environment",
594
+ raw: parseBoolean(env[ENVIRONMENT.presenceManaged], ENVIRONMENT.presenceManaged),
595
+ },
596
+ { source: "file", raw: file?.presence?.managed },
597
+ ], false);
598
+ const approverId = resolve("presence.approverId", [
599
+ { source: "environment", raw: env[ENVIRONMENT.presenceApproverId]?.trim() },
600
+ { source: "file", raw: file?.presence?.approverId },
601
+ ], null);
602
+ if (!managed) {
603
+ if (approverId !== null) {
604
+ throw new GatewayConfigError("CONFIG_INVALID", "presence.approverId", "without presence.managed: true");
605
+ }
606
+ return { mode: "NONE" };
607
+ }
608
+ if (mode === "SHADOW") {
609
+ throw new GatewayConfigError("CONFIG_INVALID", "presence.managed", "shadow never escalates");
610
+ }
611
+ if (kind === "LOCAL") {
612
+ throw new GatewayConfigError("CONFIG_INVALID", "presence.managed", "the demo authority holds; it orchestrates nothing");
613
+ }
614
+ if (approverId === null) {
615
+ throw new GatewayConfigError("CONFIG_MISSING", "presence.approverId", "who approves a managed escalation");
616
+ }
617
+ const level = resolve("presence.level", [
618
+ {
619
+ source: "environment",
620
+ raw: GatewayConfigLoader.level(env[ENVIRONMENT.presenceLevel], ENVIRONMENT.presenceLevel),
621
+ },
622
+ { source: "file", raw: GatewayConfigLoader.level(file?.presence?.level, "presence.level") },
623
+ ], "STANDARD");
624
+ const methods = resolve("presence.methods", [
625
+ {
626
+ source: "environment",
627
+ raw: parseMethods(env[ENVIRONMENT.presenceMethods], ENVIRONMENT.presenceMethods),
628
+ },
629
+ {
630
+ source: "file",
631
+ raw: file?.presence?.methods === undefined
632
+ ? undefined
633
+ : file.presence.methods.map((entry) => entry.toUpperCase()),
634
+ },
635
+ ], ["WEBAUTHN"]);
636
+ return {
637
+ mode: "MANAGED",
638
+ approverId,
639
+ approverRole: resolve("presence.approverRole", [
640
+ { source: "environment", raw: env[ENVIRONMENT.presenceApproverRole]?.trim() },
641
+ { source: "file", raw: file?.presence?.approverRole },
642
+ ], null),
643
+ requirements: { methods, level },
644
+ };
645
+ }
646
+ static level(value, setting) {
647
+ if (value === undefined)
648
+ return undefined;
649
+ const upper = value.trim().toUpperCase();
650
+ if (upper === "STANDARD" || upper === "HIGH_CONFIDENCE")
651
+ return upper;
652
+ throw new GatewayConfigError("CONFIG_INVALID", setting, "STANDARD or HIGH_CONFIDENCE");
653
+ }
654
+ }
655
+ /** The file `agentsafe init` writes: the smallest working configuration, commented. */
656
+ export function renderConfigFile(options) {
657
+ const routes = options.routes.length === 0
658
+ ? [
659
+ " # Name the consequential actions. Until a route names one, every",
660
+ " # POST, PUT, PATCH and DELETE is governed as http.<method>.",
661
+ " routes: []",
662
+ " # - path: /payments/**",
663
+ " # action: payment.create",
664
+ " # methods: [POST]",
665
+ ]
666
+ : [
667
+ " routes:",
668
+ ...options.routes.flatMap((route) => [
669
+ ` - path: ${route.path}`,
670
+ ` action: ${route.action}`,
671
+ ` methods: [${route.methods.join(", ")}]`,
672
+ ]),
673
+ ];
674
+ return [
675
+ "# AgentSafe gateway configuration. Precedence: command-line flags, then",
676
+ "# environment variables, then this file, then the defaults.",
677
+ "version: 1",
678
+ "",
679
+ "gateway:",
680
+ ` listen: "${options.listen}"`,
681
+ ` upstream: "${options.upstream}"`,
682
+ "",
683
+ "authority:",
684
+ " # Without DECIONIS_API_KEY the local demo authority answers, with a",
685
+ " # synthetic policy on loopback; it is refused in production.",
686
+ " # endpoint: https://api.decionis.com",
687
+ ` mode: ${options.mode.toLowerCase()}`,
688
+ " failurePolicy: failClosed",
689
+ "",
690
+ "interception:",
691
+ " http: true",
692
+ " # An unsafe request no route names is governed; say passthrough to narrow.",
693
+ " unmatched: govern",
694
+ ...routes,
695
+ "",
696
+ "presence:",
697
+ " # Decionis orchestrates the human ceremony on an ESCALATE when this is",
698
+ " # true and approverId names who approves; the gateway holds otherwise.",
699
+ " managed: false",
700
+ "",
701
+ "evidence:",
702
+ " enabled: true",
703
+ "",
704
+ ].join("\n");
705
+ }
706
+ //# sourceMappingURL=GatewayConfig.js.map