openlit 1.13.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.
- package/README.md +34 -1
- package/dist/__tests__/manual-trace.test.js +118 -0
- package/dist/__tests__/manual-trace.test.js.map +1 -0
- package/dist/__tests__/register.test.js +90 -0
- package/dist/__tests__/register.test.js.map +1 -0
- package/dist/config.d.ts +7 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/evals/__tests__/offline.test.js +418 -0
- package/dist/evals/__tests__/offline.test.js.map +1 -0
- package/dist/evals/index.d.ts +2 -5
- package/dist/evals/index.js +12 -26
- package/dist/evals/index.js.map +1 -1
- package/dist/evals/offline.d.ts +6 -0
- package/dist/evals/offline.js +347 -0
- package/dist/evals/offline.js.map +1 -0
- package/dist/evals/types.d.ts +69 -18
- package/dist/evals/types.js +20 -0
- package/dist/evals/types.js.map +1 -1
- package/dist/guard/__tests__/integration.test.js +178 -0
- package/dist/guard/__tests__/integration.test.js.map +1 -0
- package/dist/guard/__tests__/pii.test.js +109 -0
- package/dist/guard/__tests__/pii.test.js.map +1 -0
- package/dist/guard/__tests__/pipeline.test.js +162 -0
- package/dist/guard/__tests__/pipeline.test.js.map +1 -0
- package/dist/guard/__tests__/prompt-injection.test.js +92 -0
- package/dist/guard/__tests__/prompt-injection.test.js.map +1 -0
- package/dist/guard/base.d.ts +75 -14
- package/dist/guard/base.js +130 -53
- package/dist/guard/base.js.map +1 -1
- package/dist/guard/custom.d.ts +19 -0
- package/dist/guard/custom.js +46 -0
- package/dist/guard/custom.js.map +1 -0
- package/dist/guard/index.d.ts +24 -5
- package/dist/guard/index.js +39 -21
- package/dist/guard/index.js.map +1 -1
- package/dist/guard/integration.d.ts +32 -0
- package/dist/guard/integration.js +328 -0
- package/dist/guard/integration.js.map +1 -0
- package/dist/guard/moderation.d.ts +18 -0
- package/dist/guard/moderation.js +61 -0
- package/dist/guard/moderation.js.map +1 -0
- package/dist/guard/pii.d.ts +17 -0
- package/dist/guard/pii.js +94 -0
- package/dist/guard/pii.js.map +1 -0
- package/dist/guard/pipeline.d.ts +18 -0
- package/dist/guard/pipeline.js +96 -0
- package/dist/guard/pipeline.js.map +1 -0
- package/dist/guard/prompt-injection.d.ts +20 -6
- package/dist/guard/prompt-injection.js +59 -68
- package/dist/guard/prompt-injection.js.map +1 -1
- package/dist/guard/schema.d.ts +20 -0
- package/dist/guard/schema.js +99 -0
- package/dist/guard/schema.js.map +1 -0
- package/dist/guard/sensitive-topic.d.ts +22 -6
- package/dist/guard/sensitive-topic.js +78 -64
- package/dist/guard/sensitive-topic.js.map +1 -1
- package/dist/guard/topic-restriction.d.ts +21 -6
- package/dist/guard/topic-restriction.js +43 -64
- package/dist/guard/topic-restriction.js.map +1 -1
- package/dist/helpers.d.ts +133 -2
- package/dist/helpers.js +415 -5
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +54 -30
- package/dist/index.js +104 -22
- package/dist/index.js.map +1 -1
- package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.d.ts +13 -0
- package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js +176 -0
- package/dist/instrumentation/__tests__/ai21-rag-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/ai21-trace-comparison.test.d.ts +10 -0
- package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js +203 -0
- package/dist/instrumentation/__tests__/ai21-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js +262 -0
- package/dist/instrumentation/__tests__/assemblyai-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/astra-trace-comparison.test.d.ts +7 -0
- package/dist/instrumentation/__tests__/astra-trace-comparison.test.js +160 -0
- package/dist/instrumentation/__tests__/astra-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/browser-use-wrapper.test.js +284 -0
- package/dist/instrumentation/__tests__/browser-use-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.d.ts +12 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.js +95 -0
- package/dist/instrumentation/__tests__/cache-pricing.test.js.map +1 -0
- package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js +282 -0
- package/dist/instrumentation/__tests__/elevenlabs-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/firecrawl-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js +238 -0
- package/dist/instrumentation/__tests__/firecrawl-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/gpu-collector.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/gpu-collector.test.js +247 -0
- package/dist/instrumentation/__tests__/gpu-collector.test.js.map +1 -0
- package/dist/instrumentation/__tests__/gradient-trace-comparison.test.d.ts +11 -0
- package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js +391 -0
- package/dist/instrumentation/__tests__/gradient-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.js +150 -0
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/helpers-genai.test.d.ts +14 -0
- package/dist/instrumentation/__tests__/helpers-genai.test.js +347 -0
- package/dist/instrumentation/__tests__/helpers-genai.test.js.map +1 -0
- package/dist/instrumentation/__tests__/langchain-role-map.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/langchain-role-map.test.js +19 -0
- package/dist/instrumentation/__tests__/langchain-role-map.test.js.map +1 -0
- package/dist/instrumentation/__tests__/mem0-trace-comparison.test.d.ts +13 -0
- package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js +208 -0
- package/dist/instrumentation/__tests__/mem0-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/pg-trace-comparison.test.d.ts +21 -0
- package/dist/instrumentation/__tests__/pg-trace-comparison.test.js +455 -0
- package/dist/instrumentation/__tests__/pg-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/transformers-trace-comparison.test.d.ts +11 -0
- package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js +214 -0
- package/dist/instrumentation/__tests__/transformers-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.d.ts +6 -0
- package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js +409 -0
- package/dist/instrumentation/__tests__/vertexai-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/vllm-trace-comparison.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js +519 -0
- package/dist/instrumentation/__tests__/vllm-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/ai21/index.d.ts +11 -0
- package/dist/instrumentation/ai21/index.js +67 -0
- package/dist/instrumentation/ai21/index.js.map +1 -0
- package/dist/instrumentation/ai21/wrapper.d.ts +54 -0
- package/dist/instrumentation/ai21/wrapper.js +511 -0
- package/dist/instrumentation/ai21/wrapper.js.map +1 -0
- package/dist/instrumentation/anthropic/wrapper.js +56 -2
- package/dist/instrumentation/anthropic/wrapper.js.map +1 -1
- package/dist/instrumentation/assemblyai/index.d.ts +12 -0
- package/dist/instrumentation/assemblyai/index.js +91 -0
- package/dist/instrumentation/assemblyai/index.js.map +1 -0
- package/dist/instrumentation/assemblyai/wrapper.d.ts +35 -0
- package/dist/instrumentation/assemblyai/wrapper.js +233 -0
- package/dist/instrumentation/assemblyai/wrapper.js.map +1 -0
- package/dist/instrumentation/astra/index.d.ts +11 -0
- package/dist/instrumentation/astra/index.js +87 -0
- package/dist/instrumentation/astra/index.js.map +1 -0
- package/dist/instrumentation/astra/wrapper.d.ts +39 -0
- package/dist/instrumentation/astra/wrapper.js +349 -0
- package/dist/instrumentation/astra/wrapper.js.map +1 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.d.ts +13 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.js +60 -1
- package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -1
- package/dist/instrumentation/bedrock/wrapper.d.ts +13 -0
- package/dist/instrumentation/bedrock/wrapper.js +78 -2
- package/dist/instrumentation/bedrock/wrapper.js.map +1 -1
- package/dist/instrumentation/browser-use/index.d.ts +11 -0
- package/dist/instrumentation/browser-use/index.js +98 -0
- package/dist/instrumentation/browser-use/index.js.map +1 -0
- package/dist/instrumentation/browser-use/wrapper.d.ts +12 -0
- package/dist/instrumentation/browser-use/wrapper.js +706 -0
- package/dist/instrumentation/browser-use/wrapper.js.map +1 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.js +90 -4
- package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -1
- package/dist/instrumentation/cohere/wrapper.d.ts +13 -0
- package/dist/instrumentation/cohere/wrapper.js +59 -0
- package/dist/instrumentation/cohere/wrapper.js.map +1 -1
- package/dist/instrumentation/cursor-sdk/wrapper.js +111 -15
- package/dist/instrumentation/cursor-sdk/wrapper.js.map +1 -1
- package/dist/instrumentation/elevenlabs/index.d.ts +12 -0
- package/dist/instrumentation/elevenlabs/index.js +92 -0
- package/dist/instrumentation/elevenlabs/index.js.map +1 -0
- package/dist/instrumentation/elevenlabs/wrapper.d.ts +34 -0
- package/dist/instrumentation/elevenlabs/wrapper.js +280 -0
- package/dist/instrumentation/elevenlabs/wrapper.js.map +1 -0
- package/dist/instrumentation/firecrawl/index.d.ts +13 -0
- package/dist/instrumentation/firecrawl/index.js +115 -0
- package/dist/instrumentation/firecrawl/index.js.map +1 -0
- package/dist/instrumentation/firecrawl/wrapper.d.ts +22 -0
- package/dist/instrumentation/firecrawl/wrapper.js +378 -0
- package/dist/instrumentation/firecrawl/wrapper.js.map +1 -0
- package/dist/instrumentation/google-ai/wrapper.d.ts +13 -0
- package/dist/instrumentation/google-ai/wrapper.js +85 -1
- package/dist/instrumentation/google-ai/wrapper.js.map +1 -1
- package/dist/instrumentation/gpu/index.d.ts +38 -0
- package/dist/instrumentation/gpu/index.js +233 -0
- package/dist/instrumentation/gpu/index.js.map +1 -0
- package/dist/instrumentation/gradient/index.d.ts +12 -0
- package/dist/instrumentation/gradient/index.js +74 -0
- package/dist/instrumentation/gradient/index.js.map +1 -0
- package/dist/instrumentation/gradient/utils.d.ts +14 -0
- package/dist/instrumentation/gradient/utils.js +119 -0
- package/dist/instrumentation/gradient/utils.js.map +1 -0
- package/dist/instrumentation/gradient/wrapper.d.ts +76 -0
- package/dist/instrumentation/gradient/wrapper.js +584 -0
- package/dist/instrumentation/gradient/wrapper.js.map +1 -0
- package/dist/instrumentation/groq/wrapper.js +42 -0
- package/dist/instrumentation/groq/wrapper.js.map +1 -1
- package/dist/instrumentation/huggingface/wrapper.d.ts +13 -0
- package/dist/instrumentation/huggingface/wrapper.js +66 -0
- package/dist/instrumentation/huggingface/wrapper.js.map +1 -1
- package/dist/instrumentation/index.js +26 -0
- package/dist/instrumentation/index.js.map +1 -1
- package/dist/instrumentation/langchain/wrapper.js +5 -8
- package/dist/instrumentation/langchain/wrapper.js.map +1 -1
- package/dist/instrumentation/langgraph/wrapper.js +12 -11
- package/dist/instrumentation/langgraph/wrapper.js.map +1 -1
- package/dist/instrumentation/llamaindex/wrapper.d.ts +14 -1
- package/dist/instrumentation/llamaindex/wrapper.js +68 -0
- package/dist/instrumentation/llamaindex/wrapper.js.map +1 -1
- package/dist/instrumentation/mcp/index.d.ts +20 -0
- package/dist/instrumentation/mcp/index.js +282 -0
- package/dist/instrumentation/mcp/index.js.map +1 -0
- package/dist/instrumentation/mcp/wrapper.d.ts +72 -0
- package/dist/instrumentation/mcp/wrapper.js +571 -0
- package/dist/instrumentation/mcp/wrapper.js.map +1 -0
- package/dist/instrumentation/mem0/index.d.ts +17 -0
- package/dist/instrumentation/mem0/index.js +113 -0
- package/dist/instrumentation/mem0/index.js.map +1 -0
- package/dist/instrumentation/mem0/wrapper.d.ts +37 -0
- package/dist/instrumentation/mem0/wrapper.js +298 -0
- package/dist/instrumentation/mem0/wrapper.js.map +1 -0
- package/dist/instrumentation/mistral/wrapper.d.ts +13 -0
- package/dist/instrumentation/mistral/wrapper.js +60 -1
- package/dist/instrumentation/mistral/wrapper.js.map +1 -1
- package/dist/instrumentation/ollama/wrapper.d.ts +13 -0
- package/dist/instrumentation/ollama/wrapper.js +67 -1
- package/dist/instrumentation/ollama/wrapper.js.map +1 -1
- package/dist/instrumentation/openai/wrapper.d.ts +13 -0
- package/dist/instrumentation/openai/wrapper.js +89 -3
- package/dist/instrumentation/openai/wrapper.js.map +1 -1
- package/dist/instrumentation/pg/index.d.ts +20 -0
- package/dist/instrumentation/pg/index.js +74 -0
- package/dist/instrumentation/pg/index.js.map +1 -0
- package/dist/instrumentation/pg/wrapper.d.ts +66 -0
- package/dist/instrumentation/pg/wrapper.js +441 -0
- package/dist/instrumentation/pg/wrapper.js.map +1 -0
- package/dist/instrumentation/replicate/wrapper.d.ts +13 -0
- package/dist/instrumentation/replicate/wrapper.js +61 -0
- package/dist/instrumentation/replicate/wrapper.js.map +1 -1
- package/dist/instrumentation/strands/processor.d.ts +6 -0
- package/dist/instrumentation/strands/processor.js +73 -3
- package/dist/instrumentation/strands/processor.js.map +1 -1
- package/dist/instrumentation/strands/utils.d.ts +2 -2
- package/dist/instrumentation/strands/utils.js +15 -2
- package/dist/instrumentation/strands/utils.js.map +1 -1
- package/dist/instrumentation/together/wrapper.d.ts +13 -0
- package/dist/instrumentation/together/wrapper.js +59 -1
- package/dist/instrumentation/together/wrapper.js.map +1 -1
- package/dist/instrumentation/transformers/index.d.ts +35 -0
- package/dist/instrumentation/transformers/index.js +119 -0
- package/dist/instrumentation/transformers/index.js.map +1 -0
- package/dist/instrumentation/transformers/wrapper.d.ts +49 -0
- package/dist/instrumentation/transformers/wrapper.js +472 -0
- package/dist/instrumentation/transformers/wrapper.js.map +1 -0
- package/dist/instrumentation/vercel-ai/wrapper.d.ts +13 -0
- package/dist/instrumentation/vercel-ai/wrapper.js +106 -1
- package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -1
- package/dist/instrumentation/vertexai/index.d.ts +11 -0
- package/dist/instrumentation/vertexai/index.js +70 -0
- package/dist/instrumentation/vertexai/index.js.map +1 -0
- package/dist/instrumentation/vertexai/wrapper.d.ts +67 -0
- package/dist/instrumentation/vertexai/wrapper.js +529 -0
- package/dist/instrumentation/vertexai/wrapper.js.map +1 -0
- package/dist/instrumentation/vllm/index.d.ts +13 -0
- package/dist/instrumentation/vllm/index.js +67 -0
- package/dist/instrumentation/vllm/index.js.map +1 -0
- package/dist/instrumentation/vllm/wrapper.d.ts +60 -0
- package/dist/instrumentation/vllm/wrapper.js +482 -0
- package/dist/instrumentation/vllm/wrapper.js.map +1 -0
- package/dist/llm/index.d.ts +9 -2
- package/dist/llm/index.js.map +1 -1
- package/dist/manual-trace.d.ts +40 -0
- package/dist/manual-trace.js +103 -0
- package/dist/manual-trace.js.map +1 -0
- package/dist/otel/metrics.d.ts +11 -0
- package/dist/otel/metrics.js +48 -0
- package/dist/otel/metrics.js.map +1 -1
- package/dist/register.d.ts +4 -0
- package/dist/register.js +52 -0
- package/dist/register.js.map +1 -0
- package/dist/score/__tests__/score.test.d.ts +1 -0
- package/dist/score/__tests__/score.test.js +143 -0
- package/dist/score/__tests__/score.test.js.map +1 -0
- package/dist/score/index.d.ts +2 -0
- package/dist/score/index.js +6 -0
- package/dist/score/index.js.map +1 -0
- package/dist/score/score.d.ts +15 -0
- package/dist/score/score.js +135 -0
- package/dist/score/score.js.map +1 -0
- package/dist/semantic-convention.d.ts +273 -0
- package/dist/semantic-convention.js +317 -0
- package/dist/semantic-convention.js.map +1 -1
- package/dist/types.d.ts +15 -1
- package/package.json +18 -1
- package/dist/evals/__tests__/anthropic.test.js +0 -9
- package/dist/evals/__tests__/anthropic.test.js.map +0 -1
- package/dist/evals/__tests__/base.test.js +0 -37
- package/dist/evals/__tests__/base.test.js.map +0 -1
- package/dist/evals/__tests__/core.test.js +0 -33
- package/dist/evals/__tests__/core.test.js.map +0 -1
- package/dist/evals/__tests__/metrics.test.js +0 -59
- package/dist/evals/__tests__/metrics.test.js.map +0 -1
- package/dist/evals/__tests__/openai.test.js +0 -9
- package/dist/evals/__tests__/openai.test.js.map +0 -1
- package/dist/evals/__tests__/providers.test.js +0 -14
- package/dist/evals/__tests__/providers.test.js.map +0 -1
- package/dist/evals/__tests__/utils.test.js +0 -46
- package/dist/evals/__tests__/utils.test.js.map +0 -1
- package/dist/evals/all.d.ts +0 -4
- package/dist/evals/all.js +0 -35
- package/dist/evals/all.js.map +0 -1
- package/dist/evals/base.d.ts +0 -15
- package/dist/evals/base.js +0 -51
- package/dist/evals/base.js.map +0 -1
- package/dist/evals/bias.d.ts +0 -4
- package/dist/evals/bias.js +0 -35
- package/dist/evals/bias.js.map +0 -1
- package/dist/evals/hallucination.d.ts +0 -4
- package/dist/evals/hallucination.js +0 -32
- package/dist/evals/hallucination.js.map +0 -1
- package/dist/evals/llm/anthropic.d.ts +0 -5
- package/dist/evals/llm/anthropic.js +0 -42
- package/dist/evals/llm/anthropic.js.map +0 -1
- package/dist/evals/llm/openai.d.ts +0 -6
- package/dist/evals/llm/openai.js +0 -28
- package/dist/evals/llm/openai.js.map +0 -1
- package/dist/evals/llm/providers.d.ts +0 -7
- package/dist/evals/llm/providers.js +0 -10
- package/dist/evals/llm/providers.js.map +0 -1
- package/dist/evals/metrics.d.ts +0 -9
- package/dist/evals/metrics.js +0 -38
- package/dist/evals/metrics.js.map +0 -1
- package/dist/evals/toxicity.d.ts +0 -4
- package/dist/evals/toxicity.js +0 -33
- package/dist/evals/toxicity.js.map +0 -1
- package/dist/evals/utils.d.ts +0 -4
- package/dist/evals/utils.js +0 -39
- package/dist/evals/utils.js.map +0 -1
- package/dist/guard/__tests__/gaurd.test.js +0 -136
- package/dist/guard/__tests__/gaurd.test.js.map +0 -1
- package/dist/guard/__tests__/utils.test.js +0 -64
- package/dist/guard/__tests__/utils.test.js.map +0 -1
- package/dist/guard/all.d.ts +0 -8
- package/dist/guard/all.js +0 -28
- package/dist/guard/all.js.map +0 -1
- package/dist/guard/types.d.ts +0 -26
- package/dist/guard/types.js +0 -4
- package/dist/guard/types.js.map +0 -1
- package/dist/guard/utils.d.ts +0 -13
- package/dist/guard/utils.js +0 -79
- package/dist/guard/utils.js.map +0 -1
- /package/dist/{evals/__tests__/anthropic.test.d.ts → __tests__/manual-trace.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/metrics.test.d.ts → __tests__/register.test.d.ts} +0 -0
- /package/dist/evals/__tests__/{base.test.d.ts → offline.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/core.test.d.ts → guard/__tests__/integration.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/openai.test.d.ts → guard/__tests__/pii.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/providers.test.d.ts → guard/__tests__/pipeline.test.d.ts} +0 -0
- /package/dist/{evals/__tests__/utils.test.d.ts → guard/__tests__/prompt-injection.test.d.ts} +0 -0
- /package/dist/{guard/__tests__/gaurd.test.d.ts → instrumentation/__tests__/assemblyai-wrapper.test.d.ts} +0 -0
- /package/dist/{guard/__tests__/utils.test.d.ts → instrumentation/__tests__/browser-use-wrapper.test.d.ts} +0 -0
package/dist/guard/base.js
CHANGED
|
@@ -1,58 +1,135 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
2
|
+
/**
|
|
3
|
+
* Core types, base class, and errors for the OpenLIT guard system.
|
|
4
|
+
*
|
|
5
|
+
* Must stay in sync with: sdk/python/src/openlit/guard/_base.py
|
|
6
|
+
*/
|
|
35
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
8
|
+
exports.Guard = exports.GuardConfigError = exports.GuardTimeoutError = exports.GuardDeniedError = exports.GuardError = exports.PipelineResult = exports.ACTION_SEVERITY = exports.GuardAction = exports.GuardPhase = void 0;
|
|
9
|
+
exports.makeGuardResult = makeGuardResult;
|
|
10
|
+
var GuardPhase;
|
|
11
|
+
(function (GuardPhase) {
|
|
12
|
+
GuardPhase["PREFLIGHT"] = "preflight";
|
|
13
|
+
GuardPhase["POSTFLIGHT"] = "postflight";
|
|
14
|
+
})(GuardPhase || (exports.GuardPhase = GuardPhase = {}));
|
|
15
|
+
var GuardAction;
|
|
16
|
+
(function (GuardAction) {
|
|
17
|
+
GuardAction["ALLOW"] = "allow";
|
|
18
|
+
GuardAction["DENY"] = "deny";
|
|
19
|
+
GuardAction["REDACT"] = "redact";
|
|
20
|
+
GuardAction["WARN"] = "warn";
|
|
21
|
+
})(GuardAction || (exports.GuardAction = GuardAction = {}));
|
|
22
|
+
exports.ACTION_SEVERITY = {
|
|
23
|
+
[GuardAction.ALLOW]: 0,
|
|
24
|
+
[GuardAction.WARN]: 1,
|
|
25
|
+
[GuardAction.REDACT]: 2,
|
|
26
|
+
[GuardAction.DENY]: 3,
|
|
27
|
+
};
|
|
28
|
+
function makeGuardResult(overrides = {}) {
|
|
29
|
+
return {
|
|
30
|
+
action: GuardAction.ALLOW,
|
|
31
|
+
score: 0,
|
|
32
|
+
guardName: '',
|
|
33
|
+
classification: '',
|
|
34
|
+
explanation: '',
|
|
35
|
+
transformedText: null,
|
|
36
|
+
latencyMs: 0,
|
|
37
|
+
...overrides,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
class PipelineResult {
|
|
41
|
+
constructor(action = GuardAction.ALLOW, results = [], transformedText = null) {
|
|
42
|
+
this.action = action;
|
|
43
|
+
this.results = results;
|
|
44
|
+
this.transformedText = transformedText;
|
|
45
|
+
}
|
|
46
|
+
get explanation() {
|
|
47
|
+
return this.results
|
|
48
|
+
.map((r) => r.explanation)
|
|
49
|
+
.filter(Boolean)
|
|
50
|
+
.join('; ');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.PipelineResult = PipelineResult;
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
// Errors
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
class GuardError extends Error {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = 'GuardError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.GuardError = GuardError;
|
|
64
|
+
class GuardDeniedError extends GuardError {
|
|
65
|
+
constructor(result) {
|
|
66
|
+
super(result.explanation);
|
|
67
|
+
this.name = 'GuardDeniedError';
|
|
68
|
+
this.result = result;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.GuardDeniedError = GuardDeniedError;
|
|
72
|
+
/**
|
|
73
|
+
* Reserved for future use -- a per-guard `timeoutMs` option may be
|
|
74
|
+
* added to Pipeline in a later release.
|
|
75
|
+
*/
|
|
76
|
+
class GuardTimeoutError extends GuardError {
|
|
77
|
+
constructor(message) {
|
|
78
|
+
super(message);
|
|
79
|
+
this.name = 'GuardTimeoutError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.GuardTimeoutError = GuardTimeoutError;
|
|
83
|
+
class GuardConfigError extends GuardError {
|
|
84
|
+
constructor(message) {
|
|
85
|
+
super(message);
|
|
86
|
+
this.name = 'GuardConfigError';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.GuardConfigError = GuardConfigError;
|
|
90
|
+
class Guard {
|
|
91
|
+
/**
|
|
92
|
+
* @param opts.action - Action to take on violation (`allow`, `deny`, `redact`, `warn`). Default: `deny`.
|
|
93
|
+
* @param opts.maxScanLength - Max characters to scan. Text beyond this limit is not evaluated. Default: 102400.
|
|
94
|
+
*/
|
|
95
|
+
constructor(opts = {}) {
|
|
96
|
+
const actionStr = opts.action ?? 'deny';
|
|
97
|
+
const validActions = Object.values(GuardAction);
|
|
98
|
+
if (!validActions.includes(actionStr)) {
|
|
99
|
+
throw new GuardConfigError(`Invalid action '${actionStr}'. Must be one of: ${validActions.join(', ')}`);
|
|
100
|
+
}
|
|
101
|
+
this._action = actionStr;
|
|
102
|
+
const maxScan = opts.maxScanLength ?? 102400;
|
|
103
|
+
if (typeof maxScan !== 'number' || maxScan < 0) {
|
|
104
|
+
throw new GuardConfigError(`Invalid maxScanLength '${maxScan}'. Must be a non-negative number.`);
|
|
105
|
+
}
|
|
106
|
+
this._maxScanLength = maxScan;
|
|
107
|
+
}
|
|
108
|
+
get action() {
|
|
109
|
+
return this._action;
|
|
110
|
+
}
|
|
111
|
+
supportsPhase(phase) {
|
|
112
|
+
return this.phases.includes(phase);
|
|
113
|
+
}
|
|
114
|
+
/** Execute the guard with timing, text-length capping, and phase filtering. */
|
|
115
|
+
run(text, phase) {
|
|
116
|
+
if (!this.supportsPhase(phase)) {
|
|
117
|
+
return makeGuardResult({ guardName: this.name });
|
|
118
|
+
}
|
|
119
|
+
const capped = this._maxScanLength ? text.slice(0, this._maxScanLength) : text;
|
|
120
|
+
const start = performance.now();
|
|
121
|
+
const result = this.evaluate(capped);
|
|
122
|
+
const elapsedMs = performance.now() - start;
|
|
123
|
+
return makeGuardResult({
|
|
124
|
+
action: result.action,
|
|
125
|
+
score: result.score,
|
|
126
|
+
guardName: this.name,
|
|
127
|
+
classification: result.classification,
|
|
128
|
+
explanation: result.explanation,
|
|
129
|
+
transformedText: result.transformedText,
|
|
130
|
+
latencyMs: Math.round(elapsedMs * 1000) / 1000,
|
|
131
|
+
});
|
|
55
132
|
}
|
|
56
133
|
}
|
|
57
|
-
exports.
|
|
134
|
+
exports.Guard = Guard;
|
|
58
135
|
//# sourceMappingURL=base.js.map
|
package/dist/guard/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/guard/base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/guard/base.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom guard -- user-defined regex or callable.
|
|
3
|
+
*
|
|
4
|
+
* Must stay in sync with: sdk/python/src/openlit/guard/custom.py
|
|
5
|
+
*/
|
|
6
|
+
import { Guard, GuardPhase, GuardResult, GuardOptions } from './base';
|
|
7
|
+
export interface CustomOptions extends GuardOptions {
|
|
8
|
+
pattern?: string;
|
|
9
|
+
callable?: (text: string) => GuardResult;
|
|
10
|
+
phases?: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare class Custom extends Guard {
|
|
13
|
+
readonly name = "custom";
|
|
14
|
+
readonly phases: GuardPhase[];
|
|
15
|
+
private readonly _pattern;
|
|
16
|
+
private readonly _callable?;
|
|
17
|
+
constructor(opts?: CustomOptions);
|
|
18
|
+
evaluate(text: string): GuardResult;
|
|
19
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom guard -- user-defined regex or callable.
|
|
4
|
+
*
|
|
5
|
+
* Must stay in sync with: sdk/python/src/openlit/guard/custom.py
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.Custom = void 0;
|
|
9
|
+
const base_1 = require("./base");
|
|
10
|
+
class Custom extends base_1.Guard {
|
|
11
|
+
constructor(opts = {}) {
|
|
12
|
+
super({ action: opts.action ?? 'deny', maxScanLength: opts.maxScanLength });
|
|
13
|
+
this.name = 'custom';
|
|
14
|
+
if (!opts.pattern && !opts.callable) {
|
|
15
|
+
throw new base_1.GuardConfigError("Custom guard needs at least 'pattern' or 'callable'");
|
|
16
|
+
}
|
|
17
|
+
this._pattern = opts.pattern ? new RegExp(opts.pattern) : null;
|
|
18
|
+
this._callable = opts.callable;
|
|
19
|
+
if (opts.phases) {
|
|
20
|
+
this.phases = opts.phases.map((p) => p);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.phases = [base_1.GuardPhase.PREFLIGHT, base_1.GuardPhase.POSTFLIGHT];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
evaluate(text) {
|
|
27
|
+
if (this._pattern) {
|
|
28
|
+
const match = this._pattern.exec(text);
|
|
29
|
+
if (match) {
|
|
30
|
+
return (0, base_1.makeGuardResult)({
|
|
31
|
+
action: this._action,
|
|
32
|
+
score: 1.0,
|
|
33
|
+
guardName: this.name,
|
|
34
|
+
classification: 'pattern_match',
|
|
35
|
+
explanation: `Custom pattern matched: '${match[0]}'`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (this._callable) {
|
|
40
|
+
return this._callable(text);
|
|
41
|
+
}
|
|
42
|
+
return (0, base_1.makeGuardResult)({ guardName: this.name });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.Custom = Custom;
|
|
46
|
+
//# sourceMappingURL=custom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.js","sourceRoot":"","sources":["../../src/guard/custom.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,iCAOgB;AAQhB,MAAa,MAAO,SAAQ,YAAK;IAO/B,YAAY,OAAsB,EAAE;QAClC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QAPrE,SAAI,GAAG,QAAQ,CAAC;QASvB,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpC,MAAM,IAAI,uBAAgB,CAAC,qDAAqD,CAAC,CAAC;QACpF,CAAC;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC/D,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QAE/B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAe,CAAC,CAAC;QACxD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,CAAC,iBAAU,CAAC,SAAS,EAAE,iBAAU,CAAC,UAAU,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,KAAK,EAAE,CAAC;gBACV,OAAO,IAAA,sBAAe,EAAC;oBACrB,MAAM,EAAE,IAAI,CAAC,OAAO;oBACpB,KAAK,EAAE,GAAG;oBACV,SAAS,EAAE,IAAI,CAAC,IAAI;oBACpB,cAAc,EAAE,eAAe;oBAC/B,WAAW,EAAE,4BAA4B,KAAK,CAAC,CAAC,CAAC,GAAG;iBACrD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QAED,OAAO,IAAA,sBAAe,EAAC,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACnD,CAAC;CACF;AA5CD,wBA4CC"}
|
package/dist/guard/index.d.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* OpenLIT Guard System -- public API.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all guard classes, pipeline, types, and errors.
|
|
5
|
+
*/
|
|
6
|
+
export { Guard, GuardAction, GuardPhase, GuardConfigError, GuardDeniedError, GuardError, GuardTimeoutError, PipelineResult, ACTION_SEVERITY, makeGuardResult, } from './base';
|
|
7
|
+
export type { GuardResult, GuardOptions } from './base';
|
|
8
|
+
export { Pipeline } from './pipeline';
|
|
9
|
+
export type { PipelineOptions } from './pipeline';
|
|
10
|
+
export { PII } from './pii';
|
|
11
|
+
export type { PIIOptions } from './pii';
|
|
12
|
+
export { PromptInjection } from './prompt-injection';
|
|
13
|
+
export type { PromptInjectionOptions } from './prompt-injection';
|
|
14
|
+
export { Moderation } from './moderation';
|
|
15
|
+
export type { ModerationOptions } from './moderation';
|
|
16
|
+
export { SensitiveTopic } from './sensitive-topic';
|
|
17
|
+
export type { SensitiveTopicOptions } from './sensitive-topic';
|
|
18
|
+
export { TopicRestriction } from './topic-restriction';
|
|
19
|
+
export type { TopicRestrictionOptions } from './topic-restriction';
|
|
20
|
+
export { Schema } from './schema';
|
|
21
|
+
export type { SchemaOptions } from './schema';
|
|
22
|
+
export { Custom } from './custom';
|
|
23
|
+
export type { CustomOptions } from './custom';
|
|
24
|
+
export { setupAutoGuards } from './integration';
|
package/dist/guard/index.js
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(o, k2, desc);
|
|
11
|
-
}) : (function(o, m, k, k2) {
|
|
12
|
-
if (k2 === undefined) k2 = k;
|
|
13
|
-
o[k2] = m[k];
|
|
14
|
-
}));
|
|
15
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
-
};
|
|
2
|
+
/**
|
|
3
|
+
* OpenLIT Guard System -- public API.
|
|
4
|
+
*
|
|
5
|
+
* Re-exports all guard classes, pipeline, types, and errors.
|
|
6
|
+
*/
|
|
18
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
exports.setupAutoGuards = exports.Custom = exports.Schema = exports.TopicRestriction = exports.SensitiveTopic = exports.Moderation = exports.PromptInjection = exports.PII = exports.Pipeline = exports.makeGuardResult = exports.ACTION_SEVERITY = exports.PipelineResult = exports.GuardTimeoutError = exports.GuardError = exports.GuardDeniedError = exports.GuardConfigError = exports.GuardPhase = exports.GuardAction = exports.Guard = void 0;
|
|
9
|
+
// Foundation types and base class
|
|
10
|
+
var base_1 = require("./base");
|
|
11
|
+
Object.defineProperty(exports, "Guard", { enumerable: true, get: function () { return base_1.Guard; } });
|
|
12
|
+
Object.defineProperty(exports, "GuardAction", { enumerable: true, get: function () { return base_1.GuardAction; } });
|
|
13
|
+
Object.defineProperty(exports, "GuardPhase", { enumerable: true, get: function () { return base_1.GuardPhase; } });
|
|
14
|
+
Object.defineProperty(exports, "GuardConfigError", { enumerable: true, get: function () { return base_1.GuardConfigError; } });
|
|
15
|
+
Object.defineProperty(exports, "GuardDeniedError", { enumerable: true, get: function () { return base_1.GuardDeniedError; } });
|
|
16
|
+
Object.defineProperty(exports, "GuardError", { enumerable: true, get: function () { return base_1.GuardError; } });
|
|
17
|
+
Object.defineProperty(exports, "GuardTimeoutError", { enumerable: true, get: function () { return base_1.GuardTimeoutError; } });
|
|
18
|
+
Object.defineProperty(exports, "PipelineResult", { enumerable: true, get: function () { return base_1.PipelineResult; } });
|
|
19
|
+
Object.defineProperty(exports, "ACTION_SEVERITY", { enumerable: true, get: function () { return base_1.ACTION_SEVERITY; } });
|
|
20
|
+
Object.defineProperty(exports, "makeGuardResult", { enumerable: true, get: function () { return base_1.makeGuardResult; } });
|
|
21
|
+
// Pipeline
|
|
22
|
+
var pipeline_1 = require("./pipeline");
|
|
23
|
+
Object.defineProperty(exports, "Pipeline", { enumerable: true, get: function () { return pipeline_1.Pipeline; } });
|
|
24
|
+
// Guards
|
|
25
|
+
var pii_1 = require("./pii");
|
|
26
|
+
Object.defineProperty(exports, "PII", { enumerable: true, get: function () { return pii_1.PII; } });
|
|
27
|
+
var prompt_injection_1 = require("./prompt-injection");
|
|
28
|
+
Object.defineProperty(exports, "PromptInjection", { enumerable: true, get: function () { return prompt_injection_1.PromptInjection; } });
|
|
29
|
+
var moderation_1 = require("./moderation");
|
|
30
|
+
Object.defineProperty(exports, "Moderation", { enumerable: true, get: function () { return moderation_1.Moderation; } });
|
|
31
|
+
var sensitive_topic_1 = require("./sensitive-topic");
|
|
32
|
+
Object.defineProperty(exports, "SensitiveTopic", { enumerable: true, get: function () { return sensitive_topic_1.SensitiveTopic; } });
|
|
33
|
+
var topic_restriction_1 = require("./topic-restriction");
|
|
34
|
+
Object.defineProperty(exports, "TopicRestriction", { enumerable: true, get: function () { return topic_restriction_1.TopicRestriction; } });
|
|
35
|
+
var schema_1 = require("./schema");
|
|
36
|
+
Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return schema_1.Schema; } });
|
|
37
|
+
var custom_1 = require("./custom");
|
|
38
|
+
Object.defineProperty(exports, "Custom", { enumerable: true, get: function () { return custom_1.Custom; } });
|
|
39
|
+
// Integration
|
|
40
|
+
var integration_1 = require("./integration");
|
|
41
|
+
Object.defineProperty(exports, "setupAutoGuards", { enumerable: true, get: function () { return integration_1.setupAutoGuards; } });
|
|
24
42
|
//# sourceMappingURL=index.js.map
|
package/dist/guard/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/guard/index.ts"],"names":[],"mappings":";AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/guard/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,kCAAkC;AAClC,+BAWgB;AAVd,6FAAA,KAAK,OAAA;AACL,mGAAA,WAAW,OAAA;AACX,kGAAA,UAAU,OAAA;AACV,wGAAA,gBAAgB,OAAA;AAChB,wGAAA,gBAAgB,OAAA;AAChB,kGAAA,UAAU,OAAA;AACV,yGAAA,iBAAiB,OAAA;AACjB,sGAAA,cAAc,OAAA;AACd,uGAAA,eAAe,OAAA;AACf,uGAAA,eAAe,OAAA;AAIjB,WAAW;AACX,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AAGjB,SAAS;AACT,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AAEZ,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AAExB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AAEnB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AAEvB,yDAAuD;AAA9C,qHAAA,gBAAgB,OAAA;AAEzB,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAEf,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAGf,cAAc;AACd,6CAAgD;AAAvC,8GAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-guard integration layer.
|
|
3
|
+
*
|
|
4
|
+
* setupAutoGuards wraps LLM provider methods so that guards run on every
|
|
5
|
+
* call without any changes to existing instrumentation code.
|
|
6
|
+
*
|
|
7
|
+
* Call chain after setup:
|
|
8
|
+
*
|
|
9
|
+
* User call
|
|
10
|
+
* -> Guard wrapper (preflight -> may deny/redact)
|
|
11
|
+
* -> Instrumentor wrapper (OTel telemetry)
|
|
12
|
+
* -> Original SDK method (actual API call)
|
|
13
|
+
* <- Instrumentor wrapper
|
|
14
|
+
* <- Guard wrapper (postflight -> may redact/warn)
|
|
15
|
+
* <- Returns to user
|
|
16
|
+
*
|
|
17
|
+
* **Streaming limitation**: postflight guards require a complete response
|
|
18
|
+
* object with `choices[].message.content` (or equivalent). Streaming
|
|
19
|
+
* responses yield incremental chunks that extractors cannot fully
|
|
20
|
+
* reassemble, so postflight guards are silently skipped for streamed
|
|
21
|
+
* completions. Preflight guards always run.
|
|
22
|
+
*
|
|
23
|
+
* Must stay in sync with: sdk/python/src/openlit/guard/_integration.py
|
|
24
|
+
*/
|
|
25
|
+
import { Guard } from './base';
|
|
26
|
+
export declare function extractOpenAIInput(kwargs: Record<string, any>): string;
|
|
27
|
+
export declare function extractOpenAIOutput(response: any): string;
|
|
28
|
+
export declare function extractAnthropicInput(kwargs: Record<string, any>): string;
|
|
29
|
+
export declare function extractAnthropicOutput(response: any): string;
|
|
30
|
+
export declare function extractGenericInput(kwargs: Record<string, any>): string;
|
|
31
|
+
export declare function extractGenericOutput(response: any): string;
|
|
32
|
+
export declare function setupAutoGuards(guards: Guard[], failOpen?: boolean): void;
|