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
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Topic restriction guard.
|
|
3
|
+
*
|
|
4
|
+
* Enforces allow/deny topic lists using a user-provided topic classifier.
|
|
5
|
+
*
|
|
6
|
+
* Must stay in sync with: sdk/python/src/openlit/guard/topic_restriction.py
|
|
7
|
+
*/
|
|
8
|
+
import { Guard, GuardPhase, GuardResult, GuardOptions } from './base';
|
|
9
|
+
export interface TopicRestrictionOptions extends GuardOptions {
|
|
10
|
+
classifier: (text: string) => string;
|
|
11
|
+
allowed?: string[];
|
|
12
|
+
denied?: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare class TopicRestriction extends Guard {
|
|
15
|
+
readonly name = "topic_restriction";
|
|
16
|
+
readonly phases: GuardPhase[];
|
|
17
|
+
private readonly _classifier;
|
|
18
|
+
private readonly _allowed;
|
|
19
|
+
private readonly _denied;
|
|
20
|
+
constructor(opts: TopicRestrictionOptions);
|
|
21
|
+
evaluate(text: string): GuardResult;
|
|
7
22
|
}
|
|
@@ -1,74 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Topic restriction guard.
|
|
4
|
+
*
|
|
5
|
+
* Enforces allow/deny topic lists using a user-provided topic classifier.
|
|
6
|
+
*
|
|
7
|
+
* Must stay in sync with: sdk/python/src/openlit/guard/topic_restriction.py
|
|
8
|
+
*/
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
10
|
exports.TopicRestriction = void 0;
|
|
4
11
|
const base_1 = require("./base");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
''
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
'',
|
|
23
|
-
'Expected JSON Structure:',
|
|
24
|
-
'',
|
|
25
|
-
'{',
|
|
26
|
-
' "score": "float",',
|
|
27
|
-
' "verdict": "yes or no",',
|
|
28
|
-
' "guard": "topic_restriction",',
|
|
29
|
-
' "classification": "CATEGORY_OF_TOPIC_RESTRICTION",',
|
|
30
|
-
' "explanation": "Very short one-sentence reason"',
|
|
31
|
-
'}',
|
|
32
|
-
'',
|
|
33
|
-
'Scoring System:',
|
|
34
|
-
'- The score ranges from 0 to 1. Scores should be 0 if the classification is "none". Any other classification must be accompanied by a valid category and a score reflecting the restriction.',
|
|
35
|
-
'',
|
|
36
|
-
'Important: Use only the categories below to classify restricted topics. If the text does not fit any listed category, classify it as "none" with a score of 0.',
|
|
37
|
-
'',
|
|
38
|
-
'Categories of Restricted Topics (use only these categories):',
|
|
39
|
-
'- politics: Requests or discussions about political figures, parties, or policies that are not allowed.',
|
|
40
|
-
'- violence: Requests or discussions involving physical harm, aggression, or violent acts.',
|
|
41
|
-
'- personal_information: Requests for or mentions of sensitive personal data (e.g., credit card, address, email, phone number).',
|
|
42
|
-
'- confidential: Requests for or mentions of confidential or proprietary information.',
|
|
43
|
-
'- illegal: Requests or discussions about illegal activities.',
|
|
44
|
-
'',
|
|
45
|
-
'Final Steps:',
|
|
46
|
-
'- If no restricted topics are detected, or if the topic does not fit into one of the above categories, the return must be: {"score": 0, "verdict": "no", "guard": "none", "classification": "none", "explanation": "none"}.',
|
|
47
|
-
].join('\n');
|
|
12
|
+
class TopicRestriction extends base_1.Guard {
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
super({ action: opts.action ?? 'deny', maxScanLength: opts.maxScanLength });
|
|
15
|
+
this.name = 'topic_restriction';
|
|
16
|
+
this.phases = [base_1.GuardPhase.PREFLIGHT];
|
|
17
|
+
if (typeof opts.classifier !== 'function') {
|
|
18
|
+
throw new base_1.GuardConfigError("TopicRestriction requires a callable 'classifier'");
|
|
19
|
+
}
|
|
20
|
+
if (opts.allowed && opts.denied) {
|
|
21
|
+
throw new base_1.GuardConfigError("Provide either 'allowed' or 'denied', not both");
|
|
22
|
+
}
|
|
23
|
+
if (!opts.allowed && !opts.denied) {
|
|
24
|
+
throw new base_1.GuardConfigError("Provide either 'allowed' or 'denied' topic list");
|
|
25
|
+
}
|
|
26
|
+
this._classifier = opts.classifier;
|
|
27
|
+
this._allowed = opts.allowed ? new Set(opts.allowed.map((t) => t.toLowerCase())) : null;
|
|
28
|
+
this._denied = opts.denied ? new Set(opts.denied.map((t) => t.toLowerCase())) : null;
|
|
48
29
|
}
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// Use correct template variable for prompt and satisfy EvalsInput type
|
|
60
|
-
const prompt = (0, utils_2.formatPrompt)(this.getSystemPrompt(), { prompt: text, text });
|
|
61
|
-
const response = await this.llmResponse(prompt);
|
|
62
|
-
llmResult = (0, utils_1.toGuardResult)((0, llm_1.parseLlmResponse)(response), 'topic_restriction');
|
|
30
|
+
evaluate(text) {
|
|
31
|
+
const topic = this._classifier(text).toLowerCase().trim();
|
|
32
|
+
if (this._allowed !== null && !this._allowed.has(topic)) {
|
|
33
|
+
return (0, base_1.makeGuardResult)({
|
|
34
|
+
action: this._action,
|
|
35
|
+
score: 1.0,
|
|
36
|
+
guardName: this.name,
|
|
37
|
+
classification: topic,
|
|
38
|
+
explanation: `Topic '${topic}' is not in the allowed list`,
|
|
39
|
+
});
|
|
63
40
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
41
|
+
if (this._denied !== null && this._denied.has(topic)) {
|
|
42
|
+
return (0, base_1.makeGuardResult)({
|
|
43
|
+
action: this._action,
|
|
44
|
+
score: 1.0,
|
|
45
|
+
guardName: this.name,
|
|
46
|
+
classification: topic,
|
|
47
|
+
explanation: `Topic '${topic}' is in the denied list`,
|
|
48
|
+
});
|
|
70
49
|
}
|
|
71
|
-
return
|
|
50
|
+
return (0, base_1.makeGuardResult)({ guardName: this.name, classification: topic });
|
|
72
51
|
}
|
|
73
52
|
}
|
|
74
53
|
exports.TopicRestriction = TopicRestriction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topic-restriction.js","sourceRoot":"","sources":["../../src/guard/topic-restriction.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"topic-restriction.js","sourceRoot":"","sources":["../../src/guard/topic-restriction.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,iCAAyG;AAQzG,MAAa,gBAAiB,SAAQ,YAAK;IAQzC,YAAY,IAA6B;QACvC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QARrE,SAAI,GAAG,mBAAmB,CAAC;QAC3B,WAAM,GAAG,CAAC,iBAAU,CAAC,SAAS,CAAC,CAAC;QASvC,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YAC1C,MAAM,IAAI,uBAAgB,CAAC,mDAAmD,CAAC,CAAC;QAClF,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,IAAI,uBAAgB,CAAC,gDAAgD,CAAC,CAAC;QAC/E,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YAClC,MAAM,IAAI,uBAAgB,CAAC,iDAAiD,CAAC,CAAC;QAChF,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACxF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACvF,CAAC;IAED,QAAQ,CAAC,IAAY;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QAE1D,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACxD,OAAO,IAAA,sBAAe,EAAC;gBACrB,MAAM,EAAE,IAAI,CAAC,OAAO;gBACpB,KAAK,EAAE,GAAG;gBACV,SAAS,EAAE,IAAI,CAAC,IAAI;gBACpB,cAAc,EAAE,KAAK;gBACrB,WAAW,EAAE,UAAU,KAAK,8BAA8B;aAC3D,CAAC,CAAC;QACL,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,OAAO,IAAA,sBAAe,EAAC;gBACrB,MAAM,EAAE,IAAI,CAAC,OAAO;gBACpB,KAAK,EAAE,GAAG;gBACV,SAAS,EAAE,IAAI,CAAC,IAAI;gBACpB,cAAc,EAAE,KAAK;gBACrB,WAAW,EAAE,UAAU,KAAK,yBAAyB;aACtD,CAAC,CAAC;QACL,CAAC;QAED,OAAO,IAAA,sBAAe,EAAC,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1E,CAAC;CACF;AAnDD,4CAmDC"}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -22,6 +22,52 @@ export declare function setFrameworkLlmActive(): void;
|
|
|
22
22
|
* Mirrors Python's ContextVar.reset(token) in Strands processor.
|
|
23
23
|
*/
|
|
24
24
|
export declare function resetFrameworkLlmActive(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the user-supplied agent version label set via
|
|
27
|
+
* `OpenLit.setAgentVersion()` / `runWithAgentVersion()`, if any.
|
|
28
|
+
*
|
|
29
|
+
* Provider wrappers stamp this on `gen_ai.agent.version` so the server-side
|
|
30
|
+
* materializer can group traces by the user's preferred label in addition to
|
|
31
|
+
* the auto-computed `openlit.agent.version_hash` fingerprint.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getCurrentAgentVersion(): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Set the agent version label for the current execution context.
|
|
36
|
+
*
|
|
37
|
+
* IMPORTANT: this uses `AsyncLocalStorage.enterWith` which permanently
|
|
38
|
+
* mutates the current async resource. Sequential requests handled on the
|
|
39
|
+
* same Node worker (or reused thread/connection) will inherit the label
|
|
40
|
+
* until something overwrites or clears it. **Always pair with a matching
|
|
41
|
+
* `resetAgentVersion()` in a `finally` block**, or prefer
|
|
42
|
+
* `runWithAgentVersion(label, fn)` which guarantees scoped cleanup.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* try {
|
|
46
|
+
* setAgentVersion('hotfix-2026-05-12');
|
|
47
|
+
* await runAgent();
|
|
48
|
+
* } finally {
|
|
49
|
+
* resetAgentVersion();
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Preferred — automatic scope cleanup, no leak risk:
|
|
54
|
+
* await runWithAgentVersion('hotfix-2026-05-12', () => runAgent());
|
|
55
|
+
*/
|
|
56
|
+
export declare function setAgentVersion(version: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Clear the agent version label set by `setAgentVersion()`. No-op if no
|
|
59
|
+
* label is active. See the `setAgentVersion` docstring for the leak
|
|
60
|
+
* scenario this guards against.
|
|
61
|
+
*/
|
|
62
|
+
export declare function resetAgentVersion(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Run `fn` with the given agent version label bound to the current async
|
|
65
|
+
* scope. Mirrors `openlit.agent_version_context()` in Python and is the
|
|
66
|
+
* recommended way to attach a label — the store is automatically restored
|
|
67
|
+
* when `fn` resolves so there is no risk of leaking the label across
|
|
68
|
+
* subsequent requests.
|
|
69
|
+
*/
|
|
70
|
+
export declare function runWithAgentVersion<T>(version: string, fn: () => T): T;
|
|
25
71
|
/**
|
|
26
72
|
* Returns true when a LangGraph wrapper is controlling execution.
|
|
27
73
|
* LangChain's callback handler skips its own invoke_workflow span when true.
|
|
@@ -56,6 +102,11 @@ export declare function setFrameworkParentContext(ctx: Context): void;
|
|
|
56
102
|
*/
|
|
57
103
|
export declare function clearFrameworkParentContext(): void;
|
|
58
104
|
export declare function getServerAddressForProvider(provider: string): [string, number];
|
|
105
|
+
/** LangChain/LangGraph message type → OTel GenAI role (mirrors Python LANGCHAIN_ROLE_MAPPING). */
|
|
106
|
+
export declare const LANGCHAIN_ROLE_MAP: Record<string, string>;
|
|
107
|
+
export declare const OTEL_ASSISTANT_ROLE: string;
|
|
108
|
+
/** Map a raw LangChain message type/role to the OTel GenAI convention value. */
|
|
109
|
+
export declare function mapLangChainRole(rawRole: string | undefined | null): string;
|
|
59
110
|
/**
|
|
60
111
|
* Apply global (from init) and context-scoped (from usingAttributes /
|
|
61
112
|
* injectAdditionalAttributes) custom attributes to a span.
|
|
@@ -89,16 +140,96 @@ export default class OpenLitHelper {
|
|
|
89
140
|
static readonly PROMPT_TOKEN_FACTOR = 1000;
|
|
90
141
|
static openaiTokens(text: string, model: string): number;
|
|
91
142
|
static generalTokens(text: string): number;
|
|
92
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Compute chat completion cost, optionally accounting for prompt-cache tokens.
|
|
145
|
+
*
|
|
146
|
+
* When the model's pricing entry defines `cacheReadPrice` / `cacheCreationPrice`,
|
|
147
|
+
* the matching cache tokens are billed at those rates instead of the regular
|
|
148
|
+
* prompt price.
|
|
149
|
+
*
|
|
150
|
+
* Token accounting differs across providers:
|
|
151
|
+
* - Anthropic's native API reports `promptTokens` exclusive of cache tokens,
|
|
152
|
+
* so cache tokens are added on top (keep `promptTokensIncludeCache` false).
|
|
153
|
+
* - OpenAI / LangChain report `promptTokens` inclusive of cache read tokens,
|
|
154
|
+
* so pass `promptTokensIncludeCache: true` to subtract the re-priced cache
|
|
155
|
+
* tokens from the prompt base and avoid billing them twice.
|
|
156
|
+
*
|
|
157
|
+
* Cache tokens are only re-priced (and, when inclusive, only subtracted) when a
|
|
158
|
+
* dedicated cache price exists, so the result is identical to the legacy
|
|
159
|
+
* behaviour for any model without cache pricing configured.
|
|
160
|
+
*/
|
|
161
|
+
static getChatModelCost(model: string, pricingInfo: any, promptTokens: number, completionTokens: number, cacheReadTokens?: number, cacheCreationTokens?: number, promptTokensIncludeCache?: boolean): number;
|
|
93
162
|
static getEmbedModelCost(model: string, pricingInfo: any, promptTokens: number): number;
|
|
94
163
|
static getImageModelCost(model: string, pricingInfo: any, size: string, quality: number): number;
|
|
95
|
-
static getAudioModelCost(model: string, pricingInfo: any, prompt: string): number;
|
|
164
|
+
static getAudioModelCost(model: string, pricingInfo: any, prompt: string, duration?: number): number;
|
|
96
165
|
static fetchPricingInfo(pricingJson: any): Promise<any>;
|
|
97
166
|
/**
|
|
98
167
|
* Build OTel-spec input messages JSON string from provider messages array.
|
|
99
168
|
* Format: [{"role": "user", "parts": [{"type": "text", "content": "..."}]}]
|
|
100
169
|
*/
|
|
101
170
|
static buildInputMessages(messages: any[], system?: string): string;
|
|
171
|
+
/**
|
|
172
|
+
* Extract system message(s) from a chat-completions messages array.
|
|
173
|
+
* Returns an OTel ``gen_ai.system_instructions`` payload
|
|
174
|
+
* (``[{"type": "text", "content": "..."}]``) JSON-encoded as a string,
|
|
175
|
+
* or ``undefined`` when no system message is present.
|
|
176
|
+
*
|
|
177
|
+
* Mirrors Python's ``build_system_instructions_from_messages``.
|
|
178
|
+
*/
|
|
179
|
+
static buildSystemInstructionsFromMessages(messages: any[]): string | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Normalize a request ``tools`` array into the OTel
|
|
182
|
+
* ``gen_ai.tool.definitions`` schema and return it as a JSON string,
|
|
183
|
+
* or ``undefined`` when there is nothing usable.
|
|
184
|
+
*
|
|
185
|
+
* Accepts both the OpenAI-style schema
|
|
186
|
+
* (``{"type": "function", "function": {...}}``) and the flat schema
|
|
187
|
+
* (``{"name": ..., "description": ..., "parameters": ...}``), and
|
|
188
|
+
* Anthropic's ``input_schema`` synonym for ``parameters``.
|
|
189
|
+
*
|
|
190
|
+
* Mirrors Python's ``build_tool_definitions``.
|
|
191
|
+
*/
|
|
192
|
+
static buildToolDefinitions(tools: any): string | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* Compute the canonical agent-version fingerprint.
|
|
195
|
+
*
|
|
196
|
+
* Mirrors `fingerprint()` in
|
|
197
|
+
* `src/client/src/lib/platform/agents/snapshot.ts` so that the SDK stamps
|
|
198
|
+
* `openlit.agent.version_hash` with the same value the server-side
|
|
199
|
+
* materializer derives from `otel_traces`. The hash covers the parts that
|
|
200
|
+
* meaningfully change agent behavior: system prompt, tool set (name +
|
|
201
|
+
* schema), primary model, and sampling config.
|
|
202
|
+
*
|
|
203
|
+
* Accepts the same shapes used by the SDK chat finalizers:
|
|
204
|
+
* - `systemInstructions`: the JSON string emitted on
|
|
205
|
+
* `gen_ai.system_instructions`, the original list of `{type,content}`
|
|
206
|
+
* parts, or a plain string.
|
|
207
|
+
* - `toolDefinitions`: the JSON string emitted on
|
|
208
|
+
* `gen_ai.tool.definitions`, or the original list of
|
|
209
|
+
* `{type, name, description, parameters}` items.
|
|
210
|
+
*/
|
|
211
|
+
static computeAgentVersionHash(args: {
|
|
212
|
+
systemInstructions?: string | unknown[] | null;
|
|
213
|
+
toolDefinitions?: string | unknown[] | null;
|
|
214
|
+
primaryModel?: string | null;
|
|
215
|
+
runtimeConfig?: {
|
|
216
|
+
temperature?: number | null;
|
|
217
|
+
top_p?: number | null;
|
|
218
|
+
max_tokens?: number | null;
|
|
219
|
+
provider?: string | null;
|
|
220
|
+
} | null;
|
|
221
|
+
providers?: string[] | null;
|
|
222
|
+
}): string;
|
|
223
|
+
private static readonly _VERSION_HASH_CACHE_MAX;
|
|
224
|
+
private static _versionHashCache;
|
|
225
|
+
/**
|
|
226
|
+
* Build a stable, cheap cache key for the version-hash memoization. Uses
|
|
227
|
+
* `JSON.stringify` of inputs (orders-of-magnitude cheaper than the full
|
|
228
|
+
* canonical pass we want to skip on a cache hit). Returns `null` if
|
|
229
|
+
* inputs can't be stringified (circular refs etc.) — the caller falls
|
|
230
|
+
* back to uncached computation.
|
|
231
|
+
*/
|
|
232
|
+
private static _buildAgentVersionCacheKey;
|
|
102
233
|
/**
|
|
103
234
|
* Build OTel-spec output messages JSON string from provider response.
|
|
104
235
|
* Format: [{"role": "assistant", "parts": [{"type": "text", "content": "..."}], "finish_reason": "stop"}]
|