palaryn 0.1.0 → 0.3.2

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 (344) hide show
  1. package/README.md +243 -588
  2. package/dist/sdk/typescript/src/client.js +2 -2
  3. package/dist/sdk/typescript/src/client.js.map +1 -1
  4. package/dist/src/anomaly/detector.d.ts +7 -4
  5. package/dist/src/anomaly/detector.d.ts.map +1 -1
  6. package/dist/src/anomaly/detector.js +22 -12
  7. package/dist/src/anomaly/detector.js.map +1 -1
  8. package/dist/src/audit/logger.d.ts +10 -0
  9. package/dist/src/audit/logger.d.ts.map +1 -1
  10. package/dist/src/audit/logger.js +52 -38
  11. package/dist/src/audit/logger.js.map +1 -1
  12. package/dist/src/auth/routes.d.ts.map +1 -1
  13. package/dist/src/auth/routes.js +35 -0
  14. package/dist/src/auth/routes.js.map +1 -1
  15. package/dist/src/budget/manager.d.ts +5 -0
  16. package/dist/src/budget/manager.d.ts.map +1 -1
  17. package/dist/src/budget/manager.js +32 -0
  18. package/dist/src/budget/manager.js.map +1 -1
  19. package/dist/src/budget/model-pricing.d.ts +20 -0
  20. package/dist/src/budget/model-pricing.d.ts.map +1 -0
  21. package/dist/src/budget/model-pricing.js +107 -0
  22. package/dist/src/budget/model-pricing.js.map +1 -0
  23. package/dist/src/budget/usage-extractor.d.ts +3 -1
  24. package/dist/src/budget/usage-extractor.d.ts.map +1 -1
  25. package/dist/src/budget/usage-extractor.js +47 -3
  26. package/dist/src/budget/usage-extractor.js.map +1 -1
  27. package/dist/src/config/defaults.d.ts.map +1 -1
  28. package/dist/src/config/defaults.js +65 -13
  29. package/dist/src/config/defaults.js.map +1 -1
  30. package/dist/src/dlp/tool-patterns.d.ts +7 -0
  31. package/dist/src/dlp/tool-patterns.d.ts.map +1 -0
  32. package/dist/src/dlp/tool-patterns.js +34 -0
  33. package/dist/src/dlp/tool-patterns.js.map +1 -0
  34. package/dist/src/executor/filesystem-executor.d.ts +28 -0
  35. package/dist/src/executor/filesystem-executor.d.ts.map +1 -0
  36. package/dist/src/executor/filesystem-executor.js +192 -0
  37. package/dist/src/executor/filesystem-executor.js.map +1 -0
  38. package/dist/src/executor/http-executor.d.ts.map +1 -1
  39. package/dist/src/executor/http-executor.js +22 -2
  40. package/dist/src/executor/http-executor.js.map +1 -1
  41. package/dist/src/executor/index.d.ts +4 -0
  42. package/dist/src/executor/index.d.ts.map +1 -1
  43. package/dist/src/executor/index.js +9 -1
  44. package/dist/src/executor/index.js.map +1 -1
  45. package/dist/src/executor/shell-executor.d.ts +22 -0
  46. package/dist/src/executor/shell-executor.d.ts.map +1 -0
  47. package/dist/src/executor/shell-executor.js +119 -0
  48. package/dist/src/executor/shell-executor.js.map +1 -0
  49. package/dist/src/executor/sql-executor.d.ts +29 -0
  50. package/dist/src/executor/sql-executor.d.ts.map +1 -0
  51. package/dist/src/executor/sql-executor.js +114 -0
  52. package/dist/src/executor/sql-executor.js.map +1 -0
  53. package/dist/src/executor/websocket-executor.d.ts +26 -0
  54. package/dist/src/executor/websocket-executor.d.ts.map +1 -0
  55. package/dist/src/executor/websocket-executor.js +205 -0
  56. package/dist/src/executor/websocket-executor.js.map +1 -0
  57. package/dist/src/interceptor/index.d.ts +2 -0
  58. package/dist/src/interceptor/index.d.ts.map +1 -0
  59. package/dist/src/interceptor/index.js +6 -0
  60. package/dist/src/interceptor/index.js.map +1 -0
  61. package/dist/src/interceptor/provider-interceptor.d.ts +36 -0
  62. package/dist/src/interceptor/provider-interceptor.d.ts.map +1 -0
  63. package/dist/src/interceptor/provider-interceptor.js +302 -0
  64. package/dist/src/interceptor/provider-interceptor.js.map +1 -0
  65. package/dist/src/mcp/auth-verifier.d.ts.map +1 -1
  66. package/dist/src/mcp/auth-verifier.js +3 -2
  67. package/dist/src/mcp/auth-verifier.js.map +1 -1
  68. package/dist/src/mcp/bridge.d.ts +14 -10
  69. package/dist/src/mcp/bridge.d.ts.map +1 -1
  70. package/dist/src/mcp/bridge.js +51 -227
  71. package/dist/src/mcp/bridge.js.map +1 -1
  72. package/dist/src/mcp/http-transport.d.ts +2 -0
  73. package/dist/src/mcp/http-transport.d.ts.map +1 -1
  74. package/dist/src/mcp/http-transport.js +117 -66
  75. package/dist/src/mcp/http-transport.js.map +1 -1
  76. package/dist/src/mcp/internal-auth.d.ts +13 -0
  77. package/dist/src/mcp/internal-auth.d.ts.map +1 -0
  78. package/dist/src/mcp/internal-auth.js +12 -0
  79. package/dist/src/mcp/internal-auth.js.map +1 -0
  80. package/dist/src/mcp/tool-definitions.d.ts +41 -0
  81. package/dist/src/mcp/tool-definitions.d.ts.map +1 -0
  82. package/dist/src/mcp/tool-definitions.js +491 -0
  83. package/dist/src/mcp/tool-definitions.js.map +1 -0
  84. package/dist/src/middleware/auth.js.map +1 -1
  85. package/dist/src/middleware/session.js.map +1 -1
  86. package/dist/src/middleware/validate.d.ts +8 -0
  87. package/dist/src/middleware/validate.d.ts.map +1 -1
  88. package/dist/src/middleware/validate.js +45 -0
  89. package/dist/src/middleware/validate.js.map +1 -1
  90. package/dist/src/policy/engine.d.ts +4 -0
  91. package/dist/src/policy/engine.d.ts.map +1 -1
  92. package/dist/src/policy/engine.js +117 -0
  93. package/dist/src/policy/engine.js.map +1 -1
  94. package/dist/src/saas/routes.d.ts.map +1 -1
  95. package/dist/src/saas/routes.js +355 -22
  96. package/dist/src/saas/routes.js.map +1 -1
  97. package/dist/src/server/app.d.ts.map +1 -1
  98. package/dist/src/server/app.js +24 -3
  99. package/dist/src/server/app.js.map +1 -1
  100. package/dist/src/server/gateway.d.ts.map +1 -1
  101. package/dist/src/server/gateway.js +17 -0
  102. package/dist/src/server/gateway.js.map +1 -1
  103. package/dist/src/server/index.d.ts.map +1 -1
  104. package/dist/src/server/index.js +18 -0
  105. package/dist/src/server/index.js.map +1 -1
  106. package/dist/src/storage/interfaces.d.ts +14 -3
  107. package/dist/src/storage/interfaces.d.ts.map +1 -1
  108. package/dist/src/storage/memory.d.ts +2 -0
  109. package/dist/src/storage/memory.d.ts.map +1 -1
  110. package/dist/src/storage/memory.js +6 -0
  111. package/dist/src/storage/memory.js.map +1 -1
  112. package/dist/src/storage/postgres.d.ts +5 -0
  113. package/dist/src/storage/postgres.d.ts.map +1 -1
  114. package/dist/src/storage/postgres.js +16 -0
  115. package/dist/src/storage/postgres.js.map +1 -1
  116. package/dist/src/storage/redis.d.ts +10 -0
  117. package/dist/src/storage/redis.d.ts.map +1 -1
  118. package/dist/src/storage/redis.js +65 -0
  119. package/dist/src/storage/redis.js.map +1 -1
  120. package/dist/src/types/budget.d.ts +4 -0
  121. package/dist/src/types/budget.d.ts.map +1 -1
  122. package/dist/src/types/config.d.ts +58 -0
  123. package/dist/src/types/config.d.ts.map +1 -1
  124. package/dist/src/types/events.d.ts +1 -0
  125. package/dist/src/types/events.d.ts.map +1 -1
  126. package/dist/src/types/policy.d.ts +11 -1
  127. package/dist/src/types/policy.d.ts.map +1 -1
  128. package/dist/src/types/tool-result.d.ts +11 -0
  129. package/dist/src/types/tool-result.d.ts.map +1 -1
  130. package/dist/tests/unit/app-routes.test.d.ts +2 -0
  131. package/dist/tests/unit/app-routes.test.d.ts.map +1 -0
  132. package/dist/tests/unit/app-routes.test.js +715 -0
  133. package/dist/tests/unit/app-routes.test.js.map +1 -0
  134. package/dist/tests/unit/audit-logger.test.js +105 -0
  135. package/dist/tests/unit/audit-logger.test.js.map +1 -1
  136. package/dist/tests/unit/auth-providers.test.d.ts +2 -0
  137. package/dist/tests/unit/auth-providers.test.d.ts.map +1 -0
  138. package/dist/tests/unit/auth-providers.test.js +279 -0
  139. package/dist/tests/unit/auth-providers.test.js.map +1 -0
  140. package/dist/tests/unit/auth-routes-extended.test.d.ts +2 -0
  141. package/dist/tests/unit/auth-routes-extended.test.d.ts.map +1 -0
  142. package/dist/tests/unit/auth-routes-extended.test.js +993 -0
  143. package/dist/tests/unit/auth-routes-extended.test.js.map +1 -0
  144. package/dist/tests/unit/auth-verifier.test.d.ts +2 -0
  145. package/dist/tests/unit/auth-verifier.test.d.ts.map +1 -0
  146. package/dist/tests/unit/auth-verifier.test.js +505 -0
  147. package/dist/tests/unit/auth-verifier.test.js.map +1 -0
  148. package/dist/tests/unit/billing-routes.test.d.ts +2 -0
  149. package/dist/tests/unit/billing-routes.test.d.ts.map +1 -0
  150. package/dist/tests/unit/billing-routes.test.js +432 -0
  151. package/dist/tests/unit/billing-routes.test.js.map +1 -0
  152. package/dist/tests/unit/config-defaults.test.d.ts +2 -0
  153. package/dist/tests/unit/config-defaults.test.d.ts.map +1 -0
  154. package/dist/tests/unit/config-defaults.test.js +119 -0
  155. package/dist/tests/unit/config-defaults.test.js.map +1 -0
  156. package/dist/tests/unit/defaults.test.js +0 -10
  157. package/dist/tests/unit/defaults.test.js.map +1 -1
  158. package/dist/tests/unit/filesystem-executor.test.d.ts +2 -0
  159. package/dist/tests/unit/filesystem-executor.test.d.ts.map +1 -0
  160. package/dist/tests/unit/filesystem-executor.test.js +280 -0
  161. package/dist/tests/unit/filesystem-executor.test.js.map +1 -0
  162. package/dist/tests/unit/gateway-branches.test.d.ts +2 -0
  163. package/dist/tests/unit/gateway-branches.test.d.ts.map +1 -0
  164. package/dist/tests/unit/gateway-branches.test.js +1039 -0
  165. package/dist/tests/unit/gateway-branches.test.js.map +1 -0
  166. package/dist/tests/unit/http-executor-branches.test.d.ts +2 -0
  167. package/dist/tests/unit/http-executor-branches.test.d.ts.map +1 -0
  168. package/dist/tests/unit/http-executor-branches.test.js +495 -0
  169. package/dist/tests/unit/http-executor-branches.test.js.map +1 -0
  170. package/dist/tests/unit/logger.test.d.ts +2 -0
  171. package/dist/tests/unit/logger.test.d.ts.map +1 -0
  172. package/dist/tests/unit/logger.test.js +97 -0
  173. package/dist/tests/unit/logger.test.js.map +1 -0
  174. package/dist/tests/unit/mcp-internal-auth.test.d.ts +2 -0
  175. package/dist/tests/unit/mcp-internal-auth.test.d.ts.map +1 -0
  176. package/dist/tests/unit/mcp-internal-auth.test.js +445 -0
  177. package/dist/tests/unit/mcp-internal-auth.test.js.map +1 -0
  178. package/dist/tests/unit/metrics.test.js +102 -0
  179. package/dist/tests/unit/metrics.test.js.map +1 -1
  180. package/dist/tests/unit/model-pricing.test.d.ts +2 -0
  181. package/dist/tests/unit/model-pricing.test.d.ts.map +1 -0
  182. package/dist/tests/unit/model-pricing.test.js +87 -0
  183. package/dist/tests/unit/model-pricing.test.js.map +1 -0
  184. package/dist/tests/unit/oauth-stores.test.d.ts +2 -0
  185. package/dist/tests/unit/oauth-stores.test.d.ts.map +1 -0
  186. package/dist/tests/unit/oauth-stores.test.js +260 -0
  187. package/dist/tests/unit/oauth-stores.test.js.map +1 -0
  188. package/dist/tests/unit/policy-engine.test.js +466 -0
  189. package/dist/tests/unit/policy-engine.test.js.map +1 -1
  190. package/dist/tests/unit/provider-interceptor.test.d.ts +2 -0
  191. package/dist/tests/unit/provider-interceptor.test.d.ts.map +1 -0
  192. package/dist/tests/unit/provider-interceptor.test.js +472 -0
  193. package/dist/tests/unit/provider-interceptor.test.js.map +1 -0
  194. package/dist/tests/unit/saas-routes-branches.test.d.ts +2 -0
  195. package/dist/tests/unit/saas-routes-branches.test.d.ts.map +1 -0
  196. package/dist/tests/unit/saas-routes-branches.test.js +2165 -0
  197. package/dist/tests/unit/saas-routes-branches.test.js.map +1 -0
  198. package/dist/tests/unit/saas-routes-crud.test.d.ts +2 -0
  199. package/dist/tests/unit/saas-routes-crud.test.d.ts.map +1 -0
  200. package/dist/tests/unit/saas-routes-crud.test.js +332 -0
  201. package/dist/tests/unit/saas-routes-crud.test.js.map +1 -0
  202. package/dist/tests/unit/saas-routes-data.test.d.ts +2 -0
  203. package/dist/tests/unit/saas-routes-data.test.d.ts.map +1 -0
  204. package/dist/tests/unit/saas-routes-data.test.js +405 -0
  205. package/dist/tests/unit/saas-routes-data.test.js.map +1 -0
  206. package/dist/tests/unit/saas-routes.test.js +3 -3
  207. package/dist/tests/unit/saas-routes.test.js.map +1 -1
  208. package/dist/tests/unit/shell-executor.test.d.ts +2 -0
  209. package/dist/tests/unit/shell-executor.test.d.ts.map +1 -0
  210. package/dist/tests/unit/shell-executor.test.js +145 -0
  211. package/dist/tests/unit/shell-executor.test.js.map +1 -0
  212. package/dist/tests/unit/sql-executor.test.d.ts +2 -0
  213. package/dist/tests/unit/sql-executor.test.d.ts.map +1 -0
  214. package/dist/tests/unit/sql-executor.test.js +177 -0
  215. package/dist/tests/unit/sql-executor.test.js.map +1 -0
  216. package/dist/tests/unit/stream-proxy.test.d.ts +2 -0
  217. package/dist/tests/unit/stream-proxy.test.d.ts.map +1 -0
  218. package/dist/tests/unit/stream-proxy.test.js +147 -0
  219. package/dist/tests/unit/stream-proxy.test.js.map +1 -0
  220. package/dist/tests/unit/tool-definitions.test.d.ts +2 -0
  221. package/dist/tests/unit/tool-definitions.test.d.ts.map +1 -0
  222. package/dist/tests/unit/tool-definitions.test.js +184 -0
  223. package/dist/tests/unit/tool-definitions.test.js.map +1 -0
  224. package/dist/tests/unit/usage-extractor.test.js +140 -0
  225. package/dist/tests/unit/usage-extractor.test.js.map +1 -1
  226. package/dist/tests/unit/webhook-handler.test.d.ts +2 -0
  227. package/dist/tests/unit/webhook-handler.test.d.ts.map +1 -0
  228. package/dist/tests/unit/webhook-handler.test.js +453 -0
  229. package/dist/tests/unit/webhook-handler.test.js.map +1 -0
  230. package/dist/tests/unit/webhook-routes.test.d.ts +2 -0
  231. package/dist/tests/unit/webhook-routes.test.d.ts.map +1 -0
  232. package/dist/tests/unit/webhook-routes.test.js +69 -0
  233. package/dist/tests/unit/webhook-routes.test.js.map +1 -0
  234. package/dist/tests/unit/websocket-executor.test.d.ts +2 -0
  235. package/dist/tests/unit/websocket-executor.test.d.ts.map +1 -0
  236. package/dist/tests/unit/websocket-executor.test.js +121 -0
  237. package/dist/tests/unit/websocket-executor.test.js.map +1 -0
  238. package/package.json +8 -2
  239. package/policy-packs/demo_fail.yaml +41 -0
  240. package/policy-packs/full_tools.yaml +136 -0
  241. package/src/admin/index.ts +1 -0
  242. package/src/admin/routes.ts +509 -0
  243. package/src/admin/templates.ts +572 -0
  244. package/src/anomaly/detector.ts +730 -0
  245. package/src/anomaly/index.ts +1 -0
  246. package/src/approval/manager.ts +569 -0
  247. package/src/approval/webhook.ts +133 -0
  248. package/src/audit/logger.ts +490 -0
  249. package/src/auth/index.ts +5 -0
  250. package/src/auth/password.ts +21 -0
  251. package/src/auth/pkce.ts +22 -0
  252. package/src/auth/providers.ts +208 -0
  253. package/src/auth/routes.ts +561 -0
  254. package/src/auth/session.ts +84 -0
  255. package/src/billing/index.ts +6 -0
  256. package/src/billing/plan-enforcer.ts +135 -0
  257. package/src/billing/routes.ts +229 -0
  258. package/src/billing/stripe-client.ts +58 -0
  259. package/src/billing/webhook-handler.ts +182 -0
  260. package/src/billing/webhook-routes.ts +28 -0
  261. package/src/budget/manager.ts +679 -0
  262. package/src/budget/model-pricing.ts +119 -0
  263. package/src/budget/usage-extractor.ts +214 -0
  264. package/src/cli.ts +91 -0
  265. package/src/config/defaults.ts +261 -0
  266. package/src/config/validate.ts +88 -0
  267. package/src/dlp/composite-scanner.ts +213 -0
  268. package/src/dlp/index.ts +9 -0
  269. package/src/dlp/interfaces.ts +34 -0
  270. package/src/dlp/patterns.ts +30 -0
  271. package/src/dlp/prompt-injection-backend.ts +181 -0
  272. package/src/dlp/prompt-injection-patterns.ts +302 -0
  273. package/src/dlp/regex-backend.ts +181 -0
  274. package/src/dlp/scanner.ts +502 -0
  275. package/src/dlp/text-normalizer.ts +225 -0
  276. package/src/dlp/tool-patterns.ts +35 -0
  277. package/src/dlp/trufflehog-backend.ts +190 -0
  278. package/src/executor/filesystem-executor.ts +196 -0
  279. package/src/executor/http-executor.ts +349 -0
  280. package/src/executor/index.ts +9 -0
  281. package/src/executor/interfaces.ts +11 -0
  282. package/src/executor/noop-executor.ts +23 -0
  283. package/src/executor/registry.ts +64 -0
  284. package/src/executor/shell-executor.ts +148 -0
  285. package/src/executor/slack-executor.ts +176 -0
  286. package/src/executor/sql-executor.ts +146 -0
  287. package/src/executor/websocket-executor.ts +211 -0
  288. package/src/index.ts +24 -0
  289. package/src/interceptor/index.ts +1 -0
  290. package/src/interceptor/provider-interceptor.ts +315 -0
  291. package/src/mcp/auth-verifier.ts +152 -0
  292. package/src/mcp/bridge.ts +703 -0
  293. package/src/mcp/http-transport.ts +698 -0
  294. package/src/mcp/index.ts +9 -0
  295. package/src/mcp/internal-auth.ts +14 -0
  296. package/src/mcp/oauth-pages.ts +139 -0
  297. package/src/mcp/oauth-postgres-stores.ts +278 -0
  298. package/src/mcp/oauth-provider.ts +536 -0
  299. package/src/mcp/oauth-stores.ts +202 -0
  300. package/src/mcp/server.ts +55 -0
  301. package/src/mcp/tool-definitions.ts +562 -0
  302. package/src/metrics/collector.ts +357 -0
  303. package/src/metrics/index.ts +1 -0
  304. package/src/middleware/auth.ts +814 -0
  305. package/src/middleware/session.ts +85 -0
  306. package/src/middleware/validate.ts +130 -0
  307. package/src/policy/engine.ts +815 -0
  308. package/src/policy/index.ts +2 -0
  309. package/src/policy/opa-engine.ts +829 -0
  310. package/src/proxy/forward-proxy.ts +649 -0
  311. package/src/proxy/index.ts +1 -0
  312. package/src/ratelimit/limiter.ts +196 -0
  313. package/src/replay/engine.ts +142 -0
  314. package/src/replay/index.ts +1 -0
  315. package/src/saas/index.ts +1 -0
  316. package/src/saas/routes.ts +2178 -0
  317. package/src/server/app.ts +985 -0
  318. package/src/server/errors.ts +49 -0
  319. package/src/server/gateway.ts +1130 -0
  320. package/src/server/index.ts +307 -0
  321. package/src/server/logger.ts +255 -0
  322. package/src/server/stream-proxy.ts +202 -0
  323. package/src/storage/file-persistence.ts +315 -0
  324. package/src/storage/index.ts +4 -0
  325. package/src/storage/interfaces.ts +287 -0
  326. package/src/storage/memory.ts +686 -0
  327. package/src/storage/postgres.ts +1831 -0
  328. package/src/storage/redis.ts +835 -0
  329. package/src/tracing/index.ts +1 -0
  330. package/src/tracing/provider.ts +100 -0
  331. package/src/trust/calculator.ts +141 -0
  332. package/src/trust/index.ts +7 -0
  333. package/src/types/budget.ts +36 -0
  334. package/src/types/config.ts +278 -0
  335. package/src/types/events.ts +41 -0
  336. package/src/types/express.d.ts +14 -0
  337. package/src/types/index.ts +7 -0
  338. package/src/types/policy.ts +83 -0
  339. package/src/types/stripe-config.ts +11 -0
  340. package/src/types/subscription.ts +59 -0
  341. package/src/types/tool-call.ts +47 -0
  342. package/src/types/tool-result.ts +82 -0
  343. package/src/types/user.ts +125 -0
  344. package/tsconfig.json +24 -0
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Mock the ws module before importing the executor
4
+ const mockClose = jest.fn();
5
+ const mockSend = jest.fn();
6
+ jest.mock('ws', () => {
7
+ const EventEmitter = require('events');
8
+ class MockWebSocket extends EventEmitter {
9
+ constructor() {
10
+ super();
11
+ this.readyState = 1;
12
+ this.close = mockClose;
13
+ this.send = mockSend;
14
+ setTimeout(() => this.emit('open'), 0);
15
+ }
16
+ }
17
+ MockWebSocket.OPEN = 1;
18
+ return { default: MockWebSocket, __esModule: true };
19
+ });
20
+ const websocket_executor_1 = require("../../src/executor/websocket-executor");
21
+ function makeToolCall(overrides = {}) {
22
+ return {
23
+ tool_call_id: 'tc_test',
24
+ task_id: 'task_test',
25
+ workspace_id: 'ws_test',
26
+ actor: { type: 'agent', id: 'agent_test' },
27
+ source: { platform: 'test' },
28
+ tool: { name: 'ws.connect', capability: 'write' },
29
+ args: {},
30
+ ...overrides,
31
+ };
32
+ }
33
+ const defaultConfig = {
34
+ enabled: true,
35
+ allowed_urls: ['wss://allowed.example.com/*', 'ws://test.local/*'],
36
+ connect_timeout_ms: 5000,
37
+ max_message_size_bytes: 1024 * 1024,
38
+ };
39
+ describe('WebSocketExecutor', () => {
40
+ let executor;
41
+ beforeEach(() => {
42
+ jest.clearAllMocks();
43
+ mockSend.mockImplementation((_data, cb) => cb());
44
+ executor = new websocket_executor_1.WebSocketExecutor(defaultConfig);
45
+ });
46
+ describe('connect', () => {
47
+ test('creates connection with allowed URL', async () => {
48
+ const tc = makeToolCall({
49
+ tool: { name: 'ws.connect', capability: 'write' },
50
+ args: { url: 'wss://allowed.example.com/ws' },
51
+ });
52
+ const result = await executor.execute(tc);
53
+ expect(result.body).toHaveProperty('connected', true);
54
+ expect(result.body).toHaveProperty('connection_id');
55
+ });
56
+ test('rejects connection to disallowed URL', async () => {
57
+ const tc = makeToolCall({
58
+ tool: { name: 'ws.connect', capability: 'write' },
59
+ args: { url: 'wss://evil.example.com/ws' },
60
+ });
61
+ await expect(executor.execute(tc)).rejects.toThrow('not in the allowed URLs list');
62
+ });
63
+ test('throws on missing url arg', async () => {
64
+ const tc = makeToolCall({
65
+ tool: { name: 'ws.connect', capability: 'write' },
66
+ args: {},
67
+ });
68
+ await expect(executor.execute(tc)).rejects.toThrow('Missing or invalid "url"');
69
+ });
70
+ test('returns provided connection_id', async () => {
71
+ const tc = makeToolCall({
72
+ tool: { name: 'ws.connect', capability: 'write' },
73
+ args: { url: 'wss://allowed.example.com/ws', connection_id: 'my-conn-1' },
74
+ });
75
+ const result = await executor.execute(tc);
76
+ expect(result.body.connection_id).toBe('my-conn-1');
77
+ });
78
+ });
79
+ describe('send', () => {
80
+ test('throws for unknown connection_id', async () => {
81
+ const tc = makeToolCall({
82
+ tool: { name: 'ws.send', capability: 'write' },
83
+ args: { connection_id: 'nonexistent', message: 'hello' },
84
+ });
85
+ await expect(executor.execute(tc)).rejects.toThrow('No connection found');
86
+ });
87
+ test('throws on missing connection_id', async () => {
88
+ const tc = makeToolCall({
89
+ tool: { name: 'ws.send', capability: 'write' },
90
+ args: { message: 'hello' },
91
+ });
92
+ await expect(executor.execute(tc)).rejects.toThrow('Missing or invalid "connection_id"');
93
+ });
94
+ });
95
+ describe('close', () => {
96
+ test('throws for unknown connection_id', async () => {
97
+ const tc = makeToolCall({
98
+ tool: { name: 'ws.close', capability: 'write' },
99
+ args: { connection_id: 'nonexistent' },
100
+ });
101
+ await expect(executor.execute(tc)).rejects.toThrow('No connection found');
102
+ });
103
+ test('throws on missing connection_id', async () => {
104
+ const tc = makeToolCall({
105
+ tool: { name: 'ws.close', capability: 'write' },
106
+ args: {},
107
+ });
108
+ await expect(executor.execute(tc)).rejects.toThrow('Missing or invalid "connection_id"');
109
+ });
110
+ });
111
+ describe('action resolution', () => {
112
+ test('throws for unsupported action', async () => {
113
+ const tc = makeToolCall({
114
+ tool: { name: 'ws.invalid', capability: 'write' },
115
+ args: {},
116
+ });
117
+ await expect(executor.execute(tc)).rejects.toThrow('Unsupported WebSocket action');
118
+ });
119
+ });
120
+ });
121
+ //# sourceMappingURL=websocket-executor.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-executor.test.js","sourceRoot":"","sources":["../../../tests/unit/websocket-executor.test.ts"],"names":[],"mappings":";;AAGA,mDAAmD;AACnD,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAE3B,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE;IACnB,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,aAAc,SAAQ,YAAY;QAKtC;YACE,KAAK,EAAE,CAAC;YAJV,eAAU,GAAG,CAAC,CAAC;YACf,UAAK,GAAG,SAAS,CAAC;YAClB,SAAI,GAAG,QAAQ,CAAC;YAGd,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QACzC,CAAC;;IAPM,kBAAI,GAAG,CAAC,AAAJ,CAAK;IASlB,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AACtD,CAAC,CAAC,CAAC;AAEH,8EAA0E;AAE1E,SAAS,YAAY,CAAC,YAA+B,EAAE;IACrD,OAAO;QACL,YAA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EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;YACjD,MAAM,EAAE,GAAG,YAAY,CAAC;gBACtB,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE;gBAC/C,IAAI,EAAE,EAAE;aACT,CAAC,CAAC;YACH,MAAM,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,oCAAoC,CAAC,CAAC;QAC3F,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,IAAI,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;YAC/C,MAAM,EAAE,GAAG,YAAY,CAAC;gBACtB,IAAI,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE;gBACjD,IAAI,EAAE,EAAE;aACT,CAAC,CAAC;YACH,MAAM,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,8BAA8B,CAAC,CAAC;QACrF,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "palaryn",
3
- "version": "0.1.0",
3
+ "version": "0.3.2",
4
4
  "description": "Palaryn - Model-agnostic infrastructure layer for AI agent I/O security, cost control, and observability",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -9,7 +9,10 @@
9
9
  },
10
10
  "files": [
11
11
  "dist/",
12
+ "src/",
12
13
  "policy-packs/",
14
+ "tsconfig.json",
15
+ "package-lock.json",
13
16
  "README.md",
14
17
  "LICENSE"
15
18
  ],
@@ -38,6 +41,7 @@
38
41
  ],
39
42
  "license": "MIT",
40
43
  "dependencies": {
44
+ "@clerk/express": "^1.7.76",
41
45
  "@modelcontextprotocol/sdk": "^1.26.0",
42
46
  "@opentelemetry/api": "^1.9.0",
43
47
  "@opentelemetry/exporter-trace-otlp-http": "^0.211.0",
@@ -62,7 +66,8 @@
62
66
  "pg": "^8.18.0",
63
67
  "prom-client": "^15.1.3",
64
68
  "stripe": "^20.3.1",
65
- "winston": "^3.19.0"
69
+ "winston": "^3.19.0",
70
+ "ws": "^8.19.0"
66
71
  },
67
72
  "devDependencies": {
68
73
  "@types/cookie-parser": "^1.4.10",
@@ -74,6 +79,7 @@
74
79
  "@types/node": "^25.2.1",
75
80
  "@types/pg": "^8.16.0",
76
81
  "@types/supertest": "^6.0.3",
82
+ "@types/ws": "^8.18.1",
77
83
  "@typescript-eslint/eslint-plugin": "^8.54.0",
78
84
  "@typescript-eslint/parser": "^8.54.0",
79
85
  "eslint": "^9.39.2",
@@ -0,0 +1,41 @@
1
+ name: demo_fail
2
+ version: "1.0.0"
3
+ description: "Demo — shows how Palaryn stops runaway agents"
4
+
5
+ domain_blocklist:
6
+ - "169.254.169.254"
7
+ - "metadata.google.internal"
8
+
9
+ rules:
10
+ # Scenario 1: DLP → DENY (secrets in body)
11
+ - name: "Block requests containing secrets"
12
+ effect: DENY
13
+ priority: 1
14
+ conditions:
15
+ dlp_detected: true
16
+ dlp_severity: ["high"]
17
+
18
+ # Scenario 2 prerequisite: allow GETs (for rate limit + budget demos)
19
+ - name: "Allow read operations"
20
+ effect: ALLOW
21
+ priority: 10
22
+ conditions:
23
+ capabilities: ["read"]
24
+
25
+ # Scenario 2: REQUIRE_APPROVAL (writes)
26
+ - name: "Require approval for writes"
27
+ effect: REQUIRE_APPROVAL
28
+ priority: 20
29
+ conditions:
30
+ capabilities: ["write"]
31
+ approval:
32
+ scope: "admin"
33
+ ttl_seconds: 300
34
+ reason: "Write operations require human approval. Go to /admin/approvals to approve."
35
+
36
+ # Hard deny for delete/admin
37
+ - name: "Deny delete and admin"
38
+ effect: DENY
39
+ priority: 30
40
+ conditions:
41
+ capabilities: ["delete", "admin"]
@@ -0,0 +1,136 @@
1
+ name: full_tools
2
+ version: "1.0.0"
3
+ description: "Comprehensive policy pack with rules for all tool types including file, SQL, shell, and provider interception"
4
+
5
+ domain_allowlist:
6
+ - "*.github.com"
7
+ - "*.googleapis.com"
8
+ - "api.openai.com"
9
+ - "api.anthropic.com"
10
+
11
+ rules:
12
+ # --- HTTP rules ---
13
+ - name: allow_http_get
14
+ description: "Allow all HTTP GET requests"
15
+ effect: ALLOW
16
+ priority: 10
17
+ conditions:
18
+ tool_match: "^http\\."
19
+ capabilities: [read]
20
+
21
+ - name: approve_http_write
22
+ description: "Require approval for HTTP write operations"
23
+ effect: REQUIRE_APPROVAL
24
+ priority: 20
25
+ conditions:
26
+ tool_match: "^http\\."
27
+ capabilities: [write, delete]
28
+ approval:
29
+ scope: "http_write"
30
+ ttl_seconds: 3600
31
+ reason: "HTTP write operation requires approval"
32
+
33
+ # --- Filesystem rules ---
34
+ - name: block_sensitive_files
35
+ description: "Block access to sensitive file types"
36
+ effect: DENY
37
+ priority: 5
38
+ conditions:
39
+ tool_match: "^file\\."
40
+ file_extensions: [".env", ".key", ".pem", ".p12", ".pfx"]
41
+
42
+ - name: block_sensitive_paths
43
+ description: "Block access to sensitive directories"
44
+ effect: DENY
45
+ priority: 5
46
+ conditions:
47
+ tool_match: "^file\\."
48
+ file_paths_blocklist:
49
+ - "/etc/**"
50
+ - "**/.ssh/**"
51
+ - "**/.git/config"
52
+
53
+ - name: allow_file_read
54
+ description: "Allow file read operations"
55
+ effect: ALLOW
56
+ priority: 15
57
+ conditions:
58
+ tools: [file.read, file.list, file.stat]
59
+
60
+ - name: approve_file_write
61
+ description: "Require approval for file writes and deletes"
62
+ effect: REQUIRE_APPROVAL
63
+ priority: 20
64
+ conditions:
65
+ tools: [file.write, file.delete]
66
+ approval:
67
+ scope: "file_write"
68
+ ttl_seconds: 1800
69
+ reason: "File modification requires approval"
70
+
71
+ # --- SQL rules ---
72
+ - name: block_system_tables
73
+ description: "Block queries to system/sensitive tables"
74
+ effect: DENY
75
+ priority: 5
76
+ conditions:
77
+ tool_match: "^sql\\."
78
+ sql_tables_blocklist:
79
+ - pg_shadow
80
+ - pg_authid
81
+ - information_schema
82
+
83
+ - name: allow_sql_select
84
+ description: "Allow SELECT queries"
85
+ effect: ALLOW
86
+ priority: 15
87
+ conditions:
88
+ tool_match: "^sql\\."
89
+ sql_statements: [SELECT]
90
+
91
+ - name: approve_sql_write
92
+ description: "Require approval for non-SELECT SQL"
93
+ effect: REQUIRE_APPROVAL
94
+ priority: 20
95
+ conditions:
96
+ tool_match: "^sql\\."
97
+ sql_statements: [INSERT, UPDATE, DELETE]
98
+ approval:
99
+ scope: "sql_write"
100
+ ttl_seconds: 1800
101
+ reason: "SQL write operation requires approval"
102
+
103
+ # --- Shell rules ---
104
+ - name: approve_shell_exec
105
+ description: "Require approval for all shell commands"
106
+ effect: REQUIRE_APPROVAL
107
+ priority: 15
108
+ conditions:
109
+ tool_match: "^shell\\."
110
+ approval:
111
+ scope: "shell_exec"
112
+ ttl_seconds: 900
113
+ reason: "Shell command execution requires approval"
114
+
115
+ # --- Provider interception ---
116
+ - name: scan_provider_computer_use
117
+ description: "Flag provider computer_use tool calls for review"
118
+ effect: REQUIRE_APPROVAL
119
+ priority: 10
120
+ conditions:
121
+ provider_tool_types: [computer_use, bash]
122
+ approval:
123
+ scope: "provider_dangerous_tool"
124
+ ttl_seconds: 600
125
+ reason: "AI provider using dangerous tool type"
126
+
127
+ # --- DLP-triggered rules ---
128
+ - name: block_high_severity_dlp
129
+ description: "Block requests with high-severity DLP detections"
130
+ effect: DENY
131
+ priority: 1
132
+ conditions:
133
+ dlp_severity: [high]
134
+ dlp_detected: true
135
+
136
+ default_effect: DENY
@@ -0,0 +1 @@
1
+ export { createAdminRouter } from './routes';