openlit 1.10.0 → 1.12.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 +35 -1
- package/dist/config.d.ts +12 -4
- package/dist/config.js +7 -17
- package/dist/config.js.map +1 -1
- package/dist/evals/llm/anthropic.js +10 -6
- package/dist/evals/llm/anthropic.js.map +1 -1
- package/dist/evals/llm/openai.js +9 -5
- package/dist/evals/llm/openai.js.map +1 -1
- package/dist/features/__tests__/rule-engine.test.d.ts +1 -0
- package/dist/features/__tests__/rule-engine.test.js +146 -0
- package/dist/features/__tests__/rule-engine.test.js.map +1 -0
- package/dist/features/base.d.ts +2 -0
- package/dist/features/base.js +2 -0
- package/dist/features/base.js.map +1 -1
- package/dist/features/rule-engine.d.ts +6 -0
- package/dist/features/rule-engine.js +60 -0
- package/dist/features/rule-engine.js.map +1 -0
- package/dist/features/vault.js +1 -1
- package/dist/features/vault.js.map +1 -1
- package/dist/helpers.d.ts +93 -1
- package/dist/helpers.js +270 -8
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +95 -50
- package/dist/index.js.map +1 -1
- package/dist/instrumentation/__tests__/anthropic-wrapper.test.js +215 -27
- package/dist/instrumentation/__tests__/anthropic-wrapper.test.js.map +1 -1
- package/dist/instrumentation/__tests__/base-wrapper.test.js +19 -23
- package/dist/instrumentation/__tests__/base-wrapper.test.js.map +1 -1
- package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js +422 -0
- package/dist/instrumentation/__tests__/bedrock-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js +1 -1
- package/dist/instrumentation/__tests__/chroma-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/cohere-wrapper.test.js +150 -25
- package/dist/instrumentation/__tests__/cohere-wrapper.test.js.map +1 -1
- package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js +152 -33
- package/dist/instrumentation/__tests__/google-ai-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.js +391 -45
- package/dist/instrumentation/__tests__/groq-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.d.ts +2 -2
- package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js +323 -31
- package/dist/instrumentation/__tests__/huggingface-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/langchain-wrapper.test.d.ts +1 -0
- package/dist/instrumentation/__tests__/langchain-wrapper.test.js +282 -0
- package/dist/instrumentation/__tests__/langchain-wrapper.test.js.map +1 -0
- package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js +1 -1
- package/dist/instrumentation/__tests__/milvus-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/mistral-trace-comparison.test.d.ts +0 -3
- package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js +275 -68
- package/dist/instrumentation/__tests__/mistral-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/openai-wrapper.test.js +7 -9
- package/dist/instrumentation/__tests__/openai-wrapper.test.js.map +1 -1
- package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js +1 -1
- package/dist/instrumentation/__tests__/qdrant-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/replicate-trace-comparison.test.d.ts +2 -1
- package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js +209 -21
- package/dist/instrumentation/__tests__/replicate-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/together-trace-comparison.test.js +231 -51
- package/dist/instrumentation/__tests__/together-trace-comparison.test.js.map +1 -1
- package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.d.ts +8 -0
- package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js +446 -0
- package/dist/instrumentation/__tests__/vercel-ai-trace-comparison.test.js.map +1 -0
- package/dist/instrumentation/anthropic/index.d.ts +2 -3
- package/dist/instrumentation/anthropic/index.js.map +1 -1
- package/dist/instrumentation/anthropic/wrapper.d.ts +1 -3
- package/dist/instrumentation/anthropic/wrapper.js +211 -91
- package/dist/instrumentation/anthropic/wrapper.js.map +1 -1
- package/dist/instrumentation/azure-ai-inference/index.d.ts +11 -0
- package/dist/instrumentation/azure-ai-inference/index.js +76 -0
- package/dist/instrumentation/azure-ai-inference/index.js.map +1 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.d.ts +42 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.js +515 -0
- package/dist/instrumentation/azure-ai-inference/wrapper.js.map +1 -0
- package/dist/instrumentation/base-wrapper.d.ts +2 -1
- package/dist/instrumentation/base-wrapper.js +35 -23
- package/dist/instrumentation/base-wrapper.js.map +1 -1
- package/dist/instrumentation/bedrock/wrapper.d.ts +21 -3
- package/dist/instrumentation/bedrock/wrapper.js +318 -265
- package/dist/instrumentation/bedrock/wrapper.js.map +1 -1
- package/dist/instrumentation/chroma/wrapper.js +1 -1
- package/dist/instrumentation/chroma/wrapper.js.map +1 -1
- package/dist/instrumentation/claude-agent-sdk/index.d.ts +23 -0
- package/dist/instrumentation/claude-agent-sdk/index.js +83 -0
- package/dist/instrumentation/claude-agent-sdk/index.js.map +1 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.d.ts +13 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.js +1031 -0
- package/dist/instrumentation/claude-agent-sdk/wrapper.js.map +1 -0
- package/dist/instrumentation/cohere/index.d.ts +2 -3
- package/dist/instrumentation/cohere/index.js.map +1 -1
- package/dist/instrumentation/cohere/wrapper.d.ts +1 -1
- package/dist/instrumentation/cohere/wrapper.js +215 -56
- package/dist/instrumentation/cohere/wrapper.js.map +1 -1
- package/dist/instrumentation/google-adk/index.d.ts +57 -0
- package/dist/instrumentation/google-adk/index.js +371 -0
- package/dist/instrumentation/google-adk/index.js.map +1 -0
- package/dist/instrumentation/google-adk/utils.d.ts +45 -0
- package/dist/instrumentation/google-adk/utils.js +663 -0
- package/dist/instrumentation/google-adk/utils.js.map +1 -0
- package/dist/instrumentation/google-adk/wrapper.d.ts +11 -0
- package/dist/instrumentation/google-adk/wrapper.js +391 -0
- package/dist/instrumentation/google-adk/wrapper.js.map +1 -0
- package/dist/instrumentation/google-ai/wrapper.d.ts +7 -4
- package/dist/instrumentation/google-ai/wrapper.js +197 -61
- package/dist/instrumentation/google-ai/wrapper.js.map +1 -1
- package/dist/instrumentation/groq/wrapper.js +137 -65
- package/dist/instrumentation/groq/wrapper.js.map +1 -1
- package/dist/instrumentation/huggingface/wrapper.js +241 -39
- package/dist/instrumentation/huggingface/wrapper.js.map +1 -1
- package/dist/instrumentation/index.d.ts +2 -2
- package/dist/instrumentation/index.js +64 -6
- package/dist/instrumentation/index.js.map +1 -1
- package/dist/instrumentation/langchain/index.d.ts +0 -7
- package/dist/instrumentation/langchain/index.js +2 -20
- package/dist/instrumentation/langchain/index.js.map +1 -1
- package/dist/instrumentation/langchain/wrapper.d.ts +35 -0
- package/dist/instrumentation/langchain/wrapper.js +1098 -184
- package/dist/instrumentation/langchain/wrapper.js.map +1 -1
- package/dist/instrumentation/langgraph/index.d.ts +12 -0
- package/dist/instrumentation/langgraph/index.js +99 -0
- package/dist/instrumentation/langgraph/index.js.map +1 -0
- package/dist/instrumentation/langgraph/wrapper.d.ts +20 -0
- package/dist/instrumentation/langgraph/wrapper.js +619 -0
- package/dist/instrumentation/langgraph/wrapper.js.map +1 -0
- package/dist/instrumentation/llamaindex/index.d.ts +31 -6
- package/dist/instrumentation/llamaindex/index.js +180 -61
- package/dist/instrumentation/llamaindex/index.js.map +1 -1
- package/dist/instrumentation/llamaindex/wrapper.d.ts +15 -3
- package/dist/instrumentation/llamaindex/wrapper.js +670 -179
- package/dist/instrumentation/llamaindex/wrapper.js.map +1 -1
- package/dist/instrumentation/milvus/wrapper.js +1 -1
- package/dist/instrumentation/milvus/wrapper.js.map +1 -1
- package/dist/instrumentation/mistral/wrapper.js +154 -79
- package/dist/instrumentation/mistral/wrapper.js.map +1 -1
- package/dist/instrumentation/ollama/index.js +33 -4
- package/dist/instrumentation/ollama/index.js.map +1 -1
- package/dist/instrumentation/ollama/wrapper.d.ts +28 -2
- package/dist/instrumentation/ollama/wrapper.js +432 -48
- package/dist/instrumentation/ollama/wrapper.js.map +1 -1
- package/dist/instrumentation/openai/index.d.ts +2 -3
- package/dist/instrumentation/openai/index.js.map +1 -1
- package/dist/instrumentation/openai/wrapper.js +293 -194
- package/dist/instrumentation/openai/wrapper.js.map +1 -1
- package/dist/instrumentation/openai-agents/index.d.ts +20 -0
- package/dist/instrumentation/openai-agents/index.js +174 -0
- package/dist/instrumentation/openai-agents/index.js.map +1 -0
- package/dist/instrumentation/openai-agents/processor.d.ts +35 -0
- package/dist/instrumentation/openai-agents/processor.js +249 -0
- package/dist/instrumentation/openai-agents/processor.js.map +1 -0
- package/dist/instrumentation/openai-agents/utils.d.ts +20 -0
- package/dist/instrumentation/openai-agents/utils.js +624 -0
- package/dist/instrumentation/openai-agents/utils.js.map +1 -0
- package/dist/instrumentation/pinecone/wrapper.js +2 -2
- package/dist/instrumentation/pinecone/wrapper.js.map +1 -1
- package/dist/instrumentation/qdrant/wrapper.js +1 -1
- package/dist/instrumentation/qdrant/wrapper.js.map +1 -1
- package/dist/instrumentation/replicate/wrapper.js +103 -21
- package/dist/instrumentation/replicate/wrapper.js.map +1 -1
- package/dist/instrumentation/strands/index.d.ts +21 -0
- package/dist/instrumentation/strands/index.js +83 -0
- package/dist/instrumentation/strands/index.js.map +1 -0
- package/dist/instrumentation/strands/processor.d.ts +45 -0
- package/dist/instrumentation/strands/processor.js +545 -0
- package/dist/instrumentation/strands/processor.js.map +1 -0
- package/dist/instrumentation/strands/utils.d.ts +24 -0
- package/dist/instrumentation/strands/utils.js +360 -0
- package/dist/instrumentation/strands/utils.js.map +1 -0
- package/dist/instrumentation/together/wrapper.js +125 -51
- package/dist/instrumentation/together/wrapper.js.map +1 -1
- package/dist/instrumentation/vercel-ai/wrapper.d.ts +28 -2
- package/dist/instrumentation/vercel-ai/wrapper.js +314 -164
- package/dist/instrumentation/vercel-ai/wrapper.js.map +1 -1
- package/dist/llm/anthropic.js +10 -6
- package/dist/llm/anthropic.js.map +1 -1
- package/dist/llm/openai.js +9 -5
- package/dist/llm/openai.js.map +1 -1
- package/dist/otel/__tests__/metrics.test.js +16 -27
- package/dist/otel/__tests__/metrics.test.js.map +1 -1
- package/dist/otel/events.d.ts +11 -0
- package/dist/otel/events.js +74 -0
- package/dist/otel/events.js.map +1 -0
- package/dist/otel/metrics.d.ts +5 -6
- package/dist/otel/metrics.js +66 -48
- package/dist/otel/metrics.js.map +1 -1
- package/dist/otel/tracing.d.ts +6 -2
- package/dist/otel/tracing.js +71 -24
- package/dist/otel/tracing.js.map +1 -1
- package/dist/otel/utils.d.ts +11 -0
- package/dist/otel/utils.js +34 -0
- package/dist/otel/utils.js.map +1 -0
- package/dist/semantic-convention.d.ts +44 -5
- package/dist/semantic-convention.js +51 -8
- package/dist/semantic-convention.js.map +1 -1
- package/dist/types.d.ts +74 -22
- package/package.json +41 -9
package/README.md
CHANGED
|
@@ -202,7 +202,7 @@ Below is a detailed overview of the configuration options available, allowing yo
|
|
|
202
202
|
| `traceContent` | Enables tracing of content for deeper insights. | `true` | No |
|
|
203
203
|
| `disabledInstrumentations` | List of instrumentations to disable. | `undefined` | No |
|
|
204
204
|
| `instrumentations` | Object of instrumentation modules for manual patching | `undefined` | No |
|
|
205
|
-
| `
|
|
205
|
+
| `pricingJson` | URL or file path of the pricing JSON file. | `https://github.com/openlit/openlit/blob/main/assets/pricing.json` | No |
|
|
206
206
|
|
|
207
207
|
### OpenLIT Prompt Hub - `Openlit.getPrompt()`
|
|
208
208
|
|
|
@@ -234,6 +234,40 @@ Below are the parameters for use with the SDK for OpenLIT Vault for secret manag
|
|
|
234
234
|
|
|
235
235
|
|
|
236
236
|
|
|
237
|
+
### OpenLIT Rule Engine - `Openlit.evaluateRule()`
|
|
238
|
+
|
|
239
|
+
Evaluate trace attributes against the OpenLIT Rule Engine to retrieve matching rules and associated entities (contexts, prompts, evaluation configurations).
|
|
240
|
+
|
|
241
|
+
| Parameter | Description |
|
|
242
|
+
|--------------------|------------------------------------------------------------------------------------------------------------------------------------|
|
|
243
|
+
| `url` | Sets the OpenLIT URL. Defaults to the `OPENLIT_URL` environment variable or `http://127.0.0.1:3000`. |
|
|
244
|
+
| `apiKey` | Sets the OpenLIT API Key. Can also be provided via the `OPENLIT_API_KEY` environment variable. |
|
|
245
|
+
| `entityType` | Type of entity to match: `"context"`, `"prompt"`, or `"evaluation"`. |
|
|
246
|
+
| `fields` | Object of trace attributes to evaluate against rules. e.g. `{ "gen_ai.system": "openai" }` |
|
|
247
|
+
| `includeEntityData`| If `true`, include full entity data in the response. Default: `false`. Optional |
|
|
248
|
+
| `entityInputs` | Optional object of inputs for entity resolution (e.g. prompt variables). |
|
|
249
|
+
|
|
250
|
+
#### Example
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import Openlit from 'openlit';
|
|
254
|
+
|
|
255
|
+
const result = await Openlit.evaluateRule({
|
|
256
|
+
entityType: 'context',
|
|
257
|
+
fields: {
|
|
258
|
+
'gen_ai.system': 'openai',
|
|
259
|
+
'gen_ai.request.model': 'gpt-4',
|
|
260
|
+
'service.name': 'my-app',
|
|
261
|
+
},
|
|
262
|
+
includeEntityData: true,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
if (!('err' in result)) {
|
|
266
|
+
console.log('Matching rules:', result.matchingRuleIds);
|
|
267
|
+
console.log('Entities:', result.entities);
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
237
271
|
## 🌱 Contributing
|
|
238
272
|
|
|
239
273
|
Whether it's big or small, we love contributions 💚. Check out our [Contribution guide](../../CONTRIBUTING.md) to get started
|
package/dist/config.d.ts
CHANGED
|
@@ -7,8 +7,16 @@ export default class OpenlitConfig {
|
|
|
7
7
|
static otlpEndpoint?: OpenlitConfigInterface['otlpEndpoint'];
|
|
8
8
|
static otlpHeaders?: OpenlitConfigInterface['otlpHeaders'];
|
|
9
9
|
static disableBatch?: OpenlitConfigInterface['disableBatch'];
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
static
|
|
13
|
-
static
|
|
10
|
+
static captureMessageContent?: OpenlitConfigInterface['captureMessageContent'];
|
|
11
|
+
static pricingJson?: OpenlitConfigInterface['pricingJson'];
|
|
12
|
+
static disableMetrics?: boolean;
|
|
13
|
+
static disableEvents?: boolean;
|
|
14
|
+
static maxContentLength?: number | null;
|
|
15
|
+
static customSpanAttributes?: Record<string, string> | null;
|
|
16
|
+
static updateConfig({ environment, applicationName, tracer, otlpEndpoint, otlpHeaders, disableBatch, captureMessageContent, pricingJson, disableMetrics, disableEvents, maxContentLength, customSpanAttributes, }: Partial<OpenlitConfigInterface> & {
|
|
17
|
+
disableMetrics?: boolean;
|
|
18
|
+
disableEvents?: boolean;
|
|
19
|
+
maxContentLength?: number | null;
|
|
20
|
+
customSpanAttributes?: Record<string, string> | null;
|
|
21
|
+
}): void;
|
|
14
22
|
}
|
package/dist/config.js
CHANGED
|
@@ -1,29 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const helpers_1 = __importDefault(require("./helpers"));
|
|
7
3
|
class OpenlitConfig {
|
|
8
|
-
static
|
|
9
|
-
try {
|
|
10
|
-
const response = await helpers_1.default.fetchPricingInfo(pricing_json);
|
|
11
|
-
this.pricingInfo = response;
|
|
12
|
-
}
|
|
13
|
-
catch (e) {
|
|
14
|
-
this.pricingInfo = {};
|
|
15
|
-
}
|
|
16
|
-
return this.pricingInfo;
|
|
17
|
-
}
|
|
18
|
-
static updateConfig({ environment = 'default', applicationName = 'default', tracer, otlpEndpoint, otlpHeaders, disableBatch = true, traceContent = true, pricing_json, }) {
|
|
4
|
+
static updateConfig({ environment = 'default', applicationName = 'default', tracer, otlpEndpoint, otlpHeaders, disableBatch = false, captureMessageContent = true, pricingJson, disableMetrics = false, disableEvents = false, maxContentLength = null, customSpanAttributes = null, }) {
|
|
19
5
|
this.environment = environment;
|
|
20
6
|
this.applicationName = applicationName;
|
|
21
7
|
this.tracer = tracer;
|
|
22
8
|
this.otlpEndpoint = otlpEndpoint;
|
|
23
9
|
this.otlpHeaders = otlpHeaders;
|
|
24
10
|
this.disableBatch = disableBatch;
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
11
|
+
this.captureMessageContent = captureMessageContent;
|
|
12
|
+
this.pricingJson = pricingJson;
|
|
13
|
+
this.disableMetrics = disableMetrics;
|
|
14
|
+
this.disableEvents = disableEvents;
|
|
15
|
+
this.maxContentLength = maxContentLength;
|
|
16
|
+
this.customSpanAttributes = customSpanAttributes;
|
|
27
17
|
}
|
|
28
18
|
}
|
|
29
19
|
exports.default = OpenlitConfig;
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAEA,MAAqB,aAAa;IAehC,MAAM,CAAC,YAAY,CAAC,EAClB,WAAW,GAAG,SAAS,EACvB,eAAe,GAAG,SAAS,EAC3B,MAAM,EACN,YAAY,EACZ,WAAW,EACX,YAAY,GAAG,KAAK,EACpB,qBAAqB,GAAG,IAAI,EAC5B,WAAW,EACX,cAAc,GAAG,KAAK,EACtB,aAAa,GAAG,KAAK,EACrB,gBAAgB,GAAG,IAAI,EACvB,oBAAoB,GAAG,IAAI,GAM5B;QACC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAA0C,CAAC;QACzD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IACnD,CAAC;CACF;AA/CD,gCA+CC"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.llmResponseAnthropic = llmResponseAnthropic;
|
|
7
|
-
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
8
4
|
async function llmResponseAnthropic({ prompt, model, apiKey }) {
|
|
9
|
-
|
|
5
|
+
let Anthropic;
|
|
6
|
+
try {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
+
Anthropic = require('@anthropic-ai/sdk').default;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new Error("openlit eval features require the '@anthropic-ai/sdk' package. Install it with: npm install @anthropic-ai/sdk");
|
|
12
|
+
}
|
|
13
|
+
const client = new Anthropic({ apiKey });
|
|
10
14
|
const usedModel = model || 'claude-3-opus-20240229';
|
|
11
15
|
const response = await client.messages.create({
|
|
12
16
|
model: usedModel,
|
|
@@ -30,7 +34,7 @@ async function llmResponseAnthropic({ prompt, model, apiKey }) {
|
|
|
30
34
|
// Fallback: join all text blocks that have text
|
|
31
35
|
return response.content
|
|
32
36
|
.filter((p) => p.type === 'text' && typeof p.text === 'string')
|
|
33
|
-
.map(p => p.text)
|
|
37
|
+
.map((p) => p.text)
|
|
34
38
|
.join(' ');
|
|
35
39
|
}
|
|
36
40
|
return '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/evals/llm/anthropic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/evals/llm/anthropic.ts"],"names":[],"mappings":";;AAAA,oDA6CC;AA7CM,KAAK,UAAU,oBAAoB,CAAC,EACzC,MAAM,EACN,KAAK,EACL,MAAM,EAKP;IACC,IAAI,SAAc,CAAC;IACnB,IAAI,CAAC;QACH,8DAA8D;QAC9D,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,+GAA+G,CAChH,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,KAAK,IAAI,wBAAwB,CAAC;IACpD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,KAAK,EAAE,SAAS;QAChB,UAAU,EAAE,IAAI;QAChB,QAAQ,EAAE;YACR,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;SAClC;QACD,WAAW,EAAE,GAAG;QAChB,wEAAwE;KACzE,CAAC,CAAC;IACH,gDAAgD;IAChD,IAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC,OAAO,CAAC;IAClE,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACpC,gDAAgD;QAChD,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;YACpC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC9F,OAAO,IAAI,CAAC,IAAI,CAAC;YACnB,CAAC;QACH,CAAC;QACD,gDAAgD;QAChD,OAAO,QAAQ,CAAC,OAAO;aACpB,MAAM,CAAC,CAAC,CAAmC,EAAwC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC;aACtI,GAAG,CAAC,CAAC,CAAmB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aACpC,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/dist/evals/llm/openai.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.llmResponseOpenAI = llmResponseOpenAI;
|
|
7
|
-
const openai_1 = __importDefault(require("openai"));
|
|
8
4
|
async function llmResponseOpenAI({ prompt, model, apiKey, baseUrl }) {
|
|
9
|
-
|
|
5
|
+
let OpenAI;
|
|
6
|
+
try {
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
+
OpenAI = require('openai').default;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new Error("openlit eval features require the 'openai' package. Install it with: npm install openai");
|
|
12
|
+
}
|
|
13
|
+
const client = new OpenAI({
|
|
10
14
|
apiKey,
|
|
11
15
|
baseURL: baseUrl || 'https://api.openai.com/v1',
|
|
12
16
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/evals/llm/openai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../../src/evals/llm/openai.ts"],"names":[],"mappings":";;AAAA,8CAkCC;AAlCM,KAAK,UAAU,iBAAiB,CAAC,EACtC,MAAM,EACN,KAAK,EACL,MAAM,EACN,OAAO,EAMR;IACC,IAAI,MAAW,CAAC;IAChB,IAAI,CAAC;QACH,8DAA8D;QAC9D,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,MAAM;QACN,OAAO,EAAE,OAAO,IAAI,2BAA2B;KAChD,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,KAAK,IAAI,QAAQ,CAAC;IACpC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QACpD,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAE;YACR,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE;SAClC;QACD,WAAW,EAAE,GAAG;QAChB,eAAe,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE;KACzC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const rule_engine_1 = __importDefault(require("../rule-engine"));
|
|
7
|
+
// Mock OpenlitConfig
|
|
8
|
+
jest.mock('../../config', () => ({
|
|
9
|
+
__esModule: true,
|
|
10
|
+
default: {
|
|
11
|
+
applicationName: 'test-app',
|
|
12
|
+
environment: 'test',
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
// Mock constant
|
|
16
|
+
jest.mock('../../constant', () => ({
|
|
17
|
+
OPENLIT_URL: 'http://127.0.0.1:3000',
|
|
18
|
+
}));
|
|
19
|
+
// Save original env
|
|
20
|
+
const originalEnv = process.env;
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
jest.restoreAllMocks();
|
|
23
|
+
process.env = { ...originalEnv };
|
|
24
|
+
delete process.env.OPENLIT_URL;
|
|
25
|
+
delete process.env.OPENLIT_API_KEY;
|
|
26
|
+
});
|
|
27
|
+
afterAll(() => {
|
|
28
|
+
process.env = originalEnv;
|
|
29
|
+
});
|
|
30
|
+
describe('RuleEngine.evaluateRule', () => {
|
|
31
|
+
it('sends correct request to rule-engine evaluate endpoint', async () => {
|
|
32
|
+
const mockResponse = {
|
|
33
|
+
matchingRuleIds: ['rule-1'],
|
|
34
|
+
entities: [{ rule_id: 'rule-1', entity_type: 'context', entity_id: 'ctx-1' }],
|
|
35
|
+
};
|
|
36
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
37
|
+
ok: true,
|
|
38
|
+
json: () => Promise.resolve(mockResponse),
|
|
39
|
+
});
|
|
40
|
+
const result = await rule_engine_1.default.evaluateRule({
|
|
41
|
+
url: 'http://localhost:3000',
|
|
42
|
+
apiKey: 'test-key',
|
|
43
|
+
entityType: 'context',
|
|
44
|
+
fields: { 'gen_ai.system': 'openai' },
|
|
45
|
+
});
|
|
46
|
+
expect(global.fetch).toHaveBeenCalledTimes(1);
|
|
47
|
+
const [url, options] = global.fetch.mock.calls[0];
|
|
48
|
+
expect(url).toBe('http://localhost:3000/api/rule-engine/evaluate');
|
|
49
|
+
expect(options.method).toBe('POST');
|
|
50
|
+
expect(options.headers.Authorization).toBe('Bearer test-key');
|
|
51
|
+
const body = JSON.parse(options.body);
|
|
52
|
+
expect(body.entity_type).toBe('context');
|
|
53
|
+
expect(body.fields).toEqual({ 'gen_ai.system': 'openai' });
|
|
54
|
+
expect(body.source).toBe('ts-sdk');
|
|
55
|
+
expect(result).toEqual(mockResponse);
|
|
56
|
+
});
|
|
57
|
+
it('returns error object on HTTP error', async () => {
|
|
58
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
59
|
+
ok: false,
|
|
60
|
+
status: 401,
|
|
61
|
+
});
|
|
62
|
+
const result = await rule_engine_1.default.evaluateRule({
|
|
63
|
+
url: 'http://localhost:3000',
|
|
64
|
+
apiKey: 'bad-key',
|
|
65
|
+
entityType: 'context',
|
|
66
|
+
fields: {},
|
|
67
|
+
});
|
|
68
|
+
expect(result).toHaveProperty('err');
|
|
69
|
+
expect(result.err).toContain('401');
|
|
70
|
+
});
|
|
71
|
+
it('returns error object on network failure', async () => {
|
|
72
|
+
global.fetch = jest.fn().mockRejectedValue(new Error('Network error'));
|
|
73
|
+
const result = await rule_engine_1.default.evaluateRule({
|
|
74
|
+
url: 'http://localhost:3000',
|
|
75
|
+
apiKey: 'test-key',
|
|
76
|
+
entityType: 'context',
|
|
77
|
+
fields: {},
|
|
78
|
+
});
|
|
79
|
+
expect(result).toHaveProperty('err');
|
|
80
|
+
expect(result.err).toContain('Network error');
|
|
81
|
+
});
|
|
82
|
+
it('uses OPENLIT_URL env var as fallback', async () => {
|
|
83
|
+
process.env.OPENLIT_URL = 'http://env-host:4000';
|
|
84
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
85
|
+
ok: true,
|
|
86
|
+
json: () => Promise.resolve({ matchingRuleIds: [] }),
|
|
87
|
+
});
|
|
88
|
+
await rule_engine_1.default.evaluateRule({
|
|
89
|
+
apiKey: 'key',
|
|
90
|
+
entityType: 'context',
|
|
91
|
+
fields: {},
|
|
92
|
+
});
|
|
93
|
+
const [url] = global.fetch.mock.calls[0];
|
|
94
|
+
expect(url).toBe('http://env-host:4000/api/rule-engine/evaluate');
|
|
95
|
+
});
|
|
96
|
+
it('uses OPENLIT_API_KEY env var as fallback', async () => {
|
|
97
|
+
process.env.OPENLIT_API_KEY = 'env-api-key';
|
|
98
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
99
|
+
ok: true,
|
|
100
|
+
json: () => Promise.resolve({ matchingRuleIds: [] }),
|
|
101
|
+
});
|
|
102
|
+
await rule_engine_1.default.evaluateRule({
|
|
103
|
+
url: 'http://localhost:3000',
|
|
104
|
+
entityType: 'context',
|
|
105
|
+
fields: {},
|
|
106
|
+
});
|
|
107
|
+
const [, options] = global.fetch.mock.calls[0];
|
|
108
|
+
expect(options.headers.Authorization).toBe('Bearer env-api-key');
|
|
109
|
+
});
|
|
110
|
+
it('passes includeEntityData and entityInputs', async () => {
|
|
111
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
112
|
+
ok: true,
|
|
113
|
+
json: () => Promise.resolve({ matchingRuleIds: [], entity_data: {} }),
|
|
114
|
+
});
|
|
115
|
+
await rule_engine_1.default.evaluateRule({
|
|
116
|
+
url: 'http://localhost:3000',
|
|
117
|
+
apiKey: 'key',
|
|
118
|
+
entityType: 'prompt',
|
|
119
|
+
fields: { key: 'val' },
|
|
120
|
+
includeEntityData: true,
|
|
121
|
+
entityInputs: { variables: { name: 'test' } },
|
|
122
|
+
});
|
|
123
|
+
const body = JSON.parse(global.fetch.mock.calls[0][1].body);
|
|
124
|
+
expect(body.include_entity_data).toBe(true);
|
|
125
|
+
expect(body.entity_inputs).toEqual({ variables: { name: 'test' } });
|
|
126
|
+
expect(body.entity_type).toBe('prompt');
|
|
127
|
+
});
|
|
128
|
+
it('includes metaProperties from OpenlitConfig', async () => {
|
|
129
|
+
global.fetch = jest.fn().mockResolvedValue({
|
|
130
|
+
ok: true,
|
|
131
|
+
json: () => Promise.resolve({ matchingRuleIds: [] }),
|
|
132
|
+
});
|
|
133
|
+
await rule_engine_1.default.evaluateRule({
|
|
134
|
+
url: 'http://localhost:3000',
|
|
135
|
+
apiKey: 'key',
|
|
136
|
+
entityType: 'context',
|
|
137
|
+
fields: {},
|
|
138
|
+
});
|
|
139
|
+
const body = JSON.parse(global.fetch.mock.calls[0][1].body);
|
|
140
|
+
expect(body.metaProperties).toEqual({
|
|
141
|
+
applicationName: 'test-app',
|
|
142
|
+
environment: 'test',
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=rule-engine.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-engine.test.js","sourceRoot":"","sources":["../../../src/features/__tests__/rule-engine.test.ts"],"names":[],"mappings":";;;;;AAAA,iEAAwC;AAExC,qBAAqB;AACrB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC;IAC/B,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE;QACP,eAAe,EAAE,UAAU;QAC3B,WAAW,EAAE,MAAM;KACpB;CACF,CAAC,CAAC,CAAC;AAEJ,gBAAgB;AAChB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC;IACjC,WAAW,EAAE,uBAAuB;CACrC,CAAC,CAAC,CAAC;AAEJ,oBAAoB;AACpB,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;AAEhC,UAAU,CAAC,GAAG,EAAE;IACd,IAAI,CAAC,eAAe,EAAE,CAAC;IACvB,OAAO,CAAC,GAAG,GAAG,EAAE,GAAG,WAAW,EAAE,CAAC;IACjC,OAAO,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IAC/B,OAAO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E,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACpE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;YACzC,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC;SACrD,CAAC,CAAC;QAEH,MAAM,qBAAU,CAAC,YAAY,CAAC;YAC5B,GAAG,EAAE,uBAAuB;YAC5B,MAAM,EAAE,KAAK;YACb,UAAU,EAAE,SAAS;YACrB,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;QAEH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAE,MAAM,CAAC,KAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC3E,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC;YAClC,eAAe,EAAE,UAAU;YAC3B,WAAW,EAAE,MAAM;SACpB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/features/base.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import PromptHub from './prompt-hub';
|
|
2
|
+
import RuleEngine from './rule-engine';
|
|
2
3
|
import Vault from './vault';
|
|
3
4
|
export default class BaseOpenlit {
|
|
4
5
|
static getPrompts: typeof PromptHub.getPrompts;
|
|
5
6
|
static getSecrets: typeof Vault.getSecrets;
|
|
7
|
+
static evaluateRule: typeof RuleEngine.evaluateRule;
|
|
6
8
|
}
|
package/dist/features/base.js
CHANGED
|
@@ -4,10 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const prompt_hub_1 = __importDefault(require("./prompt-hub"));
|
|
7
|
+
const rule_engine_1 = __importDefault(require("./rule-engine"));
|
|
7
8
|
const vault_1 = __importDefault(require("./vault"));
|
|
8
9
|
class BaseOpenlit {
|
|
9
10
|
}
|
|
10
11
|
BaseOpenlit.getPrompts = prompt_hub_1.default.getPrompts;
|
|
11
12
|
BaseOpenlit.getSecrets = vault_1.default.getSecrets;
|
|
13
|
+
BaseOpenlit.evaluateRule = rule_engine_1.default.evaluateRule;
|
|
12
14
|
exports.default = BaseOpenlit;
|
|
13
15
|
//# sourceMappingURL=base.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/features/base.ts"],"names":[],"mappings":";;;;;AAAA,8DAAqC;AACrC,oDAA4B;AAE5B,MAAqB,WAAW;;AACvB,sBAAU,GAAG,oBAAS,CAAC,UAAU,CAAC;AAClC,sBAAU,GAAG,eAAK,CAAC,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/features/base.ts"],"names":[],"mappings":";;;;;AAAA,8DAAqC;AACrC,gEAAuC;AACvC,oDAA4B;AAE5B,MAAqB,WAAW;;AACvB,sBAAU,GAAG,oBAAS,CAAC,UAAU,CAAC;AAClC,sBAAU,GAAG,eAAK,CAAC,UAAU,CAAC;AAC9B,wBAAY,GAAG,qBAAU,CAAC,YAAY,CAAC;kBAH3B,WAAW"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const config_1 = __importDefault(require("../config"));
|
|
7
|
+
const constant_1 = require("../constant");
|
|
8
|
+
class RuleEngine {
|
|
9
|
+
static async evaluateRule(options) {
|
|
10
|
+
const url = process.env.OPENLIT_URL || options.url || constant_1.OPENLIT_URL;
|
|
11
|
+
const apiKey = process.env.OPENLIT_API_KEY || options.apiKey || '';
|
|
12
|
+
const metaProperties = {
|
|
13
|
+
applicationName: config_1.default.applicationName,
|
|
14
|
+
environment: config_1.default.environment,
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
const response = await fetch(`${url}/api/rule-engine/evaluate`, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
entity_type: options.entityType,
|
|
21
|
+
fields: options.fields,
|
|
22
|
+
include_entity_data: options.includeEntityData || false,
|
|
23
|
+
entity_inputs: options.entityInputs,
|
|
24
|
+
metaProperties,
|
|
25
|
+
source: 'ts-sdk',
|
|
26
|
+
}),
|
|
27
|
+
headers: {
|
|
28
|
+
Authorization: `Bearer ${apiKey}`,
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
.then(async (response) => {
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
return {
|
|
35
|
+
err: `Openlit Error : HTTP error! Status: ${response.status}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return response.json();
|
|
39
|
+
})
|
|
40
|
+
.then((resp) => {
|
|
41
|
+
return resp;
|
|
42
|
+
});
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
console.log(e);
|
|
47
|
+
if (e && typeof e.toString === 'function') {
|
|
48
|
+
return {
|
|
49
|
+
err: `Openlit Error : ${e.toString()}`,
|
|
50
|
+
data: null,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
err: `Openlit Error : ${e}`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.default = RuleEngine;
|
|
60
|
+
//# sourceMappingURL=rule-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-engine.js","sourceRoot":"","sources":["../../src/features/rule-engine.ts"],"names":[],"mappings":";;;;;AAAA,uDAAsC;AACtC,0CAA0C;AAG1C,MAAqB,UAAU;IAC7B,MAAM,CAAC,KAAK,CAAC,YAAY,CACvB,OAA0B;QAE1B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,IAAI,sBAAW,CAAC;QAClE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;QAEnE,MAAM,cAAc,GAAG;YACrB,eAAe,EAAE,gBAAa,CAAC,eAAe;YAC9C,WAAW,EAAE,gBAAa,CAAC,WAAW;SACvC,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,2BAA2B,EAAE;gBAC9D,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,WAAW,EAAE,OAAO,CAAC,UAAU;oBAC/B,MAAM,EAAE,OAAO,CAAC,MAAM;oBACtB,mBAAmB,EAAE,OAAO,CAAC,iBAAiB,IAAI,KAAK;oBACvD,aAAa,EAAE,OAAO,CAAC,YAAY;oBACnC,cAAc;oBACd,MAAM,EAAE,QAAQ;iBACjB,CAAC;gBACF,OAAO,EAAE;oBACP,aAAa,EAAE,UAAU,MAAM,EAAE;oBACjC,cAAc,EAAE,kBAAkB;iBACnC;aACF,CAAC;iBACC,IAAI,CAAC,KAAK,EAAE,QAAa,EAAE,EAAE;gBAC5B,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,OAAO;wBACL,GAAG,EAAE,uCAAuC,QAAQ,CAAC,MAAM,EAAE;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AED,OAAO;gBACL,GAAG,EAAE,mBAAmB,CAAC,EAAE;aAC5B,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAzDD,wBAyDC"}
|
package/dist/helpers.d.ts
CHANGED
|
@@ -1,4 +1,90 @@
|
|
|
1
|
-
import { Span } from '@opentelemetry/api';
|
|
1
|
+
import { Attributes, Context, Span } from '@opentelemetry/api';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true when a framework instrumentor (LangChain, LiteLLM, etc.)
|
|
4
|
+
* owns the current LLM span. Provider-level wrappers (OpenAI, Anthropic, …)
|
|
5
|
+
* must skip their own span creation when this returns true.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isFrameworkLlmActive(): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Run `fn` with the framework-LLM-active flag set. All provider wrappers
|
|
10
|
+
* invoked inside `fn` will see `isFrameworkLlmActive() === true`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function runWithFrameworkLlm<T>(fn: () => T): T;
|
|
13
|
+
/**
|
|
14
|
+
* Set framework-LLM-active flag in the current execution context.
|
|
15
|
+
* Used by SpanProcessor-based instrumentations (Strands) where
|
|
16
|
+
* the processor observes spans rather than controlling execution.
|
|
17
|
+
* Mirrors Python's ContextVar.set(True) in Strands processor.
|
|
18
|
+
*/
|
|
19
|
+
export declare function setFrameworkLlmActive(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Reset framework-LLM-active flag in the current execution context.
|
|
22
|
+
* Mirrors Python's ContextVar.reset(token) in Strands processor.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resetFrameworkLlmActive(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns true when a LangGraph wrapper is controlling execution.
|
|
27
|
+
* LangChain's callback handler skips its own invoke_workflow span when true.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isLangGraphActive(): boolean;
|
|
30
|
+
export declare function runWithLangGraph<T>(fn: () => T): T;
|
|
31
|
+
/**
|
|
32
|
+
* Returns true when a create_agent span is already being handled
|
|
33
|
+
* (prevents duplicate spans between LangChain and LangGraph).
|
|
34
|
+
*/
|
|
35
|
+
export declare function isCreateAgentActive(): boolean;
|
|
36
|
+
export declare function runWithCreateAgent<T>(fn: () => T): T;
|
|
37
|
+
/**
|
|
38
|
+
* Propagate conversation ID from invoke_workflow to child node spans.
|
|
39
|
+
* Mirrors Python's set_langgraph_conversation_id / get_langgraph_conversation_id.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getLangGraphConversationId(): string | undefined;
|
|
42
|
+
export declare function runWithLangGraphConversationId<T>(conversationId: string, fn: () => T): T;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the OTel context set by a framework processor (OpenAI Agents, etc.)
|
|
45
|
+
* so that provider wrappers can create spans as children of framework spans.
|
|
46
|
+
* Mirrors Python's context_api.attach(set_span_in_context(span)).
|
|
47
|
+
*/
|
|
48
|
+
export declare function getFrameworkParentContext(): Context | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Set the OTel parent context for provider span creation.
|
|
51
|
+
* Called by processor-based frameworks that cannot use context.with().
|
|
52
|
+
*/
|
|
53
|
+
export declare function setFrameworkParentContext(ctx: Context): void;
|
|
54
|
+
/**
|
|
55
|
+
* Clear the framework parent context.
|
|
56
|
+
*/
|
|
57
|
+
export declare function clearFrameworkParentContext(): void;
|
|
58
|
+
export declare function getServerAddressForProvider(provider: string): [string, number];
|
|
59
|
+
/**
|
|
60
|
+
* Apply global (from init) and context-scoped (from usingAttributes /
|
|
61
|
+
* injectAdditionalAttributes) custom attributes to a span.
|
|
62
|
+
* Global attributes are applied first; context attributes override on conflict.
|
|
63
|
+
* Matches Python's _apply_custom_span_attributes().
|
|
64
|
+
*/
|
|
65
|
+
export declare function applyCustomSpanAttributes(span: Span): void;
|
|
66
|
+
/**
|
|
67
|
+
* Get merged custom attributes (global + context) for use in events.
|
|
68
|
+
* Returns a flat object; context attributes override global on conflict.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getMergedCustomAttributes(): Record<string, any>;
|
|
71
|
+
/**
|
|
72
|
+
* Run a function with custom span attributes attached to all
|
|
73
|
+
* auto-instrumented spans created during its execution.
|
|
74
|
+
* Matches Python's openlit.inject_additional_attributes().
|
|
75
|
+
*/
|
|
76
|
+
export declare function injectAdditionalAttributes<T>(fn: () => T, attributes: Record<string, any>): T;
|
|
77
|
+
/**
|
|
78
|
+
* Context wrapper that adds custom attributes to all auto-instrumented
|
|
79
|
+
* spans created within its callback scope.
|
|
80
|
+
* Matches Python's openlit.using_attributes() context manager.
|
|
81
|
+
*
|
|
82
|
+
* Usage:
|
|
83
|
+
* await usingAttributes({"user.id": "u1", "team": "ml"}, async () => {
|
|
84
|
+
* await client.chat.completions.create(...);
|
|
85
|
+
* });
|
|
86
|
+
*/
|
|
87
|
+
export declare function usingAttributes<T>(attributes: Record<string, any>, fn: () => T): T;
|
|
2
88
|
export default class OpenLitHelper {
|
|
3
89
|
static readonly PROMPT_TOKEN_FACTOR = 1000;
|
|
4
90
|
static openaiTokens(text: string, model: string): number;
|
|
@@ -18,6 +104,12 @@ export default class OpenLitHelper {
|
|
|
18
104
|
* Format: [{"role": "assistant", "parts": [{"type": "text", "content": "..."}], "finish_reason": "stop"}]
|
|
19
105
|
*/
|
|
20
106
|
static buildOutputMessages(text: string, finishReason: string, toolCalls?: any[]): string;
|
|
107
|
+
/**
|
|
108
|
+
* Emit an inference event via the LoggerProvider, matching Python SDK's
|
|
109
|
+
* gen_ai.client.inference.operation.details event.
|
|
110
|
+
* Falls back to span.addEvent if LoggerProvider is not available.
|
|
111
|
+
*/
|
|
112
|
+
static emitInferenceEvent(span: Span, attrs: Attributes): void;
|
|
21
113
|
static handleException(span: Span, error: Error): void;
|
|
22
114
|
static createStreamProxy(stream: any, generatorFuncResponse: any): Promise<any>;
|
|
23
115
|
}
|