openlit 1.12.0 → 1.14.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 (352) hide show
  1. package/README.md +34 -1
  2. package/dist/__tests__/manual-trace.test.js +118 -0
  3. package/dist/__tests__/manual-trace.test.js.map +1 -0
  4. package/dist/__tests__/register.test.js +90 -0
  5. package/dist/__tests__/register.test.js.map +1 -0
  6. package/dist/config.d.ts +7 -1
  7. package/dist/config.js +3 -1
  8. package/dist/config.js.map +1 -1
  9. package/dist/evals/__tests__/offline.test.js +418 -0
  10. package/dist/evals/__tests__/offline.test.js.map +1 -0
  11. package/dist/evals/index.d.ts +2 -5
  12. package/dist/evals/index.js +12 -26
  13. package/dist/evals/index.js.map +1 -1
  14. package/dist/evals/offline.d.ts +6 -0
  15. package/dist/evals/offline.js +347 -0
  16. package/dist/evals/offline.js.map +1 -0
  17. package/dist/evals/types.d.ts +69 -18
  18. package/dist/evals/types.js +20 -0
  19. package/dist/evals/types.js.map +1 -1
  20. package/dist/guard/__tests__/integration.test.js +178 -0
  21. package/dist/guard/__tests__/integration.test.js.map +1 -0
  22. package/dist/guard/__tests__/pii.test.js +109 -0
  23. package/dist/guard/__tests__/pii.test.js.map +1 -0
  24. package/dist/guard/__tests__/pipeline.test.js +162 -0
  25. package/dist/guard/__tests__/pipeline.test.js.map +1 -0
  26. package/dist/guard/__tests__/prompt-injection.test.js +92 -0
  27. package/dist/guard/__tests__/prompt-injection.test.js.map +1 -0
  28. package/dist/guard/base.d.ts +75 -14
  29. package/dist/guard/base.js +130 -53
  30. package/dist/guard/base.js.map +1 -1
  31. package/dist/guard/custom.d.ts +19 -0
  32. package/dist/guard/custom.js +46 -0
  33. package/dist/guard/custom.js.map +1 -0
  34. package/dist/guard/index.d.ts +24 -5
  35. package/dist/guard/index.js +39 -21
  36. package/dist/guard/index.js.map +1 -1
  37. package/dist/guard/integration.d.ts +32 -0
  38. package/dist/guard/integration.js +328 -0
  39. package/dist/guard/integration.js.map +1 -0
  40. package/dist/guard/moderation.d.ts +18 -0
  41. package/dist/guard/moderation.js +61 -0
  42. package/dist/guard/moderation.js.map +1 -0
  43. package/dist/guard/pii.d.ts +17 -0
  44. package/dist/guard/pii.js +94 -0
  45. package/dist/guard/pii.js.map +1 -0
  46. package/dist/guard/pipeline.d.ts +18 -0
  47. package/dist/guard/pipeline.js +96 -0
  48. package/dist/guard/pipeline.js.map +1 -0
  49. package/dist/guard/prompt-injection.d.ts +20 -6
  50. package/dist/guard/prompt-injection.js +59 -68
  51. package/dist/guard/prompt-injection.js.map +1 -1
  52. package/dist/guard/schema.d.ts +20 -0
  53. package/dist/guard/schema.js +99 -0
  54. package/dist/guard/schema.js.map +1 -0
  55. package/dist/guard/sensitive-topic.d.ts +22 -6
  56. package/dist/guard/sensitive-topic.js +78 -64
  57. package/dist/guard/sensitive-topic.js.map +1 -1
  58. package/dist/guard/topic-restriction.d.ts +21 -6
  59. package/dist/guard/topic-restriction.js +43 -64
  60. package/dist/guard/topic-restriction.js.map +1 -1
  61. package/dist/helpers.d.ts +133 -2
  62. package/dist/helpers.js +416 -5
  63. package/dist/helpers.js.map +1 -1
  64. package/dist/index.d.ts +54 -30
  65. package/dist/index.js +104 -22
  66. package/dist/index.js.map +1 -1
  67. package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.d.ts +13 -0
  68. package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js +176 -0
  69. package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js.map +1 -0
  70. package/dist/instrumentation/__tests__/ai21-trace-comparison.test.d.ts +10 -0
  71. package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js +203 -0
  72. package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js.map +1 -0
  73. package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js +262 -0
  74. package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js.map +1 -0
  75. package/dist/instrumentation/__tests__/astra-trace-comparison.test.d.ts +7 -0
  76. package/dist/instrumentation/__tests__/astra-trace-comparison.test.js +160 -0
  77. package/dist/instrumentation/__tests__/astra-trace-comparison.test.js.map +1 -0
  78. package/dist/instrumentation/__tests__/browser-use-wrapper.test.js +284 -0
  79. package/dist/instrumentation/__tests__/browser-use-wrapper.test.js.map +1 -0
  80. package/dist/instrumentation/__tests__/cache-pricing.test.d.ts +12 -0
  81. package/dist/instrumentation/__tests__/cache-pricing.test.js +95 -0
  82. package/dist/instrumentation/__tests__/cache-pricing.test.js.map +1 -0
  83. package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.d.ts +1 -0
  84. package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js +282 -0
  85. package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js.map +1 -0
  86. package/dist/instrumentation/__tests__/firecrawl-wrapper.test.d.ts +1 -0
  87. package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js +238 -0
  88. package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js.map +1 -0
  89. package/dist/instrumentation/__tests__/gpu-collector.test.d.ts +1 -0
  90. package/dist/instrumentation/__tests__/gpu-collector.test.js +247 -0
  91. package/dist/instrumentation/__tests__/gpu-collector.test.js.map +1 -0
  92. package/dist/instrumentation/__tests__/gradient-trace-comparison.test.d.ts +11 -0
  93. package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js +391 -0
  94. package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js.map +1 -0
  95. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js +150 -0
  96. package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -1
  97. package/dist/instrumentation/__tests__/helpers-genai.test.d.ts +14 -0
  98. package/dist/instrumentation/__tests__/helpers-genai.test.js +347 -0
  99. package/dist/instrumentation/__tests__/helpers-genai.test.js.map +1 -0
  100. package/dist/instrumentation/__tests__/langchain-role-map.test.d.ts +1 -0
  101. package/dist/instrumentation/__tests__/langchain-role-map.test.js +19 -0
  102. package/dist/instrumentation/__tests__/langchain-role-map.test.js.map +1 -0
  103. package/dist/instrumentation/__tests__/mem0-trace-comparison.test.d.ts +13 -0
  104. package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js +208 -0
  105. package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js.map +1 -0
  106. package/dist/instrumentation/__tests__/pg-trace-comparison.test.d.ts +21 -0
  107. package/dist/instrumentation/__tests__/pg-trace-comparison.test.js +455 -0
  108. package/dist/instrumentation/__tests__/pg-trace-comparison.test.js.map +1 -0
  109. package/dist/instrumentation/__tests__/transformers-trace-comparison.test.d.ts +11 -0
  110. package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js +214 -0
  111. package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js.map +1 -0
  112. package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.d.ts +6 -0
  113. package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js +409 -0
  114. package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js.map +1 -0
  115. package/dist/instrumentation/__tests__/vllm-trace-comparison.test.d.ts +1 -0
  116. package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js +519 -0
  117. package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js.map +1 -0
  118. package/dist/instrumentation/ai21/index.d.ts +11 -0
  119. package/dist/instrumentation/ai21/index.js +67 -0
  120. package/dist/instrumentation/ai21/index.js.map +1 -0
  121. package/dist/instrumentation/ai21/wrapper.d.ts +54 -0
  122. package/dist/instrumentation/ai21/wrapper.js +511 -0
  123. package/dist/instrumentation/ai21/wrapper.js.map +1 -0
  124. package/dist/instrumentation/anthropic/wrapper.js +56 -2
  125. package/dist/instrumentation/anthropic/wrapper.js.map +1 -1
  126. package/dist/instrumentation/assemblyai/index.d.ts +12 -0
  127. package/dist/instrumentation/assemblyai/index.js +91 -0
  128. package/dist/instrumentation/assemblyai/index.js.map +1 -0
  129. package/dist/instrumentation/assemblyai/wrapper.d.ts +35 -0
  130. package/dist/instrumentation/assemblyai/wrapper.js +233 -0
  131. package/dist/instrumentation/assemblyai/wrapper.js.map +1 -0
  132. package/dist/instrumentation/astra/index.d.ts +11 -0
  133. package/dist/instrumentation/astra/index.js +87 -0
  134. package/dist/instrumentation/astra/index.js.map +1 -0
  135. package/dist/instrumentation/astra/wrapper.d.ts +39 -0
  136. package/dist/instrumentation/astra/wrapper.js +349 -0
  137. package/dist/instrumentation/astra/wrapper.js.map +1 -0
  138. package/dist/instrumentation/azure-ai-inference/wrapper.d.ts +13 -0
  139. package/dist/instrumentation/azure-ai-inference/wrapper.js +60 -1
  140. package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -1
  141. package/dist/instrumentation/bedrock/wrapper.d.ts +13 -0
  142. package/dist/instrumentation/bedrock/wrapper.js +78 -2
  143. package/dist/instrumentation/bedrock/wrapper.js.map +1 -1
  144. package/dist/instrumentation/browser-use/index.d.ts +11 -0
  145. package/dist/instrumentation/browser-use/index.js +98 -0
  146. package/dist/instrumentation/browser-use/index.js.map +1 -0
  147. package/dist/instrumentation/browser-use/wrapper.d.ts +12 -0
  148. package/dist/instrumentation/browser-use/wrapper.js +706 -0
  149. package/dist/instrumentation/browser-use/wrapper.js.map +1 -0
  150. package/dist/instrumentation/claude-agent-sdk/wrapper.js +90 -4
  151. package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -1
  152. package/dist/instrumentation/cohere/wrapper.d.ts +13 -0
  153. package/dist/instrumentation/cohere/wrapper.js +59 -0
  154. package/dist/instrumentation/cohere/wrapper.js.map +1 -1
  155. package/dist/instrumentation/cursor-sdk/index.d.ts +21 -0
  156. package/dist/instrumentation/cursor-sdk/index.js +58 -0
  157. package/dist/instrumentation/cursor-sdk/index.js.map +1 -0
  158. package/dist/instrumentation/cursor-sdk/wrapper.d.ts +17 -0
  159. package/dist/instrumentation/cursor-sdk/wrapper.js +785 -0
  160. package/dist/instrumentation/cursor-sdk/wrapper.js.map +1 -0
  161. package/dist/instrumentation/elevenlabs/index.d.ts +12 -0
  162. package/dist/instrumentation/elevenlabs/index.js +92 -0
  163. package/dist/instrumentation/elevenlabs/index.js.map +1 -0
  164. package/dist/instrumentation/elevenlabs/wrapper.d.ts +34 -0
  165. package/dist/instrumentation/elevenlabs/wrapper.js +280 -0
  166. package/dist/instrumentation/elevenlabs/wrapper.js.map +1 -0
  167. package/dist/instrumentation/firecrawl/index.d.ts +13 -0
  168. package/dist/instrumentation/firecrawl/index.js +115 -0
  169. package/dist/instrumentation/firecrawl/index.js.map +1 -0
  170. package/dist/instrumentation/firecrawl/wrapper.d.ts +22 -0
  171. package/dist/instrumentation/firecrawl/wrapper.js +378 -0
  172. package/dist/instrumentation/firecrawl/wrapper.js.map +1 -0
  173. package/dist/instrumentation/google-ai/wrapper.d.ts +13 -0
  174. package/dist/instrumentation/google-ai/wrapper.js +85 -1
  175. package/dist/instrumentation/google-ai/wrapper.js.map +1 -1
  176. package/dist/instrumentation/gpu/index.d.ts +38 -0
  177. package/dist/instrumentation/gpu/index.js +233 -0
  178. package/dist/instrumentation/gpu/index.js.map +1 -0
  179. package/dist/instrumentation/gradient/index.d.ts +12 -0
  180. package/dist/instrumentation/gradient/index.js +74 -0
  181. package/dist/instrumentation/gradient/index.js.map +1 -0
  182. package/dist/instrumentation/gradient/utils.d.ts +14 -0
  183. package/dist/instrumentation/gradient/utils.js +119 -0
  184. package/dist/instrumentation/gradient/utils.js.map +1 -0
  185. package/dist/instrumentation/gradient/wrapper.d.ts +76 -0
  186. package/dist/instrumentation/gradient/wrapper.js +584 -0
  187. package/dist/instrumentation/gradient/wrapper.js.map +1 -0
  188. package/dist/instrumentation/groq/wrapper.js +42 -0
  189. package/dist/instrumentation/groq/wrapper.js.map +1 -1
  190. package/dist/instrumentation/huggingface/wrapper.d.ts +13 -0
  191. package/dist/instrumentation/huggingface/wrapper.js +66 -0
  192. package/dist/instrumentation/huggingface/wrapper.js.map +1 -1
  193. package/dist/instrumentation/index.js +28 -0
  194. package/dist/instrumentation/index.js.map +1 -1
  195. package/dist/instrumentation/langchain/wrapper.js +5 -8
  196. package/dist/instrumentation/langchain/wrapper.js.map +1 -1
  197. package/dist/instrumentation/langgraph/wrapper.js +12 -11
  198. package/dist/instrumentation/langgraph/wrapper.js.map +1 -1
  199. package/dist/instrumentation/llamaindex/wrapper.d.ts +14 -1
  200. package/dist/instrumentation/llamaindex/wrapper.js +68 -0
  201. package/dist/instrumentation/llamaindex/wrapper.js.map +1 -1
  202. package/dist/instrumentation/mcp/index.d.ts +20 -0
  203. package/dist/instrumentation/mcp/index.js +282 -0
  204. package/dist/instrumentation/mcp/index.js.map +1 -0
  205. package/dist/instrumentation/mcp/wrapper.d.ts +72 -0
  206. package/dist/instrumentation/mcp/wrapper.js +571 -0
  207. package/dist/instrumentation/mcp/wrapper.js.map +1 -0
  208. package/dist/instrumentation/mem0/index.d.ts +17 -0
  209. package/dist/instrumentation/mem0/index.js +113 -0
  210. package/dist/instrumentation/mem0/index.js.map +1 -0
  211. package/dist/instrumentation/mem0/wrapper.d.ts +37 -0
  212. package/dist/instrumentation/mem0/wrapper.js +298 -0
  213. package/dist/instrumentation/mem0/wrapper.js.map +1 -0
  214. package/dist/instrumentation/mistral/wrapper.d.ts +13 -0
  215. package/dist/instrumentation/mistral/wrapper.js +60 -1
  216. package/dist/instrumentation/mistral/wrapper.js.map +1 -1
  217. package/dist/instrumentation/ollama/wrapper.d.ts +13 -0
  218. package/dist/instrumentation/ollama/wrapper.js +67 -1
  219. package/dist/instrumentation/ollama/wrapper.js.map +1 -1
  220. package/dist/instrumentation/openai/wrapper.d.ts +13 -0
  221. package/dist/instrumentation/openai/wrapper.js +89 -3
  222. package/dist/instrumentation/openai/wrapper.js.map +1 -1
  223. package/dist/instrumentation/pg/index.d.ts +20 -0
  224. package/dist/instrumentation/pg/index.js +74 -0
  225. package/dist/instrumentation/pg/index.js.map +1 -0
  226. package/dist/instrumentation/pg/wrapper.d.ts +66 -0
  227. package/dist/instrumentation/pg/wrapper.js +441 -0
  228. package/dist/instrumentation/pg/wrapper.js.map +1 -0
  229. package/dist/instrumentation/replicate/wrapper.d.ts +13 -0
  230. package/dist/instrumentation/replicate/wrapper.js +61 -0
  231. package/dist/instrumentation/replicate/wrapper.js.map +1 -1
  232. package/dist/instrumentation/strands/processor.d.ts +6 -0
  233. package/dist/instrumentation/strands/processor.js +73 -3
  234. package/dist/instrumentation/strands/processor.js.map +1 -1
  235. package/dist/instrumentation/strands/utils.d.ts +2 -2
  236. package/dist/instrumentation/strands/utils.js +15 -2
  237. package/dist/instrumentation/strands/utils.js.map +1 -1
  238. package/dist/instrumentation/together/wrapper.d.ts +13 -0
  239. package/dist/instrumentation/together/wrapper.js +59 -1
  240. package/dist/instrumentation/together/wrapper.js.map +1 -1
  241. package/dist/instrumentation/transformers/index.d.ts +35 -0
  242. package/dist/instrumentation/transformers/index.js +119 -0
  243. package/dist/instrumentation/transformers/index.js.map +1 -0
  244. package/dist/instrumentation/transformers/wrapper.d.ts +49 -0
  245. package/dist/instrumentation/transformers/wrapper.js +472 -0
  246. package/dist/instrumentation/transformers/wrapper.js.map +1 -0
  247. package/dist/instrumentation/vercel-ai/wrapper.d.ts +13 -0
  248. package/dist/instrumentation/vercel-ai/wrapper.js +106 -1
  249. package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -1
  250. package/dist/instrumentation/vertexai/index.d.ts +11 -0
  251. package/dist/instrumentation/vertexai/index.js +70 -0
  252. package/dist/instrumentation/vertexai/index.js.map +1 -0
  253. package/dist/instrumentation/vertexai/wrapper.d.ts +67 -0
  254. package/dist/instrumentation/vertexai/wrapper.js +529 -0
  255. package/dist/instrumentation/vertexai/wrapper.js.map +1 -0
  256. package/dist/instrumentation/vllm/index.d.ts +13 -0
  257. package/dist/instrumentation/vllm/index.js +67 -0
  258. package/dist/instrumentation/vllm/index.js.map +1 -0
  259. package/dist/instrumentation/vllm/wrapper.d.ts +60 -0
  260. package/dist/instrumentation/vllm/wrapper.js +482 -0
  261. package/dist/instrumentation/vllm/wrapper.js.map +1 -0
  262. package/dist/llm/index.d.ts +9 -2
  263. package/dist/llm/index.js.map +1 -1
  264. package/dist/manual-trace.d.ts +40 -0
  265. package/dist/manual-trace.js +103 -0
  266. package/dist/manual-trace.js.map +1 -0
  267. package/dist/otel/metrics.d.ts +11 -0
  268. package/dist/otel/metrics.js +48 -0
  269. package/dist/otel/metrics.js.map +1 -1
  270. package/dist/register.d.ts +4 -0
  271. package/dist/register.js +52 -0
  272. package/dist/register.js.map +1 -0
  273. package/dist/score/__tests__/score.test.d.ts +1 -0
  274. package/dist/score/__tests__/score.test.js +143 -0
  275. package/dist/score/__tests__/score.test.js.map +1 -0
  276. package/dist/score/index.d.ts +2 -0
  277. package/dist/score/index.js +6 -0
  278. package/dist/score/index.js.map +1 -0
  279. package/dist/score/score.d.ts +15 -0
  280. package/dist/score/score.js +135 -0
  281. package/dist/score/score.js.map +1 -0
  282. package/dist/semantic-convention.d.ts +278 -0
  283. package/dist/semantic-convention.js +322 -0
  284. package/dist/semantic-convention.js.map +1 -1
  285. package/dist/types.d.ts +15 -1
  286. package/package.json +18 -1
  287. package/dist/evals/__tests__/anthropic.test.js +0 -9
  288. package/dist/evals/__tests__/anthropic.test.js.map +0 -1
  289. package/dist/evals/__tests__/base.test.js +0 -37
  290. package/dist/evals/__tests__/base.test.js.map +0 -1
  291. package/dist/evals/__tests__/core.test.js +0 -33
  292. package/dist/evals/__tests__/core.test.js.map +0 -1
  293. package/dist/evals/__tests__/metrics.test.js +0 -59
  294. package/dist/evals/__tests__/metrics.test.js.map +0 -1
  295. package/dist/evals/__tests__/openai.test.js +0 -9
  296. package/dist/evals/__tests__/openai.test.js.map +0 -1
  297. package/dist/evals/__tests__/providers.test.js +0 -14
  298. package/dist/evals/__tests__/providers.test.js.map +0 -1
  299. package/dist/evals/__tests__/utils.test.js +0 -46
  300. package/dist/evals/__tests__/utils.test.js.map +0 -1
  301. package/dist/evals/all.d.ts +0 -4
  302. package/dist/evals/all.js +0 -35
  303. package/dist/evals/all.js.map +0 -1
  304. package/dist/evals/base.d.ts +0 -15
  305. package/dist/evals/base.js +0 -51
  306. package/dist/evals/base.js.map +0 -1
  307. package/dist/evals/bias.d.ts +0 -4
  308. package/dist/evals/bias.js +0 -35
  309. package/dist/evals/bias.js.map +0 -1
  310. package/dist/evals/hallucination.d.ts +0 -4
  311. package/dist/evals/hallucination.js +0 -32
  312. package/dist/evals/hallucination.js.map +0 -1
  313. package/dist/evals/llm/anthropic.d.ts +0 -5
  314. package/dist/evals/llm/anthropic.js +0 -42
  315. package/dist/evals/llm/anthropic.js.map +0 -1
  316. package/dist/evals/llm/openai.d.ts +0 -6
  317. package/dist/evals/llm/openai.js +0 -28
  318. package/dist/evals/llm/openai.js.map +0 -1
  319. package/dist/evals/llm/providers.d.ts +0 -7
  320. package/dist/evals/llm/providers.js +0 -10
  321. package/dist/evals/llm/providers.js.map +0 -1
  322. package/dist/evals/metrics.d.ts +0 -9
  323. package/dist/evals/metrics.js +0 -38
  324. package/dist/evals/metrics.js.map +0 -1
  325. package/dist/evals/toxicity.d.ts +0 -4
  326. package/dist/evals/toxicity.js +0 -33
  327. package/dist/evals/toxicity.js.map +0 -1
  328. package/dist/evals/utils.d.ts +0 -4
  329. package/dist/evals/utils.js +0 -39
  330. package/dist/evals/utils.js.map +0 -1
  331. package/dist/guard/__tests__/gaurd.test.js +0 -136
  332. package/dist/guard/__tests__/gaurd.test.js.map +0 -1
  333. package/dist/guard/__tests__/utils.test.js +0 -64
  334. package/dist/guard/__tests__/utils.test.js.map +0 -1
  335. package/dist/guard/all.d.ts +0 -8
  336. package/dist/guard/all.js +0 -28
  337. package/dist/guard/all.js.map +0 -1
  338. package/dist/guard/types.d.ts +0 -26
  339. package/dist/guard/types.js +0 -4
  340. package/dist/guard/types.js.map +0 -1
  341. package/dist/guard/utils.d.ts +0 -13
  342. package/dist/guard/utils.js +0 -79
  343. package/dist/guard/utils.js.map +0 -1
  344. /package/dist/{evals/__tests__/anthropic.test.d.ts → __tests__/manual-trace.test.d.ts} +0 -0
  345. /package/dist/{evals/__tests__/metrics.test.d.ts → __tests__/register.test.d.ts} +0 -0
  346. /package/dist/evals/__tests__/{base.test.d.ts → offline.test.d.ts} +0 -0
  347. /package/dist/{evals/__tests__/core.test.d.ts → guard/__tests__/integration.test.d.ts} +0 -0
  348. /package/dist/{evals/__tests__/openai.test.d.ts → guard/__tests__/pii.test.d.ts} +0 -0
  349. /package/dist/{evals/__tests__/providers.test.d.ts → guard/__tests__/pipeline.test.d.ts} +0 -0
  350. /package/dist/{evals/__tests__/utils.test.d.ts → guard/__tests__/prompt-injection.test.d.ts} +0 -0
  351. /package/dist/{guard/__tests__/gaurd.test.d.ts → instrumentation/__tests__/assemblyai-wrapper.test.d.ts} +0 -0
  352. /package/dist/{guard/__tests__/utils.test.d.ts → instrumentation/__tests__/browser-use-wrapper.test.d.ts} +0 -0
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+ /**
3
+ * Auto-guard integration layer.
4
+ *
5
+ * setupAutoGuards wraps LLM provider methods so that guards run on every
6
+ * call without any changes to existing instrumentation code.
7
+ *
8
+ * Call chain after setup:
9
+ *
10
+ * User call
11
+ * -> Guard wrapper (preflight -> may deny/redact)
12
+ * -> Instrumentor wrapper (OTel telemetry)
13
+ * -> Original SDK method (actual API call)
14
+ * <- Instrumentor wrapper
15
+ * <- Guard wrapper (postflight -> may redact/warn)
16
+ * <- Returns to user
17
+ *
18
+ * **Streaming limitation**: postflight guards require a complete response
19
+ * object with `choices[].message.content` (or equivalent). Streaming
20
+ * responses yield incremental chunks that extractors cannot fully
21
+ * reassemble, so postflight guards are silently skipped for streamed
22
+ * completions. Preflight guards always run.
23
+ *
24
+ * Must stay in sync with: sdk/python/src/openlit/guard/_integration.py
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.extractOpenAIInput = extractOpenAIInput;
28
+ exports.extractOpenAIOutput = extractOpenAIOutput;
29
+ exports.extractAnthropicInput = extractAnthropicInput;
30
+ exports.extractAnthropicOutput = extractAnthropicOutput;
31
+ exports.extractGenericInput = extractGenericInput;
32
+ exports.extractGenericOutput = extractGenericOutput;
33
+ exports.setupAutoGuards = setupAutoGuards;
34
+ const base_1 = require("./base");
35
+ const pipeline_1 = require("./pipeline");
36
+ function extractOpenAIInput(kwargs) {
37
+ const messages = kwargs.messages || kwargs.input || [];
38
+ if (typeof messages === 'string')
39
+ return messages;
40
+ const parts = [];
41
+ if (Array.isArray(messages)) {
42
+ for (const m of messages) {
43
+ if (typeof m === 'object' && m !== null) {
44
+ const content = m.content ?? '';
45
+ if (typeof content === 'string')
46
+ parts.push(content);
47
+ }
48
+ else if (typeof m === 'string') {
49
+ parts.push(m);
50
+ }
51
+ }
52
+ }
53
+ return parts.join(' ');
54
+ }
55
+ function extractOpenAIOutput(response) {
56
+ try {
57
+ const choices = response?.choices;
58
+ if (choices && Array.isArray(choices)) {
59
+ return choices
60
+ .map((c) => c?.message?.content || '')
61
+ .join(' ');
62
+ }
63
+ const output = response?.output;
64
+ if (output && Array.isArray(output)) {
65
+ const parts = [];
66
+ for (const item of output) {
67
+ const content = item?.content;
68
+ if (Array.isArray(content)) {
69
+ for (const block of content) {
70
+ const text = block?.text;
71
+ if (text)
72
+ parts.push(text);
73
+ }
74
+ }
75
+ else if (typeof content === 'string') {
76
+ parts.push(content);
77
+ }
78
+ }
79
+ return parts.join(' ');
80
+ }
81
+ }
82
+ catch {
83
+ // ignore
84
+ }
85
+ return '';
86
+ }
87
+ function extractAnthropicInput(kwargs) {
88
+ const messages = kwargs.messages || [];
89
+ const parts = [];
90
+ if (Array.isArray(messages)) {
91
+ for (const m of messages) {
92
+ if (typeof m === 'object' && m !== null) {
93
+ const content = m.content ?? '';
94
+ if (typeof content === 'string') {
95
+ parts.push(content);
96
+ }
97
+ else if (Array.isArray(content)) {
98
+ for (const block of content) {
99
+ if (typeof block === 'object' && block?.type === 'text') {
100
+ parts.push(block.text || '');
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+ return parts.join(' ');
108
+ }
109
+ function extractAnthropicOutput(response) {
110
+ try {
111
+ const content = response?.content;
112
+ if (Array.isArray(content)) {
113
+ const parts = [];
114
+ for (const block of content) {
115
+ const text = block?.text;
116
+ if (text)
117
+ parts.push(text);
118
+ }
119
+ return parts.join(' ');
120
+ }
121
+ }
122
+ catch {
123
+ // ignore
124
+ }
125
+ return '';
126
+ }
127
+ function extractGenericInput(kwargs) {
128
+ for (const key of ['messages', 'message', 'prompt', 'input', 'text']) {
129
+ const val = kwargs[key];
130
+ if (val == null)
131
+ continue;
132
+ if (typeof val === 'string')
133
+ return val;
134
+ if (Array.isArray(val)) {
135
+ const parts = [];
136
+ for (const item of val) {
137
+ if (typeof item === 'string') {
138
+ parts.push(item);
139
+ }
140
+ else if (typeof item === 'object' && item !== null) {
141
+ parts.push(item.content || '');
142
+ }
143
+ }
144
+ return parts.join(' ');
145
+ }
146
+ }
147
+ return '';
148
+ }
149
+ function extractGenericOutput(response) {
150
+ try {
151
+ const choices = response?.choices;
152
+ if (choices && Array.isArray(choices)) {
153
+ return choices
154
+ .map((c) => c?.message?.content || '')
155
+ .join(' ');
156
+ }
157
+ }
158
+ catch {
159
+ // ignore
160
+ }
161
+ try {
162
+ const content = response?.content;
163
+ if (typeof content === 'string')
164
+ return content;
165
+ if (Array.isArray(content)) {
166
+ const parts = [];
167
+ for (const block of content) {
168
+ const text = block?.text;
169
+ if (text)
170
+ parts.push(text);
171
+ }
172
+ if (parts.length)
173
+ return parts.join(' ');
174
+ }
175
+ }
176
+ catch {
177
+ // ignore
178
+ }
179
+ try {
180
+ if (response?.text)
181
+ return response.text;
182
+ }
183
+ catch {
184
+ // ignore
185
+ }
186
+ return '';
187
+ }
188
+ const GUARDED_METHODS = [
189
+ // OpenAI
190
+ { npmPackage: 'openai', protoPath: ['OpenAI', 'Chat', 'Completions', 'prototype'], methodName: 'create', extractInput: extractOpenAIInput, extractOutput: extractOpenAIOutput },
191
+ { npmPackage: 'openai', protoPath: ['OpenAI', 'Responses', 'prototype'], methodName: 'create', extractInput: extractOpenAIInput, extractOutput: extractOpenAIOutput },
192
+ // Anthropic
193
+ { npmPackage: '@anthropic-ai/sdk', protoPath: ['Anthropic', 'Messages', 'prototype'], methodName: 'create', extractInput: extractAnthropicInput, extractOutput: extractAnthropicOutput },
194
+ // Groq
195
+ { npmPackage: 'groq-sdk', protoPath: ['Groq', 'Chat', 'Completions', 'prototype'], methodName: 'create', extractInput: extractGenericInput, extractOutput: extractGenericOutput },
196
+ // Mistral
197
+ { npmPackage: '@mistralai/mistralai', protoPath: ['Mistral', 'chat', 'prototype'], methodName: 'complete', extractInput: extractGenericInput, extractOutput: extractGenericOutput },
198
+ // Cohere
199
+ { npmPackage: 'cohere-ai', protoPath: ['CohereClientV2', 'prototype'], methodName: 'chat', extractInput: extractGenericInput, extractOutput: extractGenericOutput },
200
+ // Together
201
+ { npmPackage: 'together-ai', protoPath: ['Together', 'Chat', 'Completions', 'prototype'], methodName: 'create', extractInput: extractGenericInput, extractOutput: extractGenericOutput },
202
+ // Bedrock (AWS)
203
+ { npmPackage: '@aws-sdk/client-bedrock-runtime', protoPath: ['BedrockRuntimeClient', 'prototype'], methodName: 'send', extractInput: extractGenericInput, extractOutput: extractGenericOutput },
204
+ // Google Generative AI
205
+ { npmPackage: '@google/generative-ai', protoPath: ['GenerativeModel', 'prototype'], methodName: 'generateContent', extractInput: extractGenericInput, extractOutput: extractGenericOutput },
206
+ ];
207
+ // ---------------------------------------------------------------------------
208
+ // Preflight / Postflight
209
+ // ---------------------------------------------------------------------------
210
+ function applyPreflight(pipeline, kwargs, extractInput) {
211
+ const inputText = extractInput(kwargs);
212
+ if (!inputText)
213
+ return kwargs;
214
+ const result = pipeline.evaluate(inputText, 'preflight');
215
+ if (result.action === base_1.GuardAction.DENY) {
216
+ throw new base_1.GuardDeniedError(result);
217
+ }
218
+ if (result.action === base_1.GuardAction.REDACT && result.transformedText !== null) {
219
+ for (const key of ['messages', 'input', 'prompt', 'text']) {
220
+ if (key in kwargs) {
221
+ const original = kwargs[key];
222
+ if (typeof original === 'string') {
223
+ return { ...kwargs, [key]: result.transformedText };
224
+ }
225
+ if (Array.isArray(original) && original.length > 0) {
226
+ const newMessages = [...original];
227
+ const last = newMessages[newMessages.length - 1];
228
+ if (typeof last === 'object' && last !== null && 'content' in last) {
229
+ newMessages[newMessages.length - 1] = { ...last, content: result.transformedText };
230
+ return { ...kwargs, [key]: newMessages };
231
+ }
232
+ }
233
+ break;
234
+ }
235
+ }
236
+ }
237
+ return kwargs;
238
+ }
239
+ function applyPostflight(pipeline, response, extractOutput) {
240
+ const outputText = extractOutput(response);
241
+ if (!outputText)
242
+ return response;
243
+ const result = pipeline.evaluate(outputText, 'postflight');
244
+ if (result.action === base_1.GuardAction.DENY) {
245
+ throw new base_1.GuardDeniedError(result);
246
+ }
247
+ if (result.action === base_1.GuardAction.REDACT && result.transformedText !== null) {
248
+ try {
249
+ const choices = response?.choices;
250
+ if (choices && Array.isArray(choices)) {
251
+ for (const choice of choices) {
252
+ if (choice?.message && 'content' in choice.message) {
253
+ choice.message.content = result.transformedText;
254
+ }
255
+ }
256
+ }
257
+ else {
258
+ const content = response?.content;
259
+ if (Array.isArray(content) && content.length > 0) {
260
+ for (const block of content) {
261
+ if ('text' in block) {
262
+ block.text = result.transformedText;
263
+ break;
264
+ }
265
+ }
266
+ }
267
+ else if (response && 'text' in response) {
268
+ response.text = result.transformedText;
269
+ }
270
+ }
271
+ }
272
+ catch {
273
+ // best-effort redaction
274
+ }
275
+ }
276
+ return response;
277
+ }
278
+ // ---------------------------------------------------------------------------
279
+ // Prototype resolver
280
+ // ---------------------------------------------------------------------------
281
+ function resolveProto(moduleExports, protoPath) {
282
+ let obj = moduleExports;
283
+ for (const key of protoPath) {
284
+ if (obj == null)
285
+ return null;
286
+ obj = obj[key];
287
+ }
288
+ return obj;
289
+ }
290
+ // ---------------------------------------------------------------------------
291
+ // Public entry point
292
+ // ---------------------------------------------------------------------------
293
+ function setupAutoGuards(guards, failOpen = true) {
294
+ const pipeline = new pipeline_1.Pipeline({ guards, failOpen });
295
+ try {
296
+ const OpenlitConfig = require('../config').default;
297
+ OpenlitConfig.guardPipeline = pipeline;
298
+ }
299
+ catch {
300
+ // config not available
301
+ }
302
+ let wrappedCount = 0;
303
+ for (const { npmPackage, protoPath, methodName, extractInput, extractOutput } of GUARDED_METHODS) {
304
+ try {
305
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
306
+ const mod = require(npmPackage);
307
+ const proto = resolveProto(mod, protoPath);
308
+ if (!proto || typeof proto[methodName] !== 'function')
309
+ continue;
310
+ const original = proto[methodName];
311
+ proto[methodName] = async function (...args) {
312
+ let params = args[0] || {};
313
+ params = applyPreflight(pipeline, params, extractInput);
314
+ args[0] = params;
315
+ const response = await original.apply(this, args);
316
+ return applyPostflight(pipeline, response, extractOutput);
317
+ };
318
+ wrappedCount++;
319
+ }
320
+ catch {
321
+ // module not installed, skip silently
322
+ }
323
+ }
324
+ if (wrappedCount > 0) {
325
+ console.log(`[openlit] Auto-guards: wrapped ${wrappedCount}/${GUARDED_METHODS.length} provider methods`);
326
+ }
327
+ }
328
+ //# sourceMappingURL=integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.js","sourceRoot":"","sources":["../../src/guard/integration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAWH,gDAeC;AAED,kDA4BC;AAED,sDAoBC;AAED,wDAeC;AAED,kDAkBC;AAED,oDA+BC;AAwID,0CAyCC;AAnUD,iCAA8D;AAC9D,yCAAsC;AAQtC,SAAgB,kBAAkB,CAAC,MAA2B;IAC5D,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;IACvD,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAClD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,KAA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D,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;gBAEjB,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAElD,OAAO,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;YAC5D,CAAC,CAAC;YACF,YAAY,EAAE,CAAC;QACjB,CAAC;QAAC,MAAM,CAAC;YACP,sCAAsC;QACxC,CAAC;IACH,CAAC;IAED,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,kCAAkC,YAAY,IAAI,eAAe,CAAC,MAAM,mBAAmB,CAAC,CAAC;IAC3G,CAAC;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Content moderation guard -- profanity & toxicity detection.
3
+ *
4
+ * Uses local keyword/regex patterns.
5
+ *
6
+ * Patterns must stay in sync with: sdk/python/src/openlit/guard/moderation.py
7
+ */
8
+ import { Guard, GuardPhase, GuardResult, GuardOptions } from './base';
9
+ export interface ModerationOptions extends GuardOptions {
10
+ customWords?: string[];
11
+ }
12
+ export declare class Moderation extends Guard {
13
+ readonly name = "moderation";
14
+ readonly phases: GuardPhase[];
15
+ private readonly _profanityRe;
16
+ constructor(opts?: ModerationOptions);
17
+ evaluate(text: string): GuardResult;
18
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /**
3
+ * Content moderation guard -- profanity & toxicity detection.
4
+ *
5
+ * Uses local keyword/regex patterns.
6
+ *
7
+ * Patterns must stay in sync with: sdk/python/src/openlit/guard/moderation.py
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.Moderation = void 0;
11
+ const base_1 = require("./base");
12
+ const BUILTIN_WORDS = [
13
+ 'fuck', 'shit', 'ass', 'bitch', 'damn', 'bastard', 'crap',
14
+ 'dick', 'piss', 'cock', 'cunt', 'slut', 'whore',
15
+ 'nigger', 'nigga', 'faggot', 'retard', 'kike', 'spic',
16
+ ];
17
+ const TOXICITY_PATTERNS = [
18
+ /\b(?:kill\s+yourself|kys|go\s+die|hope\s+you\s+die)\b/i,
19
+ /\b(?:i(?:'ll| will)\s+(?:kill|hurt|destroy)\s+you)\b/i,
20
+ ];
21
+ function buildProfanityPattern(words) {
22
+ const escaped = words.map((w) => w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
23
+ return new RegExp('\\b(?:' + escaped.join('|') + ')\\b', 'gi');
24
+ }
25
+ class Moderation extends base_1.Guard {
26
+ constructor(opts = {}) {
27
+ super({ action: opts.action ?? 'warn', maxScanLength: opts.maxScanLength });
28
+ this.name = 'moderation';
29
+ this.phases = [base_1.GuardPhase.PREFLIGHT, base_1.GuardPhase.POSTFLIGHT];
30
+ const allWords = [...BUILTIN_WORDS, ...(opts.customWords || [])];
31
+ this._profanityRe = buildProfanityPattern(allWords);
32
+ }
33
+ evaluate(text) {
34
+ const profanityMatches = text.match(this._profanityRe);
35
+ const toxicityHits = TOXICITY_PATTERNS.some((pat) => pat.test(text));
36
+ if (!profanityMatches && !toxicityHits) {
37
+ return (0, base_1.makeGuardResult)({ guardName: this.name });
38
+ }
39
+ const classifications = [];
40
+ if (profanityMatches)
41
+ classifications.push('profanity');
42
+ if (toxicityHits)
43
+ classifications.push('toxicity');
44
+ const classification = classifications.join(', ');
45
+ const score = toxicityHits ? 0.95 : 0.7;
46
+ let transformedText = null;
47
+ if (this._action === 'redact') {
48
+ transformedText = text.replace(this._profanityRe, '[REDACTED:profanity]');
49
+ }
50
+ return (0, base_1.makeGuardResult)({
51
+ action: this._action,
52
+ score,
53
+ guardName: this.name,
54
+ classification,
55
+ explanation: `Moderation flag: ${classification}`,
56
+ transformedText,
57
+ });
58
+ }
59
+ }
60
+ exports.Moderation = Moderation;
61
+ //# sourceMappingURL=moderation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moderation.js","sourceRoot":"","sources":["../../src/guard/moderation.ts"],"names":[],"mappings":";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,CAAC,YAAY,CAAC,CAAC;QACvD,MAAM,YAAY,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAErE,IAAI,CAAC,gBAAgB,IAAI,CAAC,YAAY,EAAE,CAAC;YACvC,OAAO,IAAA,sBAAe,EAAC,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,eAAe,GAAa,EAAE,CAAC;QACrC,IAAI,gBAAgB;YAAE,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACxD,IAAI,YAAY;YAAE,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEnD,MAAM,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;QAExC,IAAI,eAAe,GAAkB,IAAI,CAAC;QAC1C,IAAI,IAAI,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC9B,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,sBAAsB,CAAC,CAAC;QAC5E,CAAC;QAED,OAAO,IAAA,sBAAe,EAAC;YACrB,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,KAAK;YACL,SAAS,EAAE,IAAI,CAAC,IAAI;YACpB,cAAc;YACd,WAAW,EAAE,oBAAoB,cAAc,EAAE;YACjD,eAAe;SAChB,CAAC,CAAC;IACL,CAAC;CACF;AAzCD,gCAyCC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * PII guard -- detects and optionally redacts personally identifiable
3
+ * information, API keys, and secrets using regex patterns.
4
+ *
5
+ * Patterns must stay in sync with: sdk/python/src/openlit/guard/pii.py
6
+ */
7
+ import { Guard, GuardPhase, GuardResult, GuardOptions } from './base';
8
+ export interface PIIOptions extends GuardOptions {
9
+ customPatterns?: Record<string, string>;
10
+ }
11
+ export declare class PII extends Guard {
12
+ readonly name = "pii";
13
+ readonly phases: GuardPhase[];
14
+ private readonly _allPatterns;
15
+ constructor(opts?: PIIOptions);
16
+ evaluate(text: string): GuardResult;
17
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ /**
3
+ * PII guard -- detects and optionally redacts personally identifiable
4
+ * information, API keys, and secrets using regex patterns.
5
+ *
6
+ * Patterns must stay in sync with: sdk/python/src/openlit/guard/pii.py
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PII = void 0;
10
+ const base_1 = require("./base");
11
+ // ---- API keys / tokens ----
12
+ const PATTERNS = [
13
+ { label: 'openai-api-key', regex: /sk-(?:proj-)?[A-Za-z0-9_-]{20,}/ },
14
+ { label: 'anthropic-api-key', regex: /sk-ant-[A-Za-z0-9_-]{20,}/ },
15
+ { label: 'aws-access-key', regex: /(?<![A-Za-z0-9/+=])AKIA[0-9A-Z]{16}(?![A-Za-z0-9/+=])/ },
16
+ { label: 'gcp-api-key', regex: /AIza[0-9A-Za-z_-]{35}/ },
17
+ { label: 'github-token', regex: /(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9_]{36,}/ },
18
+ { label: 'github-fine-grained', regex: /github_pat_[A-Za-z0-9_]{22,}/ },
19
+ { label: 'stripe-key', regex: /(?:sk|pk)_(?:live|test)_[A-Za-z0-9]{24,}/ },
20
+ { label: 'slack-token', regex: /xox[bpoas]-[A-Za-z0-9-]{10,}/ },
21
+ { label: 'slack-webhook', regex: /https:\/\/hooks\.slack\.com\/services\/T[A-Za-z0-9]+\/B[A-Za-z0-9]+\/[A-Za-z0-9]+/ },
22
+ { label: 'twilio-api-key', regex: /SK[0-9a-fA-F]{32}/ },
23
+ { label: 'sendgrid-api-key', regex: /SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}/ },
24
+ { label: 'mailgun-api-key', regex: /key-[0-9a-zA-Z]{32}/ },
25
+ { label: 'azure-key', regex: /[0-9a-f]{32}/ },
26
+ { label: 'heroku-api-key', regex: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ },
27
+ // ---- PII ----
28
+ { label: 'email', regex: /[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/ },
29
+ { label: 'phone-us', regex: /(?<!\d)(?:\+?1[-.\s]?)?(?:\(?\d{3}\)?[-.\s]?)\d{3}[-.\s]?\d{4}(?!\d)/ },
30
+ { label: 'ssn', regex: /(?<!\d)\d{3}-\d{2}-\d{4}(?!\d)/ },
31
+ { label: 'credit-card', regex: /(?<!\d)(?:4\d{3}|5[1-5]\d{2}|3[47]\d{2}|6(?:011|5\d{2}))[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}(?!\d)/ },
32
+ { label: 'ipv4', regex: /(?<!\d)(?:25[0-5]|2[0-4]\d|[01]?\d\d?)(?:\.(?:25[0-5]|2[0-4]\d|[01]?\d\d?)){3}(?!\d)/ },
33
+ // ---- Secrets / credentials ----
34
+ { label: 'bearer-token', regex: /Bearer\s+[A-Za-z0-9_\-.~+/]+=*/i },
35
+ { label: 'basic-auth', regex: /Basic\s+[A-Za-z0-9+/]+=*/i },
36
+ { label: 'private-key', regex: /-----BEGIN (?:RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----/ },
37
+ { label: 'connection-string', regex: /(?:mongodb(?:\+srv)?|postgres(?:ql)?|mysql|redis|amqp):\/\/\S+/ },
38
+ { label: 'env-secret', regex: /(?:password|secret|token|api_key|apikey)\s*[=:]\s*\S+/i },
39
+ ];
40
+ class PII extends base_1.Guard {
41
+ constructor(opts = {}) {
42
+ super({ action: opts.action ?? 'redact', maxScanLength: opts.maxScanLength });
43
+ this.name = 'pii';
44
+ this.phases = [base_1.GuardPhase.PREFLIGHT, base_1.GuardPhase.POSTFLIGHT];
45
+ const extra = [];
46
+ if (opts.customPatterns) {
47
+ for (const [label, pat] of Object.entries(opts.customPatterns)) {
48
+ extra.push({ label, regex: new RegExp(pat, 'gi') });
49
+ }
50
+ }
51
+ this._allPatterns = [
52
+ ...PATTERNS.map(({ label, regex }) => ({
53
+ label,
54
+ regex: new RegExp(regex.source, regex.flags.includes('g') ? regex.flags : regex.flags + 'g'),
55
+ })),
56
+ ...extra,
57
+ ];
58
+ }
59
+ evaluate(text) {
60
+ const matches = [];
61
+ for (const { label, regex } of this._allPatterns) {
62
+ regex.lastIndex = 0;
63
+ let m;
64
+ while ((m = regex.exec(text)) !== null) {
65
+ matches.push({ label, start: m.index, end: m.index + m[0].length });
66
+ }
67
+ }
68
+ if (matches.length === 0) {
69
+ return (0, base_1.makeGuardResult)({ guardName: this.name });
70
+ }
71
+ const labels = [...new Set(matches.map((m) => m.label))].sort();
72
+ const classification = labels.join(', ');
73
+ const bestScore = Math.min(1.0, matches.length * 0.2 + 0.5);
74
+ let transformedText = null;
75
+ if (this._action === base_1.GuardAction.REDACT) {
76
+ const sortedMatches = [...matches].sort((a, b) => b.start - a.start);
77
+ let resultText = text;
78
+ for (const { label, start, end } of sortedMatches) {
79
+ resultText = resultText.slice(0, start) + `[REDACTED:${label}]` + resultText.slice(end);
80
+ }
81
+ transformedText = resultText;
82
+ }
83
+ return (0, base_1.makeGuardResult)({
84
+ action: this._action,
85
+ score: Math.round(bestScore * 100) / 100,
86
+ guardName: this.name,
87
+ classification,
88
+ explanation: `Detected ${matches.length} PII/secret match(es): ${classification}`,
89
+ transformedText,
90
+ });
91
+ }
92
+ }
93
+ exports.PII = PII;
94
+ //# sourceMappingURL=pii.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pii.js","sourceRoot":"","sources":["../../src/guard/pii.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iCAAoG;AAOpG,8BAA8B;AAC9B,MAAM,QAAQ,GAAmB;IAC/B,EAAE,KAAK,EAAE,gBAA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,aAAa,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;YACrE,IAAI,UAAU,GAAG,IAAI,CAAC;YACtB,KAAK,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,aAAa,EAAE,CAAC;gBAClD,UAAU,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,aAAa,KAAK,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC1F,CAAC;YACD,eAAe,GAAG,UAAU,CAAC;QAC/B,CAAC;QAED,OAAO,IAAA,sBAAe,EAAC;YACrB,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,GAAG,GAAG;YACxC,SAAS,EAAE,IAAI,CAAC,IAAI;YACpB,cAAc;YACd,WAAW,EAAE,YAAY,OAAO,CAAC,MAAM,0BAA0B,cAAc,EAAE;YACjF,eAAe;SAChB,CAAC,CAAC;IACL,CAAC;CACF;AA7DD,kBA6DC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Guard Pipeline -- composes multiple guards into an ordered evaluation chain.
3
+ *
4
+ * Must stay in sync with: sdk/python/src/openlit/guard/_pipeline.py
5
+ */
6
+ import { Guard, PipelineResult } from './base';
7
+ export interface PipelineOptions {
8
+ guards?: Guard[];
9
+ failOpen?: boolean;
10
+ }
11
+ export declare class Pipeline {
12
+ private readonly _guards;
13
+ private readonly _failOpen;
14
+ constructor(opts?: PipelineOptions);
15
+ get guards(): Guard[];
16
+ evaluate(text: string, phase?: string): PipelineResult;
17
+ private static _emitOtel;
18
+ }