4runr-os 2.9.33 → 2.9.35

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 (490) hide show
  1. package/apps/gateway/.dockerignore +11 -0
  2. package/apps/gateway/.eslintrc.json +28 -0
  3. package/apps/gateway/DEPLOYMENT.md +426 -0
  4. package/apps/gateway/Dockerfile +122 -0
  5. package/apps/gateway/Dockerfile.bak +41 -0
  6. package/apps/gateway/ENV_VARIABLES.md +366 -0
  7. package/apps/gateway/JWT-RATE-LIMIT-VALIDATION.md +462 -0
  8. package/apps/gateway/PERSISTENCE-AND-AUTH.md +227 -0
  9. package/apps/gateway/PHASE5-TESTING.md +222 -0
  10. package/apps/gateway/README.md +351 -0
  11. package/apps/gateway/TROUBLESHOOTING.md +541 -0
  12. package/apps/gateway/create-test-script.sh +386 -0
  13. package/apps/gateway/debug-api-responses.sh +94 -0
  14. package/apps/gateway/debug-failing-tests-v2.sh +81 -0
  15. package/apps/gateway/debug-failing-tests.sh +89 -0
  16. package/apps/gateway/debug-responses.sh +83 -0
  17. package/apps/gateway/debug-test-responses.sh +54 -0
  18. package/apps/gateway/debug-tests.sh +119 -0
  19. package/apps/gateway/diagnose-test-failure.sh +53 -0
  20. package/apps/gateway/dist/apps/gateway/src/adapters/redis-sentinel-publisher.d.ts +8 -0
  21. package/apps/gateway/dist/apps/gateway/src/adapters/redis-sentinel-publisher.d.ts.map +1 -0
  22. package/apps/gateway/dist/apps/gateway/src/adapters/redis-sentinel-publisher.js +27 -0
  23. package/apps/gateway/dist/apps/gateway/src/adapters/redis-sentinel-publisher.js.map +1 -0
  24. package/apps/gateway/dist/apps/gateway/src/adapters/sentinel-event-stream.d.ts +14 -0
  25. package/apps/gateway/dist/apps/gateway/src/adapters/sentinel-event-stream.d.ts.map +1 -0
  26. package/apps/gateway/dist/apps/gateway/src/adapters/sentinel-event-stream.js +69 -0
  27. package/apps/gateway/dist/apps/gateway/src/adapters/sentinel-event-stream.js.map +1 -0
  28. package/apps/gateway/dist/apps/gateway/src/agents/definitions-simple.d.ts +10 -0
  29. package/apps/gateway/dist/apps/gateway/src/agents/definitions-simple.d.ts.map +1 -0
  30. package/apps/gateway/dist/apps/gateway/src/agents/definitions-simple.js +372 -0
  31. package/apps/gateway/dist/apps/gateway/src/agents/definitions-simple.js.map +1 -0
  32. package/apps/gateway/dist/apps/gateway/src/agents/definitions.d.ts +14 -0
  33. package/apps/gateway/dist/apps/gateway/src/agents/definitions.d.ts.map +1 -0
  34. package/apps/gateway/dist/apps/gateway/src/agents/definitions.js +210 -0
  35. package/apps/gateway/dist/apps/gateway/src/agents/definitions.js.map +1 -0
  36. package/apps/gateway/dist/apps/gateway/src/agents/local-model-provider.d.ts +25 -0
  37. package/apps/gateway/dist/apps/gateway/src/agents/local-model-provider.d.ts.map +1 -0
  38. package/apps/gateway/dist/apps/gateway/src/agents/local-model-provider.js +144 -0
  39. package/apps/gateway/dist/apps/gateway/src/agents/local-model-provider.js.map +1 -0
  40. package/apps/gateway/dist/apps/gateway/src/agents/tools.d.ts +24 -0
  41. package/apps/gateway/dist/apps/gateway/src/agents/tools.d.ts.map +1 -0
  42. package/apps/gateway/dist/apps/gateway/src/agents/tools.js +110 -0
  43. package/apps/gateway/dist/apps/gateway/src/agents/tools.js.map +1 -0
  44. package/apps/gateway/dist/apps/gateway/src/ai-providers/anthropic-provider.d.ts +14 -0
  45. package/apps/gateway/dist/apps/gateway/src/ai-providers/anthropic-provider.d.ts.map +1 -0
  46. package/apps/gateway/dist/apps/gateway/src/ai-providers/anthropic-provider.js +139 -0
  47. package/apps/gateway/dist/apps/gateway/src/ai-providers/anthropic-provider.js.map +1 -0
  48. package/apps/gateway/dist/apps/gateway/src/ai-providers/index.d.ts +6 -0
  49. package/apps/gateway/dist/apps/gateway/src/ai-providers/index.d.ts.map +1 -0
  50. package/apps/gateway/dist/apps/gateway/src/ai-providers/index.js +6 -0
  51. package/apps/gateway/dist/apps/gateway/src/ai-providers/index.js.map +1 -0
  52. package/apps/gateway/dist/apps/gateway/src/ai-providers/openai-provider.d.ts +14 -0
  53. package/apps/gateway/dist/apps/gateway/src/ai-providers/openai-provider.d.ts.map +1 -0
  54. package/apps/gateway/dist/apps/gateway/src/ai-providers/openai-provider.js +136 -0
  55. package/apps/gateway/dist/apps/gateway/src/ai-providers/openai-provider.js.map +1 -0
  56. package/apps/gateway/dist/apps/gateway/src/ai-providers/provider-manager.d.ts +18 -0
  57. package/apps/gateway/dist/apps/gateway/src/ai-providers/provider-manager.d.ts.map +1 -0
  58. package/apps/gateway/dist/apps/gateway/src/ai-providers/provider-manager.js +91 -0
  59. package/apps/gateway/dist/apps/gateway/src/ai-providers/provider-manager.js.map +1 -0
  60. package/apps/gateway/dist/apps/gateway/src/ai-providers/redis-credentials-store.d.ts +15 -0
  61. package/apps/gateway/dist/apps/gateway/src/ai-providers/redis-credentials-store.d.ts.map +1 -0
  62. package/apps/gateway/dist/apps/gateway/src/ai-providers/redis-credentials-store.js +153 -0
  63. package/apps/gateway/dist/apps/gateway/src/ai-providers/redis-credentials-store.js.map +1 -0
  64. package/apps/gateway/dist/apps/gateway/src/ai-providers/types.d.ts +54 -0
  65. package/apps/gateway/dist/apps/gateway/src/ai-providers/types.d.ts.map +1 -0
  66. package/apps/gateway/dist/apps/gateway/src/ai-providers/types.js +2 -0
  67. package/apps/gateway/dist/apps/gateway/src/ai-providers/types.js.map +1 -0
  68. package/apps/gateway/dist/apps/gateway/src/config/persistence.d.ts +5 -0
  69. package/apps/gateway/dist/apps/gateway/src/config/persistence.d.ts.map +1 -0
  70. package/apps/gateway/dist/apps/gateway/src/config/persistence.js +14 -0
  71. package/apps/gateway/dist/apps/gateway/src/config/persistence.js.map +1 -0
  72. package/apps/gateway/dist/apps/gateway/src/crypto/envelope.d.ts +28 -0
  73. package/apps/gateway/dist/apps/gateway/src/crypto/envelope.d.ts.map +1 -0
  74. package/apps/gateway/dist/apps/gateway/src/crypto/envelope.js +111 -0
  75. package/apps/gateway/dist/apps/gateway/src/crypto/envelope.js.map +1 -0
  76. package/apps/gateway/dist/apps/gateway/src/db/prisma.d.ts +4 -0
  77. package/apps/gateway/dist/apps/gateway/src/db/prisma.d.ts.map +1 -0
  78. package/apps/gateway/dist/apps/gateway/src/db/prisma.js +31 -0
  79. package/apps/gateway/dist/apps/gateway/src/db/prisma.js.map +1 -0
  80. package/apps/gateway/dist/apps/gateway/src/db/redis.d.ts +5 -0
  81. package/apps/gateway/dist/apps/gateway/src/db/redis.d.ts.map +1 -0
  82. package/apps/gateway/dist/apps/gateway/src/db/redis.js +68 -0
  83. package/apps/gateway/dist/apps/gateway/src/db/redis.js.map +1 -0
  84. package/apps/gateway/dist/apps/gateway/src/devkit/agents-api.d.ts +3 -0
  85. package/apps/gateway/dist/apps/gateway/src/devkit/agents-api.d.ts.map +1 -0
  86. package/apps/gateway/dist/apps/gateway/src/devkit/agents-api.js +369 -0
  87. package/apps/gateway/dist/apps/gateway/src/devkit/agents-api.js.map +1 -0
  88. package/apps/gateway/dist/apps/gateway/src/devkit/metrics-parser.d.ts +46 -0
  89. package/apps/gateway/dist/apps/gateway/src/devkit/metrics-parser.d.ts.map +1 -0
  90. package/apps/gateway/dist/apps/gateway/src/devkit/metrics-parser.js +114 -0
  91. package/apps/gateway/dist/apps/gateway/src/devkit/metrics-parser.js.map +1 -0
  92. package/apps/gateway/dist/apps/gateway/src/devkit/middleware.d.ts +9 -0
  93. package/apps/gateway/dist/apps/gateway/src/devkit/middleware.d.ts.map +1 -0
  94. package/apps/gateway/dist/apps/gateway/src/devkit/middleware.js +23 -0
  95. package/apps/gateway/dist/apps/gateway/src/devkit/middleware.js.map +1 -0
  96. package/apps/gateway/dist/apps/gateway/src/devkit/routes.d.ts +3 -0
  97. package/apps/gateway/dist/apps/gateway/src/devkit/routes.d.ts.map +1 -0
  98. package/apps/gateway/dist/apps/gateway/src/devkit/routes.js +266 -0
  99. package/apps/gateway/dist/apps/gateway/src/devkit/routes.js.map +1 -0
  100. package/apps/gateway/dist/apps/gateway/src/devkit/tools-api.d.ts +3 -0
  101. package/apps/gateway/dist/apps/gateway/src/devkit/tools-api.d.ts.map +1 -0
  102. package/apps/gateway/dist/apps/gateway/src/devkit/tools-api.js +183 -0
  103. package/apps/gateway/dist/apps/gateway/src/devkit/tools-api.js.map +1 -0
  104. package/apps/gateway/dist/apps/gateway/src/health/index.d.ts +22 -0
  105. package/apps/gateway/dist/apps/gateway/src/health/index.d.ts.map +1 -0
  106. package/apps/gateway/dist/apps/gateway/src/health/index.js +180 -0
  107. package/apps/gateway/dist/apps/gateway/src/health/index.js.map +1 -0
  108. package/apps/gateway/dist/apps/gateway/src/index.d.ts +2 -0
  109. package/apps/gateway/dist/apps/gateway/src/index.d.ts.map +1 -0
  110. package/apps/gateway/dist/apps/gateway/src/index.js +982 -0
  111. package/apps/gateway/dist/apps/gateway/src/index.js.map +1 -0
  112. package/apps/gateway/dist/apps/gateway/src/metrics/index.d.ts +33 -0
  113. package/apps/gateway/dist/apps/gateway/src/metrics/index.d.ts.map +1 -0
  114. package/apps/gateway/dist/apps/gateway/src/metrics/index.js +166 -0
  115. package/apps/gateway/dist/apps/gateway/src/metrics/index.js.map +1 -0
  116. package/apps/gateway/dist/apps/gateway/src/middleware/auth.d.ts +5 -0
  117. package/apps/gateway/dist/apps/gateway/src/middleware/auth.d.ts.map +1 -0
  118. package/apps/gateway/dist/apps/gateway/src/middleware/auth.js +64 -0
  119. package/apps/gateway/dist/apps/gateway/src/middleware/auth.js.map +1 -0
  120. package/apps/gateway/dist/apps/gateway/src/middleware/authApiKey.d.ts +4 -0
  121. package/apps/gateway/dist/apps/gateway/src/middleware/authApiKey.d.ts.map +1 -0
  122. package/apps/gateway/dist/apps/gateway/src/middleware/authApiKey.js +105 -0
  123. package/apps/gateway/dist/apps/gateway/src/middleware/authApiKey.js.map +1 -0
  124. package/apps/gateway/dist/apps/gateway/src/middleware/authJwt.d.ts +12 -0
  125. package/apps/gateway/dist/apps/gateway/src/middleware/authJwt.d.ts.map +1 -0
  126. package/apps/gateway/dist/apps/gateway/src/middleware/authJwt.js +75 -0
  127. package/apps/gateway/dist/apps/gateway/src/middleware/authJwt.js.map +1 -0
  128. package/apps/gateway/dist/apps/gateway/src/middleware/correlationId.d.ts +4 -0
  129. package/apps/gateway/dist/apps/gateway/src/middleware/correlationId.d.ts.map +1 -0
  130. package/apps/gateway/dist/apps/gateway/src/middleware/correlationId.js +11 -0
  131. package/apps/gateway/dist/apps/gateway/src/middleware/correlationId.js.map +1 -0
  132. package/apps/gateway/dist/apps/gateway/src/middleware/ddos-protection.d.ts +13 -0
  133. package/apps/gateway/dist/apps/gateway/src/middleware/ddos-protection.d.ts.map +1 -0
  134. package/apps/gateway/dist/apps/gateway/src/middleware/ddos-protection.js +178 -0
  135. package/apps/gateway/dist/apps/gateway/src/middleware/ddos-protection.js.map +1 -0
  136. package/apps/gateway/dist/apps/gateway/src/middleware/errorHandler.d.ts +14 -0
  137. package/apps/gateway/dist/apps/gateway/src/middleware/errorHandler.d.ts.map +1 -0
  138. package/apps/gateway/dist/apps/gateway/src/middleware/errorHandler.js +98 -0
  139. package/apps/gateway/dist/apps/gateway/src/middleware/errorHandler.js.map +1 -0
  140. package/apps/gateway/dist/apps/gateway/src/middleware/mfa.d.ts +3 -0
  141. package/apps/gateway/dist/apps/gateway/src/middleware/mfa.d.ts.map +1 -0
  142. package/apps/gateway/dist/apps/gateway/src/middleware/mfa.js +92 -0
  143. package/apps/gateway/dist/apps/gateway/src/middleware/mfa.js.map +1 -0
  144. package/apps/gateway/dist/apps/gateway/src/middleware/rateLimit.d.ts +6 -0
  145. package/apps/gateway/dist/apps/gateway/src/middleware/rateLimit.d.ts.map +1 -0
  146. package/apps/gateway/dist/apps/gateway/src/middleware/rateLimit.js +54 -0
  147. package/apps/gateway/dist/apps/gateway/src/middleware/rateLimit.js.map +1 -0
  148. package/apps/gateway/dist/apps/gateway/src/middleware/rbac.d.ts +19 -0
  149. package/apps/gateway/dist/apps/gateway/src/middleware/rbac.d.ts.map +1 -0
  150. package/apps/gateway/dist/apps/gateway/src/middleware/rbac.js +229 -0
  151. package/apps/gateway/dist/apps/gateway/src/middleware/rbac.js.map +1 -0
  152. package/apps/gateway/dist/apps/gateway/src/middleware/security.d.ts +8 -0
  153. package/apps/gateway/dist/apps/gateway/src/middleware/security.d.ts.map +1 -0
  154. package/apps/gateway/dist/apps/gateway/src/middleware/security.js +55 -0
  155. package/apps/gateway/dist/apps/gateway/src/middleware/security.js.map +1 -0
  156. package/apps/gateway/dist/apps/gateway/src/middleware/validate.d.ts +7 -0
  157. package/apps/gateway/dist/apps/gateway/src/middleware/validate.d.ts.map +1 -0
  158. package/apps/gateway/dist/apps/gateway/src/middleware/validate.js +156 -0
  159. package/apps/gateway/dist/apps/gateway/src/middleware/validate.js.map +1 -0
  160. package/apps/gateway/dist/apps/gateway/src/queue/config.d.ts +26 -0
  161. package/apps/gateway/dist/apps/gateway/src/queue/config.d.ts.map +1 -0
  162. package/apps/gateway/dist/apps/gateway/src/queue/config.js +21 -0
  163. package/apps/gateway/dist/apps/gateway/src/queue/config.js.map +1 -0
  164. package/apps/gateway/dist/apps/gateway/src/queue/index.d.ts +13 -0
  165. package/apps/gateway/dist/apps/gateway/src/queue/index.d.ts.map +1 -0
  166. package/apps/gateway/dist/apps/gateway/src/queue/index.js +152 -0
  167. package/apps/gateway/dist/apps/gateway/src/queue/index.js.map +1 -0
  168. package/apps/gateway/dist/apps/gateway/src/queue/processor.d.ts +16 -0
  169. package/apps/gateway/dist/apps/gateway/src/queue/processor.d.ts.map +1 -0
  170. package/apps/gateway/dist/apps/gateway/src/queue/processor.js +316 -0
  171. package/apps/gateway/dist/apps/gateway/src/queue/processor.js.map +1 -0
  172. package/apps/gateway/dist/apps/gateway/src/routes/ai-providers-simple.d.ts +3 -0
  173. package/apps/gateway/dist/apps/gateway/src/routes/ai-providers-simple.d.ts.map +1 -0
  174. package/apps/gateway/dist/apps/gateway/src/routes/ai-providers-simple.js +116 -0
  175. package/apps/gateway/dist/apps/gateway/src/routes/ai-providers-simple.js.map +1 -0
  176. package/apps/gateway/dist/apps/gateway/src/routes/ai-providers.d.ts +3 -0
  177. package/apps/gateway/dist/apps/gateway/src/routes/ai-providers.d.ts.map +1 -0
  178. package/apps/gateway/dist/apps/gateway/src/routes/ai-providers.js +157 -0
  179. package/apps/gateway/dist/apps/gateway/src/routes/ai-providers.js.map +1 -0
  180. package/apps/gateway/dist/apps/gateway/src/routes/chats.d.ts +3 -0
  181. package/apps/gateway/dist/apps/gateway/src/routes/chats.d.ts.map +1 -0
  182. package/apps/gateway/dist/apps/gateway/src/routes/chats.js +150 -0
  183. package/apps/gateway/dist/apps/gateway/src/routes/chats.js.map +1 -0
  184. package/apps/gateway/dist/apps/gateway/src/routes/gdpr.d.ts +3 -0
  185. package/apps/gateway/dist/apps/gateway/src/routes/gdpr.d.ts.map +1 -0
  186. package/apps/gateway/dist/apps/gateway/src/routes/gdpr.js +228 -0
  187. package/apps/gateway/dist/apps/gateway/src/routes/gdpr.js.map +1 -0
  188. package/apps/gateway/dist/apps/gateway/src/routes/mfa.d.ts +3 -0
  189. package/apps/gateway/dist/apps/gateway/src/routes/mfa.d.ts.map +1 -0
  190. package/apps/gateway/dist/apps/gateway/src/routes/mfa.js +191 -0
  191. package/apps/gateway/dist/apps/gateway/src/routes/mfa.js.map +1 -0
  192. package/apps/gateway/dist/apps/gateway/src/routes/sentinel-policies.d.ts +3 -0
  193. package/apps/gateway/dist/apps/gateway/src/routes/sentinel-policies.d.ts.map +1 -0
  194. package/apps/gateway/dist/apps/gateway/src/routes/sentinel-policies.js +142 -0
  195. package/apps/gateway/dist/apps/gateway/src/routes/sentinel-policies.js.map +1 -0
  196. package/apps/gateway/dist/apps/gateway/src/routes/sentinel-predictive.d.ts +3 -0
  197. package/apps/gateway/dist/apps/gateway/src/routes/sentinel-predictive.d.ts.map +1 -0
  198. package/apps/gateway/dist/apps/gateway/src/routes/sentinel-predictive.js +82 -0
  199. package/apps/gateway/dist/apps/gateway/src/routes/sentinel-predictive.js.map +1 -0
  200. package/apps/gateway/dist/apps/gateway/src/routes/shield.d.ts +3 -0
  201. package/apps/gateway/dist/apps/gateway/src/routes/shield.d.ts.map +1 -0
  202. package/apps/gateway/dist/apps/gateway/src/routes/shield.js +71 -0
  203. package/apps/gateway/dist/apps/gateway/src/routes/shield.js.map +1 -0
  204. package/apps/gateway/dist/apps/gateway/src/routes/tool-credentials.d.ts +3 -0
  205. package/apps/gateway/dist/apps/gateway/src/routes/tool-credentials.d.ts.map +1 -0
  206. package/apps/gateway/dist/apps/gateway/src/routes/tool-credentials.js +194 -0
  207. package/apps/gateway/dist/apps/gateway/src/routes/tool-credentials.js.map +1 -0
  208. package/apps/gateway/dist/apps/gateway/src/routes/tool-proxy.d.ts +3 -0
  209. package/apps/gateway/dist/apps/gateway/src/routes/tool-proxy.d.ts.map +1 -0
  210. package/apps/gateway/dist/apps/gateway/src/routes/tool-proxy.js +187 -0
  211. package/apps/gateway/dist/apps/gateway/src/routes/tool-proxy.js.map +1 -0
  212. package/apps/gateway/dist/apps/gateway/src/runs/index.d.ts +5 -0
  213. package/apps/gateway/dist/apps/gateway/src/runs/index.d.ts.map +1 -0
  214. package/apps/gateway/dist/apps/gateway/src/runs/index.js +19 -0
  215. package/apps/gateway/dist/apps/gateway/src/runs/index.js.map +1 -0
  216. package/apps/gateway/dist/apps/gateway/src/runs/memoryRunStore.d.ts +12 -0
  217. package/apps/gateway/dist/apps/gateway/src/runs/memoryRunStore.d.ts.map +1 -0
  218. package/apps/gateway/dist/apps/gateway/src/runs/memoryRunStore.js +78 -0
  219. package/apps/gateway/dist/apps/gateway/src/runs/memoryRunStore.js.map +1 -0
  220. package/apps/gateway/dist/apps/gateway/src/runs/postgresRunStore.d.ts +15 -0
  221. package/apps/gateway/dist/apps/gateway/src/runs/postgresRunStore.d.ts.map +1 -0
  222. package/apps/gateway/dist/apps/gateway/src/runs/postgresRunStore.js +148 -0
  223. package/apps/gateway/dist/apps/gateway/src/runs/postgresRunStore.js.map +1 -0
  224. package/apps/gateway/dist/apps/gateway/src/runs/runStore.d.ts +10 -0
  225. package/apps/gateway/dist/apps/gateway/src/runs/runStore.d.ts.map +1 -0
  226. package/apps/gateway/dist/apps/gateway/src/runs/runStore.js +2 -0
  227. package/apps/gateway/dist/apps/gateway/src/runs/runStore.js.map +1 -0
  228. package/apps/gateway/dist/apps/gateway/src/runs/types.d.ts +44 -0
  229. package/apps/gateway/dist/apps/gateway/src/runs/types.d.ts.map +1 -0
  230. package/apps/gateway/dist/apps/gateway/src/runs/types.js +2 -0
  231. package/apps/gateway/dist/apps/gateway/src/runs/types.js.map +1 -0
  232. package/apps/gateway/dist/apps/gateway/src/schemas/runs.d.ts +126 -0
  233. package/apps/gateway/dist/apps/gateway/src/schemas/runs.d.ts.map +1 -0
  234. package/apps/gateway/dist/apps/gateway/src/schemas/runs.js +63 -0
  235. package/apps/gateway/dist/apps/gateway/src/schemas/runs.js.map +1 -0
  236. package/apps/gateway/dist/apps/gateway/src/utils/circuit-breaker.d.ts +13 -0
  237. package/apps/gateway/dist/apps/gateway/src/utils/circuit-breaker.d.ts.map +1 -0
  238. package/apps/gateway/dist/apps/gateway/src/utils/circuit-breaker.js +72 -0
  239. package/apps/gateway/dist/apps/gateway/src/utils/circuit-breaker.js.map +1 -0
  240. package/apps/gateway/dist/apps/gateway/src/utils/log-encryption.d.ts +10 -0
  241. package/apps/gateway/dist/apps/gateway/src/utils/log-encryption.d.ts.map +1 -0
  242. package/apps/gateway/dist/apps/gateway/src/utils/log-encryption.js +140 -0
  243. package/apps/gateway/dist/apps/gateway/src/utils/log-encryption.js.map +1 -0
  244. package/apps/gateway/dist/packages/adapters/redis/IdempotencyStore.d.ts +41 -0
  245. package/apps/gateway/dist/packages/adapters/redis/IdempotencyStore.d.ts.map +1 -0
  246. package/apps/gateway/dist/packages/adapters/redis/IdempotencyStore.js +127 -0
  247. package/apps/gateway/dist/packages/adapters/redis/IdempotencyStore.js.map +1 -0
  248. package/apps/gateway/dist/packages/middleware/idempotency/idempotency.d.ts +45 -0
  249. package/apps/gateway/dist/packages/middleware/idempotency/idempotency.d.ts.map +1 -0
  250. package/apps/gateway/dist/packages/middleware/idempotency/idempotency.js +145 -0
  251. package/apps/gateway/dist/packages/middleware/idempotency/idempotency.js.map +1 -0
  252. package/apps/gateway/dist/src/api/admin.d.ts +7 -0
  253. package/apps/gateway/dist/src/api/admin.d.ts.map +1 -0
  254. package/apps/gateway/dist/src/api/admin.js +275 -0
  255. package/apps/gateway/dist/src/api/admin.js.map +1 -0
  256. package/apps/gateway/dist/src/api/agents.d.ts +3 -0
  257. package/apps/gateway/dist/src/api/agents.d.ts.map +1 -0
  258. package/apps/gateway/dist/src/api/agents.js +66 -0
  259. package/apps/gateway/dist/src/api/agents.js.map +1 -0
  260. package/apps/gateway/dist/src/api/proxy.d.ts +3 -0
  261. package/apps/gateway/dist/src/api/proxy.d.ts.map +1 -0
  262. package/apps/gateway/dist/src/api/proxy.js +373 -0
  263. package/apps/gateway/dist/src/api/proxy.js.map +1 -0
  264. package/apps/gateway/dist/src/api/tokens.d.ts +3 -0
  265. package/apps/gateway/dist/src/api/tokens.d.ts.map +1 -0
  266. package/apps/gateway/dist/src/api/tokens.js +116 -0
  267. package/apps/gateway/dist/src/api/tokens.js.map +1 -0
  268. package/apps/gateway/dist/src/crypto/envelope.d.ts +26 -0
  269. package/apps/gateway/dist/src/crypto/envelope.d.ts.map +1 -0
  270. package/apps/gateway/dist/src/crypto/envelope.js +100 -0
  271. package/apps/gateway/dist/src/crypto/envelope.js.map +1 -0
  272. package/apps/gateway/dist/src/models/memory-db.d.ts +149 -0
  273. package/apps/gateway/dist/src/models/memory-db.d.ts.map +1 -0
  274. package/apps/gateway/dist/src/models/memory-db.js +295 -0
  275. package/apps/gateway/dist/src/models/memory-db.js.map +1 -0
  276. package/apps/gateway/dist/src/observability/metrics.d.ts +62 -0
  277. package/apps/gateway/dist/src/observability/metrics.d.ts.map +1 -0
  278. package/apps/gateway/dist/src/observability/metrics.js +205 -0
  279. package/apps/gateway/dist/src/observability/metrics.js.map +1 -0
  280. package/apps/gateway/dist/src/policies/validators.d.ts +147 -0
  281. package/apps/gateway/dist/src/policies/validators.d.ts.map +1 -0
  282. package/apps/gateway/dist/src/policies/validators.js +105 -0
  283. package/apps/gateway/dist/src/policies/validators.js.map +1 -0
  284. package/apps/gateway/dist/src/runtime/cache.d.ts +31 -0
  285. package/apps/gateway/dist/src/runtime/cache.d.ts.map +1 -0
  286. package/apps/gateway/dist/src/runtime/cache.js +142 -0
  287. package/apps/gateway/dist/src/runtime/cache.js.map +1 -0
  288. package/apps/gateway/dist/src/runtime/circuit.d.ts +57 -0
  289. package/apps/gateway/dist/src/runtime/circuit.d.ts.map +1 -0
  290. package/apps/gateway/dist/src/runtime/circuit.js +173 -0
  291. package/apps/gateway/dist/src/runtime/circuit.js.map +1 -0
  292. package/apps/gateway/dist/src/runtime/http.d.ts +62 -0
  293. package/apps/gateway/dist/src/runtime/http.d.ts.map +1 -0
  294. package/apps/gateway/dist/src/runtime/http.js +102 -0
  295. package/apps/gateway/dist/src/runtime/http.js.map +1 -0
  296. package/apps/gateway/dist/src/runtime/lifecycle.d.ts +49 -0
  297. package/apps/gateway/dist/src/runtime/lifecycle.d.ts.map +1 -0
  298. package/apps/gateway/dist/src/runtime/lifecycle.js +155 -0
  299. package/apps/gateway/dist/src/runtime/lifecycle.js.map +1 -0
  300. package/apps/gateway/dist/src/runtime/retry.d.ts +33 -0
  301. package/apps/gateway/dist/src/runtime/retry.d.ts.map +1 -0
  302. package/apps/gateway/dist/src/runtime/retry.js +122 -0
  303. package/apps/gateway/dist/src/runtime/retry.js.map +1 -0
  304. package/apps/gateway/dist/src/secrets/provider.d.ts +50 -0
  305. package/apps/gateway/dist/src/secrets/provider.d.ts.map +1 -0
  306. package/apps/gateway/dist/src/secrets/provider.js +189 -0
  307. package/apps/gateway/dist/src/secrets/provider.js.map +1 -0
  308. package/apps/gateway/dist/src/sentinel/config.d.ts +25 -0
  309. package/apps/gateway/dist/src/sentinel/config.d.ts.map +1 -0
  310. package/apps/gateway/dist/src/sentinel/config.js +179 -0
  311. package/apps/gateway/dist/src/sentinel/config.js.map +1 -0
  312. package/apps/gateway/dist/src/sentinel/judge.d.ts +24 -0
  313. package/apps/gateway/dist/src/sentinel/judge.d.ts.map +1 -0
  314. package/apps/gateway/dist/src/sentinel/judge.js +275 -0
  315. package/apps/gateway/dist/src/sentinel/judge.js.map +1 -0
  316. package/apps/gateway/dist/src/sentinel/middleware.d.ts +19 -0
  317. package/apps/gateway/dist/src/sentinel/middleware.d.ts.map +1 -0
  318. package/apps/gateway/dist/src/sentinel/middleware.js +231 -0
  319. package/apps/gateway/dist/src/sentinel/middleware.js.map +1 -0
  320. package/apps/gateway/dist/src/sentinel/shield.d.ts +116 -0
  321. package/apps/gateway/dist/src/sentinel/shield.d.ts.map +1 -0
  322. package/apps/gateway/dist/src/sentinel/shield.js +344 -0
  323. package/apps/gateway/dist/src/sentinel/shield.js.map +1 -0
  324. package/apps/gateway/dist/src/sentinel/telemetry.d.ts +79 -0
  325. package/apps/gateway/dist/src/sentinel/telemetry.d.ts.map +1 -0
  326. package/apps/gateway/dist/src/sentinel/telemetry.js +313 -0
  327. package/apps/gateway/dist/src/sentinel/telemetry.js.map +1 -0
  328. package/apps/gateway/dist/src/sentinel/types.d.ts +283 -0
  329. package/apps/gateway/dist/src/sentinel/types.d.ts.map +1 -0
  330. package/apps/gateway/dist/src/sentinel/types.js +2 -0
  331. package/apps/gateway/dist/src/sentinel/types.js.map +1 -0
  332. package/apps/gateway/dist/src/services/4runr-cipher.d.ts +9 -0
  333. package/apps/gateway/dist/src/services/4runr-cipher.d.ts.map +1 -0
  334. package/apps/gateway/dist/src/services/4runr-cipher.js +64 -0
  335. package/apps/gateway/dist/src/services/4runr-cipher.js.map +1 -0
  336. package/apps/gateway/dist/src/services/policyEngine.d.ts +17 -0
  337. package/apps/gateway/dist/src/services/policyEngine.d.ts.map +1 -0
  338. package/apps/gateway/dist/src/services/policyEngine.js +310 -0
  339. package/apps/gateway/dist/src/services/policyEngine.js.map +1 -0
  340. package/apps/gateway/dist/src/tools/gmail-send.d.ts +19 -0
  341. package/apps/gateway/dist/src/tools/gmail-send.d.ts.map +1 -0
  342. package/apps/gateway/dist/src/tools/gmail-send.js +120 -0
  343. package/apps/gateway/dist/src/tools/gmail-send.js.map +1 -0
  344. package/apps/gateway/dist/src/tools/http-fetch.d.ts +13 -0
  345. package/apps/gateway/dist/src/tools/http-fetch.d.ts.map +1 -0
  346. package/apps/gateway/dist/src/tools/http-fetch.js +86 -0
  347. package/apps/gateway/dist/src/tools/http-fetch.js.map +1 -0
  348. package/apps/gateway/dist/src/tools/index.d.ts +71 -0
  349. package/apps/gateway/dist/src/tools/index.d.ts.map +1 -0
  350. package/apps/gateway/dist/src/tools/index.js +99 -0
  351. package/apps/gateway/dist/src/tools/index.js.map +1 -0
  352. package/apps/gateway/dist/src/tools/mock/gmail_send.mock.d.ts +12 -0
  353. package/apps/gateway/dist/src/tools/mock/gmail_send.mock.d.ts.map +1 -0
  354. package/apps/gateway/dist/src/tools/mock/gmail_send.mock.js +10 -0
  355. package/apps/gateway/dist/src/tools/mock/gmail_send.mock.js.map +1 -0
  356. package/apps/gateway/dist/src/tools/mock/http_fetch.mock.d.ts +13 -0
  357. package/apps/gateway/dist/src/tools/mock/http_fetch.mock.d.ts.map +1 -0
  358. package/apps/gateway/dist/src/tools/mock/http_fetch.mock.js +10 -0
  359. package/apps/gateway/dist/src/tools/mock/http_fetch.mock.js.map +1 -0
  360. package/apps/gateway/dist/src/tools/mock/openai.mock.d.ts +9 -0
  361. package/apps/gateway/dist/src/tools/mock/openai.mock.d.ts.map +1 -0
  362. package/apps/gateway/dist/src/tools/mock/openai.mock.js +8 -0
  363. package/apps/gateway/dist/src/tools/mock/openai.mock.js.map +1 -0
  364. package/apps/gateway/dist/src/tools/mock/serpapi.mock.d.ts +15 -0
  365. package/apps/gateway/dist/src/tools/mock/serpapi.mock.d.ts.map +1 -0
  366. package/apps/gateway/dist/src/tools/mock/serpapi.mock.js +12 -0
  367. package/apps/gateway/dist/src/tools/mock/serpapi.mock.js.map +1 -0
  368. package/apps/gateway/dist/src/tools/openai.d.ts +27 -0
  369. package/apps/gateway/dist/src/tools/openai.d.ts.map +1 -0
  370. package/apps/gateway/dist/src/tools/openai.js +100 -0
  371. package/apps/gateway/dist/src/tools/openai.js.map +1 -0
  372. package/apps/gateway/dist/src/tools/serpapi.d.ts +16 -0
  373. package/apps/gateway/dist/src/tools/serpapi.d.ts.map +1 -0
  374. package/apps/gateway/dist/src/tools/serpapi.js +56 -0
  375. package/apps/gateway/dist/src/tools/serpapi.js.map +1 -0
  376. package/apps/gateway/dist/src/types/policy.d.ts +221 -0
  377. package/apps/gateway/dist/src/types/policy.d.ts.map +1 -0
  378. package/apps/gateway/dist/src/types/policy.js +60 -0
  379. package/apps/gateway/dist/src/types/policy.js.map +1 -0
  380. package/apps/gateway/dist/src/utils/token-utils.d.ts +5 -0
  381. package/apps/gateway/dist/src/utils/token-utils.d.ts.map +1 -0
  382. package/apps/gateway/dist/src/utils/token-utils.js +28 -0
  383. package/apps/gateway/dist/src/utils/token-utils.js.map +1 -0
  384. package/apps/gateway/find-gateway.sh +37 -0
  385. package/apps/gateway/jest.config.cjs +50 -0
  386. package/apps/gateway/load-tests/README.md +107 -0
  387. package/apps/gateway/load-tests/k6-basic.js +128 -0
  388. package/apps/gateway/load-tests/k6-rate-limit.js +57 -0
  389. package/apps/gateway/minimal-test.sh +60 -0
  390. package/apps/gateway/package.json +66 -0
  391. package/apps/gateway/public/sentinel-dashboard.html +428 -0
  392. package/apps/gateway/quick-debug.sh +70 -0
  393. package/apps/gateway/scripts/seed-api-key.ts +63 -0
  394. package/apps/gateway/scripts/setup-test-env.sh +67 -0
  395. package/apps/gateway/simple-test.sh +72 -0
  396. package/apps/gateway/src/__tests__/auth.test.ts +272 -0
  397. package/apps/gateway/src/__tests__/devkit-api.test.ts +268 -0
  398. package/apps/gateway/src/__tests__/integration/README.md +86 -0
  399. package/apps/gateway/src/__tests__/integration/authentication.test.ts +155 -0
  400. package/apps/gateway/src/__tests__/integration/e2e-comprehensive-fixed.test.ts +368 -0
  401. package/apps/gateway/src/__tests__/integration/e2e-workflow.test.ts +239 -0
  402. package/apps/gateway/src/__tests__/integration/helpers/test-server.ts +142 -0
  403. package/apps/gateway/src/__tests__/integration/idempotency.test.ts +213 -0
  404. package/apps/gateway/src/__tests__/integration/postgres-persistence.test.ts +173 -0
  405. package/apps/gateway/src/__tests__/integration/rate-limiting.test.ts +148 -0
  406. package/apps/gateway/src/__tests__/integration/sentinel.test.ts +152 -0
  407. package/apps/gateway/src/__tests__/no-persistence-mode.test.ts +180 -0
  408. package/apps/gateway/src/__tests__/rateLimit.test.ts +107 -0
  409. package/apps/gateway/src/__tests__/validation.test.ts +290 -0
  410. package/apps/gateway/src/adapters/redis-sentinel-publisher.ts +47 -0
  411. package/apps/gateway/src/adapters/sentinel-event-stream.ts +106 -0
  412. package/apps/gateway/src/agents/definitions-simple.ts +531 -0
  413. package/apps/gateway/src/agents/definitions.ts +297 -0
  414. package/apps/gateway/src/agents/local-model-provider.ts +219 -0
  415. package/apps/gateway/src/agents/tools.ts +163 -0
  416. package/apps/gateway/src/ai-providers/anthropic-provider.ts +194 -0
  417. package/apps/gateway/src/ai-providers/index.ts +10 -0
  418. package/apps/gateway/src/ai-providers/openai-provider.ts +193 -0
  419. package/apps/gateway/src/ai-providers/provider-manager.ts +160 -0
  420. package/apps/gateway/src/ai-providers/redis-credentials-store.ts +220 -0
  421. package/apps/gateway/src/ai-providers/types.ts +75 -0
  422. package/apps/gateway/src/config/persistence.ts +38 -0
  423. package/apps/gateway/src/crypto/envelope.ts +184 -0
  424. package/apps/gateway/src/db/prisma.ts +58 -0
  425. package/apps/gateway/src/db/redis.ts +95 -0
  426. package/apps/gateway/src/devkit/agents-api.ts +486 -0
  427. package/apps/gateway/src/devkit/metrics-parser.ts +152 -0
  428. package/apps/gateway/src/devkit/middleware.ts +53 -0
  429. package/apps/gateway/src/devkit/routes.ts +344 -0
  430. package/apps/gateway/src/devkit/tools-api.ts +251 -0
  431. package/apps/gateway/src/health/index.ts +257 -0
  432. package/apps/gateway/src/index.ts +1288 -0
  433. package/apps/gateway/src/metrics/index.ts +218 -0
  434. package/apps/gateway/src/middleware/auth.ts +118 -0
  435. package/apps/gateway/src/middleware/authApiKey.ts +156 -0
  436. package/apps/gateway/src/middleware/authJwt.ts +129 -0
  437. package/apps/gateway/src/middleware/correlationId.ts +36 -0
  438. package/apps/gateway/src/middleware/ddos-protection.ts +286 -0
  439. package/apps/gateway/src/middleware/errorHandler.ts +168 -0
  440. package/apps/gateway/src/middleware/mfa.ts +137 -0
  441. package/apps/gateway/src/middleware/rateLimit.ts +104 -0
  442. package/apps/gateway/src/middleware/rbac.ts +301 -0
  443. package/apps/gateway/src/middleware/security.ts +116 -0
  444. package/apps/gateway/src/middleware/validate.ts +194 -0
  445. package/apps/gateway/src/middleware/validate.ts.backup +153 -0
  446. package/apps/gateway/src/queue/config.ts +61 -0
  447. package/apps/gateway/src/queue/index.ts +229 -0
  448. package/apps/gateway/src/queue/processor.ts +461 -0
  449. package/apps/gateway/src/routes/ai-providers-simple.ts +166 -0
  450. package/apps/gateway/src/routes/ai-providers.ts +235 -0
  451. package/apps/gateway/src/routes/chats.ts +177 -0
  452. package/apps/gateway/src/routes/gdpr.ts +299 -0
  453. package/apps/gateway/src/routes/mfa.ts +254 -0
  454. package/apps/gateway/src/routes/sentinel-policies.ts +204 -0
  455. package/apps/gateway/src/routes/sentinel-predictive.ts +119 -0
  456. package/apps/gateway/src/routes/shield.ts +114 -0
  457. package/apps/gateway/src/routes/tool-credentials.ts +282 -0
  458. package/apps/gateway/src/routes/tool-proxy.ts +303 -0
  459. package/apps/gateway/src/runs/index.ts +34 -0
  460. package/apps/gateway/src/runs/memoryRunStore.ts +105 -0
  461. package/apps/gateway/src/runs/postgresRunStore.ts +186 -0
  462. package/apps/gateway/src/runs/runStore.ts +17 -0
  463. package/apps/gateway/src/runs/types.ts +58 -0
  464. package/apps/gateway/src/schemas/runs.ts +115 -0
  465. package/apps/gateway/src/types/fastify-rate-limit.d.ts +12 -0
  466. package/apps/gateway/src/utils/circuit-breaker.ts +134 -0
  467. package/apps/gateway/src/utils/log-encryption.ts +212 -0
  468. package/apps/gateway/test-all-individual.sh +69 -0
  469. package/apps/gateway/test-all-phases-final.sh +568 -0
  470. package/apps/gateway/test-all-phases-fixed-v2.sh +523 -0
  471. package/apps/gateway/test-all-phases-fixed.sh +385 -0
  472. package/apps/gateway/test-all-phases.sh +663 -0
  473. package/apps/gateway/test-concurrency.sh +60 -0
  474. package/apps/gateway/test-debug.sh +44 -0
  475. package/apps/gateway/test-e2e.sh +96 -0
  476. package/apps/gateway/test-extraction.sh +48 -0
  477. package/apps/gateway/test-full-operations-final.sh +328 -0
  478. package/apps/gateway/test-full-operations.sh +326 -0
  479. package/apps/gateway/test-idempotency-only.sh +108 -0
  480. package/apps/gateway/test-idempotency.sh +97 -0
  481. package/apps/gateway/test-individual.sh +126 -0
  482. package/apps/gateway/test-queue.sh +94 -0
  483. package/apps/gateway/tsconfig.json +32 -0
  484. package/apps/gateway/update-and-test.sh +36 -0
  485. package/dist/tui-handlers.js +8 -7
  486. package/dist/tui-handlers.js.map +1 -1
  487. package/mk3-tui/binaries/win32-x64/mk3-tui.exe +0 -0
  488. package/mk3-tui/src/main.rs +9 -19
  489. package/mk3-tui/src/ui/layout.rs +1 -1
  490. package/package.json +6 -3
@@ -0,0 +1,11 @@
1
+ # Exclude client-side packages that aren't needed on server
2
+ packages/os-cli
3
+ packages/cli
4
+ packages/cli-tool
5
+ packages/cli-tool-standalone
6
+
7
+ # Exclude other client-side files
8
+ 4runr-os-enhanced.ts
9
+ 4runr-os.ts
10
+ run-os.ps1
11
+
@@ -0,0 +1,28 @@
1
+ {
2
+ "root": true,
3
+ "parser": "@typescript-eslint/parser",
4
+ "parserOptions": {
5
+ "ecmaVersion": 2022,
6
+ "sourceType": "module"
7
+ },
8
+ "plugins": ["@typescript-eslint"],
9
+ "extends": [
10
+ "eslint:recommended",
11
+ "plugin:@typescript-eslint/recommended"
12
+ ],
13
+ "rules": {
14
+ "@typescript-eslint/no-explicit-any": "off",
15
+ "@typescript-eslint/no-unused-vars": "warn",
16
+ "@typescript-eslint/no-non-null-assertion": "off"
17
+ },
18
+ "env": {
19
+ "node": true,
20
+ "es2022": true
21
+ },
22
+ "ignorePatterns": [
23
+ "**/__tests__/**",
24
+ "**/*.test.ts",
25
+ "dist/**"
26
+ ]
27
+ }
28
+
@@ -0,0 +1,426 @@
1
+ # Deployment Guide
2
+
3
+ Complete guide for deploying the 4Runr Gateway to production.
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Prerequisites](#prerequisites)
8
+ 2. [Pre-Deployment Checklist](#pre-deployment-checklist)
9
+ 3. [Environment Setup](#environment-setup)
10
+ 4. [Database Setup](#database-setup)
11
+ 5. [Deployment Methods](#deployment-methods)
12
+ 6. [Post-Deployment Verification](#post-deployment-verification)
13
+ 7. [Rollback Procedures](#rollback-procedures)
14
+ 8. [Scaling](#scaling)
15
+
16
+ ## Prerequisites
17
+
18
+ ### Infrastructure Requirements
19
+
20
+ - **PostgreSQL 12+**: For persistent storage
21
+ - **Redis 6+**: For queue, rate limiting, and idempotency
22
+ - **Docker & Docker Compose**: For containerized deployment (recommended)
23
+ - **Node.js 18+**: For direct deployment (alternative)
24
+
25
+ ### Security Requirements
26
+
27
+ - Strong database passwords
28
+ - Secure JWT secrets (min 32 characters)
29
+ - Encryption keys for sensitive data
30
+ - SSL/TLS certificates for HTTPS
31
+ - Firewall rules configured
32
+
33
+ ### Network Requirements
34
+
35
+ - Port 3000: Gateway API (or configure reverse proxy)
36
+ - Port 5432: PostgreSQL (internal only)
37
+ - Port 6379: Redis (internal only)
38
+
39
+ ## Pre-Deployment Checklist
40
+
41
+ - [ ] All environment variables configured
42
+ - [ ] Database migrations tested
43
+ - [ ] Secrets generated and stored securely
44
+ - [ ] Health checks configured
45
+ - [ ] Monitoring and alerting set up
46
+ - [ ] Backup strategy in place
47
+ - [ ] Rollback plan documented
48
+ - [ ] Load testing completed
49
+ - [ ] Security audit performed
50
+
51
+ ## Environment Setup
52
+
53
+ ### 1. Generate Secure Secrets
54
+
55
+ ```bash
56
+ # Generate JWT secret
57
+ openssl rand -base64 32
58
+
59
+ # Generate encryption key
60
+ openssl rand -base64 32
61
+
62
+ # Generate API keys (if using memory mode)
63
+ openssl rand -hex 32
64
+ ```
65
+
66
+ ### 2. Create Production Environment File
67
+
68
+ ```bash
69
+ cd infra
70
+ cp env.example .env.production
71
+ ```
72
+
73
+ Edit `.env.production` with production values:
74
+
75
+ ```bash
76
+ NODE_ENV=production
77
+ GATEWAY_PERSISTENCE=postgres
78
+ DATABASE_URL=postgresql://user:strong-password@db-host:5432/4runr_gateway
79
+ REDIS_URL=redis://redis-host:6379
80
+
81
+ AUTH_ENABLED=true
82
+ AUTH_MODE=mixed
83
+ JWT_SECRET=<generated-secret>
84
+ JWT_ALG=HS256
85
+
86
+ RATE_LIMIT_ENABLED=true
87
+ RATE_LIMIT_MAX=100
88
+ RATE_LIMIT_WINDOW_MS=60000
89
+
90
+ SENTINEL_STORE_PLAIN=false
91
+ SENTINEL_MODE=live
92
+ SENTINEL_SHIELD_MODE=enforce
93
+
94
+ LOG_LEVEL=warn
95
+ ```
96
+
97
+ ### 3. Store Secrets Securely
98
+
99
+ **DO NOT** commit secrets to version control. Use:
100
+ - Environment variable management (AWS Secrets Manager, HashiCorp Vault, etc.)
101
+ - Docker secrets
102
+ - Kubernetes secrets
103
+ - CI/CD secret management
104
+
105
+ ## Database Setup
106
+
107
+ ### 1. Create Database
108
+
109
+ ```sql
110
+ CREATE DATABASE 4runr_gateway;
111
+ CREATE USER 4runr WITH PASSWORD 'strong-password';
112
+ GRANT ALL PRIVILEGES ON DATABASE 4runr_gateway TO 4runr;
113
+ ```
114
+
115
+ ### 2. Run Migrations
116
+
117
+ ```bash
118
+ cd apps/gateway
119
+ pnpm db:generate
120
+ pnpm db:migrate
121
+ ```
122
+
123
+ Or via Docker:
124
+ ```bash
125
+ docker-compose -f infra/docker-compose.prod.yml run --rm gateway pnpm db:migrate
126
+ ```
127
+
128
+ ### 3. Seed Initial Data (Optional)
129
+
130
+ ```bash
131
+ # Seed API key
132
+ pnpm seed:api-key
133
+ ```
134
+
135
+ ## Deployment Methods
136
+
137
+ ### Method 1: Docker Compose (Recommended)
138
+
139
+ **Best for**: Single server deployments, small to medium scale
140
+
141
+ 1. **Build and start:**
142
+ ```bash
143
+ cd infra
144
+ docker-compose -f docker-compose.prod.yml up -d --build
145
+ ```
146
+
147
+ 2. **Verify services:**
148
+ ```bash
149
+ docker-compose -f docker-compose.prod.yml ps
150
+ docker-compose -f docker-compose.prod.yml logs -f gateway
151
+ ```
152
+
153
+ 3. **Check health:**
154
+ ```bash
155
+ curl http://localhost:3000/health
156
+ curl http://localhost:3000/ready
157
+ ```
158
+
159
+ ### Method 2: Kubernetes
160
+
161
+ **Best for**: Large scale, high availability
162
+
163
+ 1. **Create namespace:**
164
+ ```bash
165
+ kubectl create namespace 4runr-gateway
166
+ ```
167
+
168
+ 2. **Create secrets:**
169
+ ```bash
170
+ kubectl create secret generic gateway-secrets \
171
+ --from-literal=jwt-secret='your-secret' \
172
+ --from-literal=database-url='postgresql://...' \
173
+ --namespace=4runr-gateway
174
+ ```
175
+
176
+ 3. **Deploy:**
177
+ ```bash
178
+ kubectl apply -f k8s/gateway-deployment.yaml
179
+ kubectl apply -f k8s/gateway-service.yaml
180
+ ```
181
+
182
+ ### Method 3: Direct Node.js
183
+
184
+ **Best for**: Development, custom deployments
185
+
186
+ 1. **Build:**
187
+ ```bash
188
+ cd apps/gateway
189
+ pnpm install
190
+ pnpm build
191
+ ```
192
+
193
+ 2. **Start:**
194
+ ```bash
195
+ NODE_ENV=production node dist/index.js
196
+ ```
197
+
198
+ Or use PM2:
199
+ ```bash
200
+ pm2 start dist/index.js --name gateway
201
+ pm2 save
202
+ pm2 startup
203
+ ```
204
+
205
+ ## Post-Deployment Verification
206
+
207
+ ### 1. Health Checks
208
+
209
+ ```bash
210
+ # Liveness
211
+ curl http://your-server/health
212
+ # Expected: {"status":"ok"}
213
+
214
+ # Readiness
215
+ curl http://your-server/ready
216
+ # Expected: {"ready":true,"checks":{...}}
217
+
218
+ # Startup
219
+ curl http://your-server/startup
220
+ # Expected: {"started":true}
221
+ ```
222
+
223
+ ### 2. API Functionality
224
+
225
+ ```bash
226
+ # Create a run
227
+ curl -X POST http://your-server/api/runs \
228
+ -H "x-api-key: your-key" \
229
+ -H "Content-Type: application/json" \
230
+ -d '{"name": "Test Run", "input": {}}'
231
+
232
+ # List runs
233
+ curl http://your-server/api/runs \
234
+ -H "x-api-key: your-key"
235
+
236
+ # Check metrics
237
+ curl http://your-server/metrics
238
+ ```
239
+
240
+ ### 3. Monitor Logs
241
+
242
+ ```bash
243
+ # Docker
244
+ docker-compose -f infra/docker-compose.prod.yml logs -f gateway
245
+
246
+ # Kubernetes
247
+ kubectl logs -f deployment/gateway -n 4runr-gateway
248
+
249
+ # PM2
250
+ pm2 logs gateway
251
+ ```
252
+
253
+ ### 4. Check Metrics
254
+
255
+ Access Prometheus metrics at `/metrics` and verify:
256
+ - HTTP request counts
257
+ - Run creation/start/completion rates
258
+ - Error rates
259
+ - Queue job metrics
260
+ - Rate limit hits
261
+
262
+ ## Rollback Procedures
263
+
264
+ ### Quick Rollback (Docker Compose)
265
+
266
+ ```bash
267
+ cd infra
268
+
269
+ # Stop current version
270
+ docker-compose -f docker-compose.prod.yml down
271
+
272
+ # Switch to previous version
273
+ git checkout <previous-version-tag>
274
+
275
+ # Rebuild and start
276
+ docker-compose -f docker-compose.prod.yml up -d --build
277
+ ```
278
+
279
+ ### Database Rollback
280
+
281
+ If migrations need to be rolled back:
282
+
283
+ ```bash
284
+ cd apps/gateway
285
+ pnpm prisma migrate resolve --rolled-back <migration-name>
286
+ ```
287
+
288
+ **Warning**: Only rollback migrations if you're certain no data depends on them.
289
+
290
+ ### Configuration Rollback
291
+
292
+ ```bash
293
+ # Restore previous environment file
294
+ cp .env.production.backup .env.production
295
+
296
+ # Restart services
297
+ docker-compose -f docker-compose.prod.yml restart gateway
298
+ ```
299
+
300
+ ## Scaling
301
+
302
+ ### Horizontal Scaling
303
+
304
+ The gateway is stateless and can be scaled horizontally:
305
+
306
+ ```bash
307
+ # Docker Compose (multiple instances)
308
+ docker-compose -f docker-compose.prod.yml up -d --scale gateway=3
309
+
310
+ # Kubernetes
311
+ kubectl scale deployment gateway --replicas=3 -n 4runr-gateway
312
+ ```
313
+
314
+ ### Load Balancing
315
+
316
+ Use a load balancer (nginx, HAProxy, AWS ALB) in front of multiple gateway instances:
317
+
318
+ ```nginx
319
+ upstream gateway {
320
+ least_conn;
321
+ server gateway1:3000;
322
+ server gateway2:3000;
323
+ server gateway3:3000;
324
+ }
325
+ ```
326
+
327
+ ### Database Scaling
328
+
329
+ - Use connection pooling (Prisma handles this)
330
+ - Consider read replicas for read-heavy workloads
331
+ - Monitor connection counts
332
+
333
+ ### Redis Scaling
334
+
335
+ - Use Redis Cluster for high availability
336
+ - Configure Redis Sentinel for failover
337
+ - Monitor memory usage
338
+
339
+ ## Monitoring & Alerting
340
+
341
+ ### Key Metrics to Monitor
342
+
343
+ - **HTTP Request Rate**: Requests per second
344
+ - **Error Rate**: 4xx and 5xx errors
345
+ - **Response Time**: p50, p95, p99 latencies
346
+ - **Queue Depth**: Number of jobs waiting
347
+ - **Database Connections**: Active connections
348
+ - **Memory Usage**: Container/node memory
349
+ - **CPU Usage**: Container/node CPU
350
+
351
+ ### Recommended Alerts
352
+
353
+ - Error rate > 1%
354
+ - Response time p95 > 1s
355
+ - Queue depth > 1000
356
+ - Database connections > 80% of max
357
+ - Memory usage > 80%
358
+ - Health check failures
359
+
360
+ ## Backup & Recovery
361
+
362
+ ### Database Backups
363
+
364
+ ```bash
365
+ # Daily backup script
366
+ pg_dump -h db-host -U 4runr 4runr_gateway > backup-$(date +%Y%m%d).sql
367
+
368
+ # Restore
369
+ psql -h db-host -U 4runr 4runr_gateway < backup-20231119.sql
370
+ ```
371
+
372
+ ### Configuration Backups
373
+
374
+ ```bash
375
+ # Backup environment file
376
+ cp .env.production .env.production.backup
377
+
378
+ # Backup docker-compose
379
+ cp docker-compose.prod.yml docker-compose.prod.yml.backup
380
+ ```
381
+
382
+ ## Security Hardening
383
+
384
+ ### Production Security Checklist
385
+
386
+ - [ ] HTTPS enabled (TLS 1.2+)
387
+ - [ ] Security headers configured
388
+ - [ ] Secrets stored securely (not in code)
389
+ - [ ] Database access restricted (firewall)
390
+ - [ ] Redis access restricted (firewall)
391
+ - [ ] Rate limiting enabled
392
+ - [ ] Authentication required
393
+ - [ ] Error messages masked in production
394
+ - [ ] Logging configured (no sensitive data)
395
+ - [ ] Regular security updates
396
+
397
+ ### SSL/TLS Setup
398
+
399
+ Use a reverse proxy (nginx, Traefik) for SSL termination:
400
+
401
+ ```nginx
402
+ server {
403
+ listen 443 ssl;
404
+ server_name api.yourdomain.com;
405
+
406
+ ssl_certificate /path/to/cert.pem;
407
+ ssl_certificate_key /path/to/key.pem;
408
+
409
+ location / {
410
+ proxy_pass http://gateway:3000;
411
+ }
412
+ }
413
+ ```
414
+
415
+ ## Troubleshooting
416
+
417
+ See [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) for common deployment issues.
418
+
419
+ ## Support
420
+
421
+ For deployment issues:
422
+ - Check logs: `docker-compose logs gateway`
423
+ - Verify health: `curl http://localhost/health`
424
+ - Review metrics: `curl http://localhost/metrics`
425
+ - See troubleshooting guide
426
+
@@ -0,0 +1,122 @@
1
+ FROM node:20-slim AS base
2
+ WORKDIR /workspace
3
+ RUN apt-get update && apt-get install -y ca-certificates curl && rm -rf /var/lib/apt/lists/*
4
+
5
+ FROM base AS deps
6
+ RUN apt-get update && apt-get install -y python3 make g++ openssl libssl-dev && rm -rf /var/lib/apt/lists/*
7
+ COPY pnpm-workspace.yaml package.json tsconfig.json ./
8
+ # Copy .npmrc if it exists (optional - create empty if missing)
9
+ COPY apps/gateway ./apps/gateway
10
+ # Copy packages directory but we'll remove client-side ones immediately
11
+ COPY packages ./packages
12
+ # Remove client-side packages BEFORE pnpm reads the workspace (os-cli depends on unpublished @4runr/devkit)
13
+ RUN rm -rf packages/os-cli packages/cli packages/cli-tool packages/cli-tool-standalone packages/devkit || true
14
+ COPY prisma ./prisma
15
+ COPY src ./src
16
+ # Create .npmrc if it doesn't exist (pnpm will work without it)
17
+ RUN touch .npmrc || true
18
+ RUN corepack enable && corepack prepare pnpm@9.12.1 --activate
19
+ # Set node-linker to hoisted for flat node_modules structure
20
+ RUN pnpm config set node-linker hoisted
21
+ # Skip Prisma generation during install (we'll generate it in build if needed)
22
+ ENV PRISMA_SKIP_POSTINSTALL_GENERATE=1
23
+ RUN pnpm install --filter @4runr/shared --filter @4runr/sentinel --filter @4runr/gateway --workspace-root
24
+
25
+ FROM deps AS build
26
+ # Clean shared and sentinel package dists to ensure fresh build with updated types
27
+ RUN rm -rf packages/shared/dist packages/shared/.tsbuildinfo packages/sentinel/dist packages/sentinel/.tsbuildinfo
28
+ RUN pnpm --filter @4runr/shared run build
29
+ RUN pnpm --filter @4runr/sentinel run build
30
+ # Generate Prisma client before building gateway
31
+ # Use dummy DATABASE_URL for generation (just needs schema, not actual connection)
32
+ # Prisma schema is at /workspace/prisma/schema.prisma
33
+ RUN cd /workspace/apps/gateway && \
34
+ export DATABASE_URL="postgresql://dummy:dummy@localhost:5432/dummy" && \
35
+ pnpm db:generate && \
36
+ (test -d node_modules/.prisma/client || test -d ../../node_modules/.prisma/client) && \
37
+ echo "✓ Prisma client generated" || echo "✗ Prisma client generation failed"
38
+ # Compile root src/crypto folder (used by gateway routes)
39
+ # Create a temporary tsconfig for compiling just the crypto folder
40
+ RUN mkdir -p dist/src/crypto && \
41
+ echo '{"compilerOptions":{"target":"ES2022","module":"ES2022","moduleResolution":"bundler","esModuleInterop":true,"skipLibCheck":true,"outDir":"dist/src/crypto","rootDir":"src/crypto"},"include":["src/crypto/envelope.ts"]}' > /tmp/crypto-tsconfig.json && \
42
+ npx tsc --project /tmp/crypto-tsconfig.json 2>&1 | head -10 && \
43
+ test -f dist/src/crypto/envelope.js && echo "✓ Compiled envelope.js" || echo "⚠ envelope.js compilation may have failed"
44
+
45
+ RUN rm -rf apps/gateway/dist && \
46
+ pnpm --filter @4runr/gateway run build && \
47
+ (test -f apps/gateway/dist/index.js || test -f apps/gateway/dist/apps/gateway/src/index.js) && \
48
+ echo "✓ Gateway build completed successfully" || \
49
+ (echo "✗ Build failed: index.js not found" && exit 1)
50
+
51
+ FROM base AS runner
52
+ WORKDIR /workspace
53
+ RUN apt-get update && apt-get install -y openssl ca-certificates curl && rm -rf /var/lib/apt/lists/*
54
+ # Copy package files, config, and built artifacts
55
+ COPY --from=build /workspace/package.json ./package.json
56
+ COPY --from=build /workspace/pnpm-workspace.yaml ./pnpm-workspace.yaml
57
+ # .npmrc is optional - create empty if it doesn't exist
58
+ RUN touch .npmrc || true
59
+ COPY --from=build /workspace/packages ./packages
60
+ COPY --from=build /workspace/apps/gateway/package.json ./apps/gateway/package.json
61
+ COPY --from=build /workspace/apps/gateway/dist ./apps/gateway/dist
62
+ # Copy public directory (static files like dashboard)
63
+ COPY --from=deps /workspace/apps/gateway/public ./apps/gateway/public
64
+ # Copy node_modules from build stage (hoisted node-linker creates flat structure)
65
+ # Use --chown to set ownership during copy to avoid breaking symlinks
66
+ COPY --from=build --chown=node:node /workspace/node_modules ./node_modules
67
+ # Copy Prisma schema (needed for runtime client generation if needed)
68
+ COPY --from=build /workspace/prisma ./prisma
69
+ # Copy src directory (contains crypto and memory-db for AI providers)
70
+ COPY --from=build /workspace/src ./src
71
+ # Copy compiled crypto (if it was compiled)
72
+ RUN mkdir -p dist/src && (cp -r /workspace/dist/src/* dist/src/ 2>/dev/null || echo "Note: No compiled src found")
73
+ # Verify Prisma client was copied (could be in root node_modules with hoisted linker)
74
+ RUN (test -d node_modules/.prisma/client || test -d apps/gateway/node_modules/.prisma/client) && \
75
+ echo "✓ Prisma client found" || \
76
+ echo "⚠ Prisma client not found - checking..." && \
77
+ find node_modules -name ".prisma" -type d 2>/dev/null | head -5 || \
78
+ echo "⚠ Will generate Prisma client at runtime if needed"
79
+ # Verify shared package is accessible
80
+ RUN test -d packages/shared/dist && echo "✓ shared/dist exists" || echo "✗ shared/dist missing"
81
+ RUN test -f packages/shared/dist/index.js && echo "✓ shared/dist/index.js exists" || echo "✗ shared/dist/index.js missing"
82
+ # Check if @4runr/shared exists and if it's a symlink
83
+ # If not, create it (symlinks don't need special ownership)
84
+ RUN if [ ! -L node_modules/@4runr/shared ] && [ ! -d node_modules/@4runr/shared ]; then \
85
+ echo "✗ @4runr/shared NOT found in node_modules, creating symlink..."; \
86
+ mkdir -p node_modules/@4runr && \
87
+ ln -s ../../packages/shared node_modules/@4runr/shared && \
88
+ echo "✓ Created symlink: node_modules/@4runr/shared -> ../../packages/shared"; \
89
+ fi
90
+ # Verify the shared package's package.json exists (for ESM resolution)
91
+ RUN test -f node_modules/@4runr/shared/package.json && echo "✓ @4runr/shared/package.json exists" || echo "✗ @4runr/shared/package.json missing"
92
+ # Verify the package.json has the correct exports field for ESM resolution
93
+ RUN node -e "try { const pkg = require('./node_modules/@4runr/shared/package.json'); if (pkg.exports && pkg.exports['.']) { console.log('✓ package.json exports field configured correctly'); } else { console.error('✗ package.json missing exports field'); process.exit(1); } } catch(e) { console.error('✗ Error reading shared package.json:', e.message); process.exit(1); }"
94
+ # Verify Sentinel package is accessible
95
+ RUN test -d packages/sentinel/dist && echo "✓ sentinel/dist exists" || echo "✗ sentinel/dist missing"
96
+ RUN test -f packages/sentinel/dist/index.js && echo "✓ sentinel/dist/index.js exists" || echo "✗ sentinel/dist/index.js missing"
97
+ # Check if @4runr/sentinel exists and if it's a symlink
98
+ # If not, create it (symlinks don't need special ownership)
99
+ RUN if [ ! -L node_modules/@4runr/sentinel ] && [ ! -d node_modules/@4runr/sentinel ]; then \
100
+ echo "✗ @4runr/sentinel NOT found in node_modules, creating symlink..."; \
101
+ mkdir -p node_modules/@4runr && \
102
+ ln -s ../../packages/sentinel node_modules/@4runr/sentinel && \
103
+ echo "✓ Created symlink: node_modules/@4runr/sentinel -> ../../packages/sentinel"; \
104
+ fi
105
+ # Verify the Sentinel package's package.json exists (for ESM resolution)
106
+ RUN test -f node_modules/@4runr/sentinel/package.json && echo "✓ @4runr/sentinel/package.json exists" || echo "✗ @4runr/sentinel/package.json missing"
107
+ # Verify the package.json has the correct exports field for ESM resolution
108
+ RUN node -e "try { const pkg = require('./node_modules/@4runr/sentinel/package.json'); if (pkg.exports && pkg.exports['.']) { console.log('✓ Sentinel package.json exports field configured correctly'); } else { console.error('✗ Sentinel package.json missing exports field'); process.exit(1); } } catch(e) { console.error('✗ Error reading Sentinel package.json:', e.message); process.exit(1); }"
109
+ # Verify fastify exists (should be directly in node_modules with hoisted node-linker)
110
+ RUN test -d node_modules/fastify && echo "✓ fastify found in node_modules" || \
111
+ (echo "✗ fastify NOT found!" && ls -la node_modules/ | head -40)
112
+ RUN test -f node_modules/fastify/package.json && echo "✓ fastify package.json exists" || echo "✗ fastify package.json missing"
113
+ # Test Node.js ESM resolution from the gateway dist directory
114
+ RUN cd apps/gateway/dist && \
115
+ node --input-type=module -e "import('fastify').then(() => console.log('✓ Node.js can resolve fastify from dist')).catch(e => console.error('✗ Cannot resolve:', e.message))" || \
116
+ echo "Testing from workspace root:" && \
117
+ cd /workspace && \
118
+ node --input-type=module -e "import('fastify').then(() => console.log('✓ Node.js can resolve fastify from root')).catch(e => console.error('✗ Cannot resolve from root:', e.message))"
119
+ USER node
120
+ WORKDIR /workspace
121
+ # Run from workspace root - Node.js ESM should find node_modules at /workspace/node_modules
122
+ CMD ["node", "apps/gateway/dist/apps/gateway/src/index.js"]
@@ -0,0 +1,41 @@
1
+ FROM node:18-alpine AS base
2
+
3
+ # Install dependencies only when needed
4
+ FROM base AS deps
5
+ RUN apk add --no-cache libc6-compat
6
+ WORKDIR /app
7
+
8
+ # Install dependencies based on the preferred package manager
9
+ COPY package.json ./
10
+ RUN npm install
11
+
12
+ # Rebuild the source code only when needed
13
+ FROM base AS builder
14
+ WORKDIR /app
15
+ COPY --from=deps /app/node_modules ./node_modules
16
+ COPY . .
17
+
18
+ # Build the application
19
+ RUN npm run build
20
+
21
+ # Production image, copy all the files and run the app
22
+ FROM base AS runner
23
+ WORKDIR /app
24
+
25
+ ENV NODE_ENV=production
26
+
27
+ RUN addgroup --system --gid 1001 nodejs
28
+ RUN adduser --system --uid 1001 4runr
29
+
30
+ COPY --from=builder /app/dist ./dist
31
+ COPY --from=builder /app/node_modules ./node_modules
32
+ COPY --from=builder /app/package.json ./package.json
33
+
34
+ USER 4runr
35
+
36
+ EXPOSE 3000
37
+
38
+ ENV PORT=3000
39
+ ENV HOST=0.0.0.0
40
+
41
+ CMD ["node", "dist/index.js"]