langwatch 0.2.0 → 0.3.0-prerelease.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +268 -1
- package/dist/chunk-4BZATFKJ.mjs +181 -0
- package/dist/chunk-4BZATFKJ.mjs.map +1 -0
- package/dist/chunk-CSC3CMIT.mjs +118 -0
- package/dist/chunk-CSC3CMIT.mjs.map +1 -0
- package/dist/chunk-F63YKTXA.mjs +47 -0
- package/dist/chunk-F63YKTXA.mjs.map +1 -0
- package/dist/chunk-G3AUABT7.js +4 -0
- package/dist/chunk-G3AUABT7.js.map +1 -0
- package/dist/chunk-HPC6Z7J4.js +118 -0
- package/dist/chunk-HPC6Z7J4.js.map +1 -0
- package/dist/chunk-KGDAENGD.js +50 -0
- package/dist/chunk-KGDAENGD.js.map +1 -0
- package/dist/chunk-LD74LVRU.js +47 -0
- package/dist/chunk-LD74LVRU.js.map +1 -0
- package/dist/chunk-OM7VY3XT.mjs +4 -0
- package/dist/chunk-PCQVQ7SB.js +45 -0
- package/dist/chunk-PCQVQ7SB.js.map +1 -0
- package/dist/chunk-PMBEK6YE.mjs +424 -0
- package/dist/chunk-PMBEK6YE.mjs.map +1 -0
- package/dist/chunk-PR3JDWC3.mjs +50 -0
- package/dist/chunk-PR3JDWC3.mjs.map +1 -0
- package/dist/chunk-PTJ6AAI7.js +360 -0
- package/dist/chunk-PTJ6AAI7.js.map +1 -0
- package/dist/chunk-QEWDG5QE.mjs +45 -0
- package/dist/chunk-QEWDG5QE.mjs.map +1 -0
- package/dist/chunk-REUCVT7A.mjs +39 -0
- package/dist/chunk-REUCVT7A.mjs.map +1 -0
- package/dist/chunk-SVJ7SCGB.js +424 -0
- package/dist/chunk-SVJ7SCGB.js.map +1 -0
- package/dist/chunk-VJSOCNPA.js +181 -0
- package/dist/chunk-VJSOCNPA.js.map +1 -0
- package/dist/chunk-WM2GRSRW.js +39 -0
- package/dist/chunk-WM2GRSRW.js.map +1 -0
- package/dist/chunk-Z5J5UI5E.mjs +360 -0
- package/dist/chunk-Z5J5UI5E.mjs.map +1 -0
- package/dist/client-B2HqIKg6.d.ts +51 -0
- package/dist/client-XyCqclCi.d.mts +51 -0
- package/dist/client-browser.d.mts +8 -0
- package/dist/client-browser.d.ts +8 -0
- package/dist/client-browser.js +83 -0
- package/dist/client-browser.js.map +1 -0
- package/dist/client-browser.mjs +83 -0
- package/dist/client-browser.mjs.map +1 -0
- package/dist/client-node.d.mts +8 -0
- package/dist/client-node.d.ts +8 -0
- package/dist/client-node.js +90 -0
- package/dist/client-node.js.map +1 -0
- package/dist/client-node.mjs +90 -0
- package/dist/client-node.mjs.map +1 -0
- package/dist/evaluation/index.d.mts +897 -0
- package/dist/evaluation/index.d.ts +897 -0
- package/dist/evaluation/index.js +13 -0
- package/dist/evaluation/index.js.map +1 -0
- package/dist/evaluation/index.mjs +13 -0
- package/dist/evaluation/index.mjs.map +1 -0
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.mts +64 -0
- package/dist/filterable-batch-span-processor-zO5kcjBY.d.ts +64 -0
- package/dist/index.d.mts +45 -1027
- package/dist/index.d.ts +45 -1027
- package/dist/index.js +11 -27291
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -956
- package/dist/index.mjs.map +1 -1
- package/dist/observability/index.d.mts +260 -0
- package/dist/observability/index.d.ts +260 -0
- package/dist/observability/index.js +20 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/index.mjs +20 -0
- package/dist/observability/index.mjs.map +1 -0
- package/dist/observability/instrumentation/langchain/index.d.mts +40 -0
- package/dist/observability/instrumentation/langchain/index.d.ts +40 -0
- package/dist/observability/instrumentation/langchain/index.js +666 -0
- package/dist/observability/instrumentation/langchain/index.js.map +1 -0
- package/dist/observability/instrumentation/langchain/index.mjs +666 -0
- package/dist/observability/instrumentation/langchain/index.mjs.map +1 -0
- package/dist/prompt/index.d.mts +10 -0
- package/dist/prompt/index.d.ts +10 -0
- package/dist/prompt/index.js +18 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/index.mjs +18 -0
- package/dist/prompt/index.mjs.map +1 -0
- package/dist/prompt-BXJWdbQp.d.mts +1967 -0
- package/dist/prompt-BXJWdbQp.d.ts +1967 -0
- package/dist/record-evaluation-CmxMXa-3.d.mts +25 -0
- package/dist/record-evaluation-CmxMXa-3.d.ts +25 -0
- package/dist/trace-D-bZOuqb.d.mts +622 -0
- package/dist/trace-G2312klE.d.ts +622 -0
- package/package.json +86 -37
- package/.eslintrc.cjs +0 -37
- package/copy-types.sh +0 -17
- package/dist/chunk-LKD2K67J.mjs +0 -717
- package/dist/chunk-LKD2K67J.mjs.map +0 -1
- package/dist/utils-Cv-rUjJ1.d.mts +0 -313
- package/dist/utils-Cv-rUjJ1.d.ts +0 -313
- package/dist/utils.d.mts +0 -2
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +0 -709
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs +0 -11
- package/example/.env.example +0 -12
- package/example/.eslintrc.json +0 -26
- package/example/LICENSE +0 -13
- package/example/README.md +0 -12
- package/example/app/(chat)/chat/[id]/page.tsx +0 -60
- package/example/app/(chat)/layout.tsx +0 -14
- package/example/app/(chat)/page.tsx +0 -27
- package/example/app/actions.ts +0 -156
- package/example/app/globals.css +0 -76
- package/example/app/guardrails/page.tsx +0 -26
- package/example/app/langchain/page.tsx +0 -27
- package/example/app/langchain-rag/page.tsx +0 -28
- package/example/app/late-update/page.tsx +0 -27
- package/example/app/layout.tsx +0 -64
- package/example/app/login/actions.ts +0 -71
- package/example/app/login/page.tsx +0 -18
- package/example/app/manual/page.tsx +0 -27
- package/example/app/new/page.tsx +0 -5
- package/example/app/opengraph-image.png +0 -0
- package/example/app/share/[id]/page.tsx +0 -58
- package/example/app/signup/actions.ts +0 -111
- package/example/app/signup/page.tsx +0 -18
- package/example/app/twitter-image.png +0 -0
- package/example/auth.config.ts +0 -42
- package/example/auth.ts +0 -45
- package/example/components/button-scroll-to-bottom.tsx +0 -36
- package/example/components/chat-history.tsx +0 -49
- package/example/components/chat-list.tsx +0 -52
- package/example/components/chat-message-actions.tsx +0 -40
- package/example/components/chat-message.tsx +0 -80
- package/example/components/chat-panel.tsx +0 -139
- package/example/components/chat-share-dialog.tsx +0 -95
- package/example/components/chat.tsx +0 -84
- package/example/components/clear-history.tsx +0 -75
- package/example/components/empty-screen.tsx +0 -38
- package/example/components/external-link.tsx +0 -29
- package/example/components/footer.tsx +0 -19
- package/example/components/header.tsx +0 -114
- package/example/components/login-button.tsx +0 -42
- package/example/components/login-form.tsx +0 -97
- package/example/components/markdown.tsx +0 -9
- package/example/components/prompt-form.tsx +0 -115
- package/example/components/providers.tsx +0 -17
- package/example/components/sidebar-actions.tsx +0 -125
- package/example/components/sidebar-desktop.tsx +0 -19
- package/example/components/sidebar-footer.tsx +0 -16
- package/example/components/sidebar-item.tsx +0 -124
- package/example/components/sidebar-items.tsx +0 -42
- package/example/components/sidebar-list.tsx +0 -38
- package/example/components/sidebar-mobile.tsx +0 -31
- package/example/components/sidebar-toggle.tsx +0 -24
- package/example/components/sidebar.tsx +0 -21
- package/example/components/signup-form.tsx +0 -95
- package/example/components/stocks/events-skeleton.tsx +0 -31
- package/example/components/stocks/events.tsx +0 -30
- package/example/components/stocks/index.tsx +0 -36
- package/example/components/stocks/message.tsx +0 -134
- package/example/components/stocks/spinner.tsx +0 -16
- package/example/components/stocks/stock-purchase.tsx +0 -146
- package/example/components/stocks/stock-skeleton.tsx +0 -22
- package/example/components/stocks/stock.tsx +0 -210
- package/example/components/stocks/stocks-skeleton.tsx +0 -9
- package/example/components/stocks/stocks.tsx +0 -67
- package/example/components/tailwind-indicator.tsx +0 -14
- package/example/components/theme-toggle.tsx +0 -31
- package/example/components/ui/alert-dialog.tsx +0 -141
- package/example/components/ui/badge.tsx +0 -36
- package/example/components/ui/button.tsx +0 -57
- package/example/components/ui/codeblock.tsx +0 -148
- package/example/components/ui/dialog.tsx +0 -122
- package/example/components/ui/dropdown-menu.tsx +0 -205
- package/example/components/ui/icons.tsx +0 -507
- package/example/components/ui/input.tsx +0 -25
- package/example/components/ui/label.tsx +0 -26
- package/example/components/ui/select.tsx +0 -164
- package/example/components/ui/separator.tsx +0 -31
- package/example/components/ui/sheet.tsx +0 -140
- package/example/components/ui/sonner.tsx +0 -31
- package/example/components/ui/switch.tsx +0 -29
- package/example/components/ui/textarea.tsx +0 -24
- package/example/components/ui/tooltip.tsx +0 -30
- package/example/components/user-menu.tsx +0 -53
- package/example/components.json +0 -17
- package/example/instrumentation.ts +0 -11
- package/example/lib/chat/guardrails.tsx +0 -181
- package/example/lib/chat/langchain-rag.tsx +0 -191
- package/example/lib/chat/langchain.tsx +0 -112
- package/example/lib/chat/late-update.tsx +0 -208
- package/example/lib/chat/manual.tsx +0 -605
- package/example/lib/chat/vercel-ai.tsx +0 -576
- package/example/lib/hooks/use-copy-to-clipboard.tsx +0 -33
- package/example/lib/hooks/use-enter-submit.tsx +0 -23
- package/example/lib/hooks/use-local-storage.ts +0 -24
- package/example/lib/hooks/use-scroll-anchor.tsx +0 -86
- package/example/lib/hooks/use-sidebar.tsx +0 -60
- package/example/lib/hooks/use-streamable-text.ts +0 -25
- package/example/lib/types.ts +0 -41
- package/example/lib/utils.ts +0 -89
- package/example/middleware.ts +0 -8
- package/example/next-env.d.ts +0 -5
- package/example/next.config.js +0 -16
- package/example/package-lock.json +0 -10917
- package/example/package.json +0 -84
- package/example/pnpm-lock.yaml +0 -5712
- package/example/postcss.config.js +0 -6
- package/example/prettier.config.cjs +0 -34
- package/example/public/apple-touch-icon.png +0 -0
- package/example/public/favicon-16x16.png +0 -0
- package/example/public/favicon.ico +0 -0
- package/example/public/next.svg +0 -1
- package/example/public/thirteen.svg +0 -1
- package/example/public/vercel.svg +0 -1
- package/example/tailwind.config.ts +0 -81
- package/example/tsconfig.json +0 -35
- package/src/LangWatchExporter.ts +0 -96
- package/src/evaluations.ts +0 -219
- package/src/index.test.ts +0 -402
- package/src/index.ts +0 -596
- package/src/langchain.ts +0 -557
- package/src/server/types/.gitkeep +0 -0
- package/src/typeUtils.ts +0 -89
- package/src/types.ts +0 -82
- package/src/utils.ts +0 -205
- package/ts-to-zod.config.js +0 -24
- package/tsconfig.json +0 -32
- package/tsup.config.ts +0 -10
- package/vitest.config.ts +0 -8
- /package/dist/{utils.mjs.map → chunk-OM7VY3XT.mjs.map} +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/client-shared.ts
|
|
2
|
+
import {
|
|
3
|
+
trace
|
|
4
|
+
} from "@opentelemetry/api";
|
|
5
|
+
function getActualTracerProvider() {
|
|
6
|
+
var _a;
|
|
7
|
+
const potentiallyProxyTracerProvider = trace.getTracerProvider();
|
|
8
|
+
const delegate = (_a = potentiallyProxyTracerProvider == null ? void 0 : potentiallyProxyTracerProvider.getDelegate) == null ? void 0 : _a.call(potentiallyProxyTracerProvider);
|
|
9
|
+
return delegate != null ? delegate : potentiallyProxyTracerProvider;
|
|
10
|
+
}
|
|
11
|
+
function isOtelInitialized() {
|
|
12
|
+
const provider = getActualTracerProvider();
|
|
13
|
+
return provider && typeof provider.addSpanProcessor === "function";
|
|
14
|
+
}
|
|
15
|
+
function mergeResourceIntoExistingTracerProvider(resource) {
|
|
16
|
+
if (!isOtelInitialized()) {
|
|
17
|
+
throw new Error("OpenTelemetry SDK is not initialized, cannot merge resource into existing tracer provider.");
|
|
18
|
+
}
|
|
19
|
+
const provider = getActualTracerProvider();
|
|
20
|
+
if (!(provider == null ? void 0 : provider.resource)) {
|
|
21
|
+
throw new Error("OpenTelemetry SDK is not initialized, provider does not have a resource.");
|
|
22
|
+
}
|
|
23
|
+
if (typeof resource !== "object") {
|
|
24
|
+
throw new Error("OpenTelemetry SDK is not initialized, provider resource is not an object.");
|
|
25
|
+
}
|
|
26
|
+
if (typeof provider.resource.merge !== "function") {
|
|
27
|
+
throw new Error("OpenTelemetry SDK is not initialized, provider resource does not have a merge method.");
|
|
28
|
+
}
|
|
29
|
+
provider.resource = provider.resource.merge(resource);
|
|
30
|
+
}
|
|
31
|
+
function addSpanProcessorToExistingTracerProvider(spanProcessor) {
|
|
32
|
+
if (!isOtelInitialized()) {
|
|
33
|
+
throw new Error("OpenTelemetry SDK is not initialized, cannot add span processor to existing tracer provider.");
|
|
34
|
+
}
|
|
35
|
+
const provider = getActualTracerProvider();
|
|
36
|
+
if (!(provider == null ? void 0 : provider.addSpanProcessor)) {
|
|
37
|
+
throw new Error("OpenTelemetry SDK is not initialized, provider does not have a addSpanProcessor method.");
|
|
38
|
+
}
|
|
39
|
+
provider.addSpanProcessor(spanProcessor);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
isOtelInitialized,
|
|
44
|
+
mergeResourceIntoExistingTracerProvider,
|
|
45
|
+
addSpanProcessorToExistingTracerProvider
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=chunk-F63YKTXA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client-shared.ts"],"sourcesContent":["import {\n trace,\n ProxyTracerProvider,\n} from \"@opentelemetry/api\";\nimport { Resource } from \"@opentelemetry/resources\";\nimport { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\n\n/**\n * Gets the actual tracer provider, handling the proxy delegate pattern.\n *\n * @returns The actual tracer provider or undefined if not available\n */\nfunction getActualTracerProvider(): any {\n const potentiallyProxyTracerProvider = trace.getTracerProvider() as unknown;\n\n // Attempt to get the delegate if it's a ProxyTracerProvider\n const delegate = (potentiallyProxyTracerProvider as ProxyTracerProvider | undefined)?.getDelegate?.();\n\n // Return the delegate if available, otherwise return the original provider\n return delegate ?? (potentiallyProxyTracerProvider as any);\n}\n\n/**\n * Checks if the OpenTelemetry SDK has been initialized anywhere in the process.\n *\n * @returns true if the OpenTelemetry SDK has been initialized, false otherwise.\n */\nexport function isOtelInitialized() {\n const provider = getActualTracerProvider();\n\n // Check if the provider has the addSpanProcessor method, which indicates SDK initialization\n return provider && typeof provider.addSpanProcessor === \"function\";\n}\n\n/**\n * Merges a resource into the existing tracer provider.\n *\n * @param resource - The resource to merge into the existing tracer provider.\n */\nexport function mergeResourceIntoExistingTracerProvider(resource: Resource) {\n if (!isOtelInitialized()) {\n throw new Error(\"OpenTelemetry SDK is not initialized, cannot merge resource into existing tracer provider.\");\n }\n\n const provider = getActualTracerProvider();\n\n if (!provider?.resource) {\n throw new Error(\"OpenTelemetry SDK is not initialized, provider does not have a resource.\");\n }\n if (typeof resource !== \"object\") {\n throw new Error(\"OpenTelemetry SDK is not initialized, provider resource is not an object.\");\n }\n if (typeof provider.resource.merge !== \"function\") {\n throw new Error(\"OpenTelemetry SDK is not initialized, provider resource does not have a merge method.\");\n }\n\n provider.resource = provider.resource.merge(resource);\n}\n\nexport function addSpanProcessorToExistingTracerProvider(spanProcessor: SpanProcessor) {\n if (!isOtelInitialized()) {\n throw new Error(\"OpenTelemetry SDK is not initialized, cannot add span processor to existing tracer provider.\");\n }\n\n const provider = getActualTracerProvider();\n\n if (!provider?.addSpanProcessor) {\n throw new Error(\"OpenTelemetry SDK is not initialized, provider does not have a addSpanProcessor method.\");\n }\n\n provider.addSpanProcessor(spanProcessor);\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAEK;AASP,SAAS,0BAA+B;AAZxC;AAaE,QAAM,iCAAiC,MAAM,kBAAkB;AAG/D,QAAM,YAAY,sFAAoE,gBAApE;AAGlB,SAAO,8BAAa;AACtB;AAOO,SAAS,oBAAoB;AAClC,QAAM,WAAW,wBAAwB;AAGzC,SAAO,YAAY,OAAO,SAAS,qBAAqB;AAC1D;AAOO,SAAS,wCAAwC,UAAoB;AAC1E,MAAI,CAAC,kBAAkB,GAAG;AACxB,UAAM,IAAI,MAAM,4FAA4F;AAAA,EAC9G;AAEA,QAAM,WAAW,wBAAwB;AAEzC,MAAI,EAAC,qCAAU,WAAU;AACvB,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC5F;AACA,MAAI,OAAO,aAAa,UAAU;AAChC,UAAM,IAAI,MAAM,2EAA2E;AAAA,EAC7F;AACA,MAAI,OAAO,SAAS,SAAS,UAAU,YAAY;AACjD,UAAM,IAAI,MAAM,uFAAuF;AAAA,EACzG;AAEA,WAAS,WAAW,SAAS,SAAS,MAAM,QAAQ;AACtD;AAEO,SAAS,yCAAyC,eAA8B;AACrF,MAAI,CAAC,kBAAkB,GAAG;AACxB,UAAM,IAAI,MAAM,8FAA8F;AAAA,EAChH;AAEA,QAAM,WAAW,wBAAwB;AAEzC,MAAI,EAAC,qCAAU,mBAAkB;AAC/B,UAAM,IAAI,MAAM,yFAAyF;AAAA,EAC3G;AAEA,WAAS,iBAAiB,aAAa;AACzC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-G3AUABT7.js"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-G3AUABT7.js"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkPCQVQ7SBjs = require('./chunk-PCQVQ7SB.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkSVJ7SCGBjs = require('./chunk-SVJ7SCGB.js');
|
|
9
|
+
|
|
10
|
+
// src/internal/api/errors.ts
|
|
11
|
+
var LangWatchApiError = class extends Error {
|
|
12
|
+
constructor(message, response) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.httpStatus = response.status;
|
|
15
|
+
this.httpStatusText = response.statusText;
|
|
16
|
+
}
|
|
17
|
+
async safeParseBody(response) {
|
|
18
|
+
var _a;
|
|
19
|
+
try {
|
|
20
|
+
if ((_a = response.headers.get("Content-Type")) == null ? void 0 : _a.includes("application/json")) {
|
|
21
|
+
const json = await response.json();
|
|
22
|
+
this.body = json;
|
|
23
|
+
if (json.error && typeof json.error === "string") {
|
|
24
|
+
this.apiError = json.error;
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.body = await response.text();
|
|
29
|
+
} catch (e) {
|
|
30
|
+
this.body = null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/evaluation/run-evaluation.ts
|
|
36
|
+
var _api = require('@opentelemetry/api');
|
|
37
|
+
async function runEvaluation(details) {
|
|
38
|
+
return await _chunkSVJ7SCGBjs.tracer.startActiveSpan("run evaluation", async (span) => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
span.setType(details.asGuardrail ? "guardrail" : "evaluation");
|
|
41
|
+
try {
|
|
42
|
+
const evaluatorId = "slug" in details ? details.slug : details.evaluator;
|
|
43
|
+
const request = {
|
|
44
|
+
trace_id: span.spanContext().traceId,
|
|
45
|
+
span_id: span.spanContext().spanId,
|
|
46
|
+
data: details.data,
|
|
47
|
+
name: details.name,
|
|
48
|
+
settings: details.settings,
|
|
49
|
+
as_guardrail: details.asGuardrail
|
|
50
|
+
};
|
|
51
|
+
if (_chunkPCQVQ7SBjs.canAutomaticallyCaptureInput.call(void 0, )) {
|
|
52
|
+
span.setInput(request);
|
|
53
|
+
}
|
|
54
|
+
const url = new URL(
|
|
55
|
+
`/api/evaluations/${evaluatorId}/evaluate`,
|
|
56
|
+
_chunkPCQVQ7SBjs.getEndpoint.call(void 0, )
|
|
57
|
+
);
|
|
58
|
+
const response = await fetch(url.toString(), {
|
|
59
|
+
method: "POST",
|
|
60
|
+
headers: {
|
|
61
|
+
"X-Auth-Token": _chunkPCQVQ7SBjs.getApiKey.call(void 0, ),
|
|
62
|
+
"Content-Type": "application/json"
|
|
63
|
+
},
|
|
64
|
+
body: JSON.stringify(request)
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const err = new LangWatchApiError("Unable to run evaluation", response);
|
|
68
|
+
await err.safeParseBody(response);
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
const result = await response.json();
|
|
72
|
+
span.setMetrics({
|
|
73
|
+
cost: (_a = result.cost) == null ? void 0 : _a.amount
|
|
74
|
+
});
|
|
75
|
+
span.setOutputEvaluation((_b = details.asGuardrail) != null ? _b : false, result);
|
|
76
|
+
if (result.status === "processed") {
|
|
77
|
+
return {
|
|
78
|
+
status: "processed",
|
|
79
|
+
passed: result.passed,
|
|
80
|
+
score: result.score,
|
|
81
|
+
details: result.details,
|
|
82
|
+
label: result.label,
|
|
83
|
+
cost: result.cost
|
|
84
|
+
};
|
|
85
|
+
} else if (result.status === "skipped") {
|
|
86
|
+
return {
|
|
87
|
+
status: "skipped",
|
|
88
|
+
details: result.details
|
|
89
|
+
};
|
|
90
|
+
} else if (result.status === "error") {
|
|
91
|
+
return {
|
|
92
|
+
status: "error",
|
|
93
|
+
error_type: result.error_type || "Unknown",
|
|
94
|
+
details: result.details || "Unknown error",
|
|
95
|
+
traceback: result.traceback || []
|
|
96
|
+
};
|
|
97
|
+
} else {
|
|
98
|
+
return {
|
|
99
|
+
status: "error",
|
|
100
|
+
error_type: "UnknownStatus",
|
|
101
|
+
details: `Unknown evaluation status: ${result.status}`,
|
|
102
|
+
traceback: []
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
} catch (error) {
|
|
106
|
+
span.recordException(error);
|
|
107
|
+
span.setStatus({ code: _api.SpanStatusCode.ERROR, message: error == null ? void 0 : error.message });
|
|
108
|
+
throw error;
|
|
109
|
+
} finally {
|
|
110
|
+
span.end();
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
exports.runEvaluation = runEvaluation;
|
|
118
|
+
//# sourceMappingURL=chunk-HPC6Z7J4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/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A;AAAA,UACR,UAAA,EAAa,MAAA,CAAe,WAAA,GAAc,SAAA;AAAA,UAC1C,OAAA,EAAS,MAAA,CAAO,QAAA,GAAW,eAAA;AAAA,UAC3B,SAAA,EAAY,MAAA,CAAe,UAAA,GAAa,CAAC;AAAA,QAC3C,CAAA;AAAA,MACF,EAAA,KAAO;AACL,QAAA,OAAO;AAAA,UACL,MAAA,EAAQ,OAAA;AAAA,UACR,UAAA,EAAY,eAAA;AAAA,UACZ,OAAA,EAAS,CAAA,2BAAA,EAA8B,MAAA,CAAO,MAAM,CAAA,CAAA;AACxC,UAAA;AACd,QAAA;AACF,MAAA;AACc,IAAA;AACqB,MAAA;AACoB,MAAA;AACjD,MAAA;AACN,IAAA;AACS,MAAA;AACX,IAAA;AACD,EAAA;AACH;AFnB+D;AACA;AACA;AACA","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-HPC6Z7J4.js","sourcesContent":[null,"export class LangWatchApiError extends Error {\n public readonly httpStatus: number;\n public readonly httpStatusText: string;\n public apiError: string | undefined;\n public body: unknown;\n\n constructor(message: string, response: Response) {\n super(message);\n this.httpStatus = response.status;\n this.httpStatusText = response.statusText;\n }\n\n async safeParseBody(response: Response): Promise<void> {\n try {\n if (response.headers.get(\"Content-Type\")?.includes(\"application/json\")) {\n const json = await response.json();\n\n this.body = json;\n\n if (json.error && typeof json.error === \"string\") {\n this.apiError = json.error;\n }\n\n return;\n }\n\n this.body = await response.text();\n } catch {\n this.body = null;\n }\n }\n}\n","import { LangWatchApiError } from \"../internal/api/errors\";\nimport { canAutomaticallyCaptureInput, getApiKey, getEndpoint } from \"../client\";\nimport { Conversation } from \"../internal/generated/types/evaluations\";\nimport {\n Evaluators,\n EvaluatorTypes,\n SingleEvaluationResult,\n} from \"../internal/generated/types/evaluators.generated\";\nimport { RAGChunk } from \"../internal/generated/types/tracer\";\nimport { tracer } from \"./tracer\";\nimport { EvaluationResultModel } from \"./types\";\nimport { SpanStatusCode } from \"@opentelemetry/api\";\n\nexport interface BasicEvaluationData {\n input?: string;\n output?: string;\n expected_output?: unknown;\n contexts?: RAGChunk[] | string[];\n expected_contexts?: RAGChunk[] | string[];\n conversation?: Conversation;\n}\n\nexport interface EvaluationDetailsBase {\n name?: string;\n data: BasicEvaluationData | Record<string, unknown>;\n contexts?: RAGChunk[] | string[];\n conversation?: Conversation;\n asGuardrail?: boolean;\n}\n\nexport interface SavedEvaluationDetails extends EvaluationDetailsBase {\n slug: string;\n settings?: Record<string, unknown>;\n}\n\nexport interface LangEvalsEvaluationDetails<T extends EvaluatorTypes>\n extends EvaluationDetailsBase {\n evaluator: T;\n settings?: Evaluators[T][\"settings\"];\n}\n\nexport type EvaluationDetails =\n | SavedEvaluationDetails\n | LangEvalsEvaluationDetails<EvaluatorTypes>;\n\nexport async function runEvaluation(\n details: EvaluationDetails,\n): Promise<SingleEvaluationResult> {\n return await tracer.startActiveSpan(\"run evaluation\", async (span) => {\n span.setType(details.asGuardrail ? \"guardrail\" : \"evaluation\");\n\n try {\n const evaluatorId =\n \"slug\" in details ? details.slug : details.evaluator;\n const request = {\n trace_id: span.spanContext().traceId,\n span_id: span.spanContext().spanId,\n data: details.data,\n name: details.name,\n settings: details.settings,\n as_guardrail: details.asGuardrail,\n };\n\n if (canAutomaticallyCaptureInput()) {\n span.setInput(request);\n }\n\n const url = new URL(\n `/api/evaluations/${evaluatorId}/evaluate`,\n getEndpoint(),\n );\n\n const response = await fetch(url.toString(), {\n method: \"POST\",\n headers: {\n \"X-Auth-Token\": getApiKey(),\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(request),\n });\n if (!response.ok) {\n const err = new LangWatchApiError(\"Unable to run evaluation\", response);\n await err.safeParseBody(response);\n\n throw err;\n }\n\n const result: EvaluationResultModel = await response.json();\n\n span.setMetrics({\n cost: result.cost?.amount,\n });\n\n span.setOutputEvaluation(details.asGuardrail ?? false, result);\n\n if (result.status === \"processed\") {\n return {\n status: \"processed\",\n passed: result.passed,\n score: result.score,\n details: result.details,\n label: result.label,\n cost: result.cost,\n } as SingleEvaluationResult;\n } else if (result.status === \"skipped\") {\n return {\n status: \"skipped\",\n details: result.details,\n } as SingleEvaluationResult;\n } else if (result.status === \"error\") {\n return {\n status: \"error\",\n error_type: (result as any).error_type || \"Unknown\",\n details: result.details || \"Unknown error\",\n traceback: (result as any).traceback || [],\n } as SingleEvaluationResult;\n } else {\n return {\n status: \"error\",\n error_type: \"UnknownStatus\",\n details: `Unknown evaluation status: ${result.status}`,\n traceback: [],\n } as SingleEvaluationResult;\n }\n } catch (error) {\n span.recordException(error as Error);\n span.setStatus({ code: SpanStatusCode.ERROR, message: (error as Error)?.message });\n throw error;\n } finally {\n span.end();\n }\n });\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/observability/processors/filterable-batch-span-processor.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _sdktracebase = require('@opentelemetry/sdk-trace-base');
|
|
5
|
+
var FilterableBatchSpanProcessor = class extends _sdktracebase.BatchSpanProcessor {
|
|
6
|
+
/**
|
|
7
|
+
* Create a new FilterableBatchSpanProcessor.
|
|
8
|
+
*
|
|
9
|
+
* @param exporter - The underlying SpanExporter to use for exporting spans.
|
|
10
|
+
* @param filters - An array of rules for excluding spans from export.
|
|
11
|
+
*/
|
|
12
|
+
constructor(exporter, filters) {
|
|
13
|
+
super(exporter);
|
|
14
|
+
this._filters = filters;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Called when a span ends. If the span matches any exclude rule, it is dropped and not exported.
|
|
18
|
+
*
|
|
19
|
+
* @param span - The ReadableSpan that has ended.
|
|
20
|
+
*/
|
|
21
|
+
onEnd(span) {
|
|
22
|
+
for (const filter of this._filters) {
|
|
23
|
+
let sourceValue;
|
|
24
|
+
if (filter.fieldName === "span_name") {
|
|
25
|
+
sourceValue = span.name;
|
|
26
|
+
} else if (filter.fieldName === "instrumentation_scope_name") {
|
|
27
|
+
sourceValue = span.instrumentationScope.name;
|
|
28
|
+
} else {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const matchValue = filter.matchValue;
|
|
32
|
+
const matchOperation = filter.matchOperation;
|
|
33
|
+
switch (true) {
|
|
34
|
+
case (matchOperation === "exact_match" && sourceValue === matchValue):
|
|
35
|
+
case (matchOperation === "includes" && sourceValue.includes(matchValue)):
|
|
36
|
+
case (matchOperation === "starts_with" && sourceValue.startsWith(matchValue)):
|
|
37
|
+
case (matchOperation === "ends_with" && sourceValue.endsWith(matchValue)):
|
|
38
|
+
return;
|
|
39
|
+
default:
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
super.onEnd(span);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
exports.FilterableBatchSpanProcessor = FilterableBatchSpanProcessor;
|
|
50
|
+
//# sourceMappingURL=chunk-KGDAENGD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-KGDAENGD.js","../src/observability/processors/filterable-batch-span-processor.ts"],"names":[],"mappings":"AAAA;ACSA;AACE;AAAA,6DAGK;AAsCA,IAAM,6BAAA,EAAN,MAAA,QAA2C,iCAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASnE,WAAA,CAAY,QAAA,EAAwB,OAAA,EAAsC;AACxE,IAAA,KAAA,CAAM,QAAQ,CAAA;AACd,IAAA,IAAA,CAAK,SAAA,EAAW,OAAA;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOS,KAAA,CAAM,IAAA,EAA0B;AACvC,IAAA,IAAA,CAAA,MAAW,OAAA,GAAU,IAAA,CAAK,QAAA,EAAU;AAClC,MAAA,IAAI,WAAA;AAEJ,MAAA,GAAA,CAAI,MAAA,CAAO,UAAA,IAAc,WAAA,EAAa;AACpC,QAAA,YAAA,EAAc,IAAA,CAAK,IAAA;AAAA,MACrB,EAAA,KAAA,GAAA,CAAW,MAAA,CAAO,UAAA,IAAc,4BAAA,EAA8B;AAC5D,QAAA,YAAA,EAAc,IAAA,CAAK,oBAAA,CAAqB,IAAA;AAAA,MAC1C,EAAA,KAAO;AACL,QAAA,QAAA;AAAA,MACF;AAEA,MAAA,MAAM,WAAA,EAAa,MAAA,CAAO,UAAA;AAC1B,MAAA,MAAM,eAAA,EAAiB,MAAA,CAAO,cAAA;AAE9B,MAAA,OAAA,CAAQ,IAAA,EAAM;AAAA,QACZ,KAAA,CAAK,eAAA,IAAmB,cAAA,GAAiB,YAAA,IAAgB,UAAA,CAAA;AAAA,QACzD,KAAA,CAAK,eAAA,IAAmB,WAAA,GAAc,WAAA,CAAY,QAAA,CAAS,UAAU,CAAA,CAAA;AAAA,QACrE,KAAA,CAAK,eAAA,IAAmB,cAAA,GAAiB,WAAA,CAAY,UAAA,CAAW,UAAU,CAAA,CAAA;AAAA,QAC1E,KAAA,CAAK,eAAA,IAAmB,YAAA,GAAe,WAAA,CAAY,QAAA,CAAS,UAAU,CAAA,CAAA;AACpE,UAAA,MAAA;AAAA,QAEF,OAAA;AAAS,UAAA,KAAA;AAAA,MACX;AAAA,IACF;AAEA,IAAA,KAAA,CAAM,KAAA,CAAM,IAAI,CAAA;AAAA,EAClB;AACF,CAAA;ADrDA;AACA;AACE;AACF,oEAAC","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-KGDAENGD.js","sourcesContent":[null,"/**\n * Filterable Batch Span Exporter for OpenTelemetry\n *\n * This module provides a BatchSpanProcessor subclass that allows filtering of spans before export\n * based on configurable rules. Spans matching any exclude rule are dropped and not exported.\n *\n * @module filterable-batch-span-exporter\n */\n\nimport {\n BatchSpanProcessor,\n ReadableSpan,\n SpanExporter,\n} from '@opentelemetry/sdk-trace-base';\n\n/**\n * A rule for excluding spans from export based on their name or instrumentation scope name.\n *\n * @property fieldName - The span field to match against ('span_name' or 'instrumentation_scope_name').\n * @property matchValue - The value to match against the field.\n * @property matchOperation - The operation to use for matching ('includes', 'exact_match', 'starts_with', 'ends_with').\n *\n * @example\n * const rule: SpanProcessingExcludeRule = {\n * fieldName: 'span_name',\n * matchValue: 'heartbeat',\n * matchOperation: 'exact_match',\n * };\n */\nexport interface SpanProcessingExcludeRule {\n fieldName: \"span_name\" | \"instrumentation_scope_name\";\n matchValue: string;\n matchOperation: \"includes\" | \"exact_match\" | \"starts_with\" | \"ends_with\";\n}\n\n/**\n * A BatchSpanProcessor that filters out spans matching any of the provided exclude rules before export.\n *\n * This is useful for dropping noisy or irrelevant spans (e.g., health checks, heartbeats) from being exported to your tracing backend.\n *\n * @example\n * import { FilterableBatchSpanProcessor } from './filterable-batch-span-exporter';\n * import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';\n *\n * const exporter = new OTLPTraceExporter({ url: '...' });\n * const filters = [\n * { fieldName: 'span_name', matchValue: 'heartbeat', matchOperation: 'exact_match' },\n * { fieldName: 'instrumentation_scope_name', matchValue: 'internal', matchOperation: 'starts_with' },\n * ];\n * provider.addSpanProcessor(new FilterableBatchSpanProcessor(exporter, filters));\n */\nexport class FilterableBatchSpanProcessor extends BatchSpanProcessor {\n private readonly _filters: SpanProcessingExcludeRule[];\n\n /**\n * Create a new FilterableBatchSpanProcessor.\n *\n * @param exporter - The underlying SpanExporter to use for exporting spans.\n * @param filters - An array of rules for excluding spans from export.\n */\n constructor(exporter: SpanExporter, filters: SpanProcessingExcludeRule[]) {\n super(exporter);\n this._filters = filters;\n }\n\n /**\n * Called when a span ends. If the span matches any exclude rule, it is dropped and not exported.\n *\n * @param span - The ReadableSpan that has ended.\n */\n override onEnd(span: ReadableSpan): void {\n for (const filter of this._filters) {\n let sourceValue: string;\n\n if (filter.fieldName === \"span_name\") {\n sourceValue = span.name;\n } else if (filter.fieldName === \"instrumentation_scope_name\") {\n sourceValue = span.instrumentationScope.name;\n } else {\n continue;\n }\n\n const matchValue = filter.matchValue;\n const matchOperation = filter.matchOperation;\n\n switch (true) {\n case matchOperation === \"exact_match\" && sourceValue === matchValue:\n case matchOperation === \"includes\" && sourceValue.includes(matchValue):\n case matchOperation === \"starts_with\" && sourceValue.startsWith(matchValue):\n case matchOperation === \"ends_with\" && sourceValue.endsWith(matchValue):\n return;\n\n default: break;\n }\n }\n\n super.onEnd(span);\n }\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/client-shared.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _api = require('@opentelemetry/api');
|
|
5
|
+
function getActualTracerProvider() {
|
|
6
|
+
var _a;
|
|
7
|
+
const potentiallyProxyTracerProvider = _api.trace.getTracerProvider();
|
|
8
|
+
const delegate = (_a = potentiallyProxyTracerProvider == null ? void 0 : potentiallyProxyTracerProvider.getDelegate) == null ? void 0 : _a.call(potentiallyProxyTracerProvider);
|
|
9
|
+
return delegate != null ? delegate : potentiallyProxyTracerProvider;
|
|
10
|
+
}
|
|
11
|
+
function isOtelInitialized() {
|
|
12
|
+
const provider = getActualTracerProvider();
|
|
13
|
+
return provider && typeof provider.addSpanProcessor === "function";
|
|
14
|
+
}
|
|
15
|
+
function mergeResourceIntoExistingTracerProvider(resource) {
|
|
16
|
+
if (!isOtelInitialized()) {
|
|
17
|
+
throw new Error("OpenTelemetry SDK is not initialized, cannot merge resource into existing tracer provider.");
|
|
18
|
+
}
|
|
19
|
+
const provider = getActualTracerProvider();
|
|
20
|
+
if (!(provider == null ? void 0 : provider.resource)) {
|
|
21
|
+
throw new Error("OpenTelemetry SDK is not initialized, provider does not have a resource.");
|
|
22
|
+
}
|
|
23
|
+
if (typeof resource !== "object") {
|
|
24
|
+
throw new Error("OpenTelemetry SDK is not initialized, provider resource is not an object.");
|
|
25
|
+
}
|
|
26
|
+
if (typeof provider.resource.merge !== "function") {
|
|
27
|
+
throw new Error("OpenTelemetry SDK is not initialized, provider resource does not have a merge method.");
|
|
28
|
+
}
|
|
29
|
+
provider.resource = provider.resource.merge(resource);
|
|
30
|
+
}
|
|
31
|
+
function addSpanProcessorToExistingTracerProvider(spanProcessor) {
|
|
32
|
+
if (!isOtelInitialized()) {
|
|
33
|
+
throw new Error("OpenTelemetry SDK is not initialized, cannot add span processor to existing tracer provider.");
|
|
34
|
+
}
|
|
35
|
+
const provider = getActualTracerProvider();
|
|
36
|
+
if (!(provider == null ? void 0 : provider.addSpanProcessor)) {
|
|
37
|
+
throw new Error("OpenTelemetry SDK is not initialized, provider does not have a addSpanProcessor method.");
|
|
38
|
+
}
|
|
39
|
+
provider.addSpanProcessor(spanProcessor);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
exports.isOtelInitialized = isOtelInitialized; exports.mergeResourceIntoExistingTracerProvider = mergeResourceIntoExistingTracerProvider; exports.addSpanProcessorToExistingTracerProvider = addSpanProcessorToExistingTracerProvider;
|
|
47
|
+
//# sourceMappingURL=chunk-LD74LVRU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-LD74LVRU.js","../src/client-shared.ts"],"names":[],"mappings":"AAAA;ACAA;AACE;AAAA,yCAEK;AASP,SAAS,uBAAA,CAAA,EAA+B;AAZxC,EAAA,IAAA,EAAA;AAaE,EAAA,MAAM,+BAAA,EAAiC,UAAA,CAAM,iBAAA,CAAkB,CAAA;AAG/D,EAAA,MAAM,SAAA,EAAA,CAAY,GAAA,EAAA,+BAAA,GAAA,KAAA,EAAA,KAAA,EAAA,EAAA,8BAAA,CAAoE,WAAA,EAAA,GAApE,KAAA,EAAA,KAAA,EAAA,EAAA,EAAA,CAAA,IAAA,CAAA,8BAAA,CAAA;AAGlB,EAAA,OAAO,SAAA,GAAA,KAAA,EAAA,SAAA,EAAa,8BAAA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A,MAAM,IAAI,KAAA,CAAM,yFAAyF,CAAA;AAAA,EAC3G;AAEA,EAAA,QAAA,CAAS,gBAAA,CAAiB,aAAa,CAAA;AACzC;AD/BA;AACA;AACE;AACA;AACA;AACF,sOAAC","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-LD74LVRU.js","sourcesContent":[null,"import {\n trace,\n ProxyTracerProvider,\n} from \"@opentelemetry/api\";\nimport { Resource } from \"@opentelemetry/resources\";\nimport { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\n\n/**\n * Gets the actual tracer provider, handling the proxy delegate pattern.\n *\n * @returns The actual tracer provider or undefined if not available\n */\nfunction getActualTracerProvider(): any {\n const potentiallyProxyTracerProvider = trace.getTracerProvider() as unknown;\n\n // Attempt to get the delegate if it's a ProxyTracerProvider\n const delegate = (potentiallyProxyTracerProvider as ProxyTracerProvider | undefined)?.getDelegate?.();\n\n // Return the delegate if available, otherwise return the original provider\n return delegate ?? (potentiallyProxyTracerProvider as any);\n}\n\n/**\n * Checks if the OpenTelemetry SDK has been initialized anywhere in the process.\n *\n * @returns true if the OpenTelemetry SDK has been initialized, false otherwise.\n */\nexport function isOtelInitialized() {\n const provider = getActualTracerProvider();\n\n // Check if the provider has the addSpanProcessor method, which indicates SDK initialization\n return provider && typeof provider.addSpanProcessor === \"function\";\n}\n\n/**\n * Merges a resource into the existing tracer provider.\n *\n * @param resource - The resource to merge into the existing tracer provider.\n */\nexport function mergeResourceIntoExistingTracerProvider(resource: Resource) {\n if (!isOtelInitialized()) {\n throw new Error(\"OpenTelemetry SDK is not initialized, cannot merge resource into existing tracer provider.\");\n }\n\n const provider = getActualTracerProvider();\n\n if (!provider?.resource) {\n throw new Error(\"OpenTelemetry SDK is not initialized, provider does not have a resource.\");\n }\n if (typeof resource !== \"object\") {\n throw new Error(\"OpenTelemetry SDK is not initialized, provider resource is not an object.\");\n }\n if (typeof provider.resource.merge !== \"function\") {\n throw new Error(\"OpenTelemetry SDK is not initialized, provider resource does not have a merge method.\");\n }\n\n provider.resource = provider.resource.merge(resource);\n}\n\nexport function addSpanProcessorToExistingTracerProvider(spanProcessor: SpanProcessor) {\n if (!isOtelInitialized()) {\n throw new Error(\"OpenTelemetry SDK is not initialized, cannot add span processor to existing tracer provider.\");\n }\n\n const provider = getActualTracerProvider();\n\n if (!provider?.addSpanProcessor) {\n throw new Error(\"OpenTelemetry SDK is not initialized, provider does not have a addSpanProcessor method.\");\n }\n\n provider.addSpanProcessor(spanProcessor);\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/client.ts
|
|
2
|
+
var _a, _b;
|
|
3
|
+
var config = {
|
|
4
|
+
apiKey: (_a = process.env.LANGWATCH_API_KEY) != null ? _a : "",
|
|
5
|
+
endpoint: (_b = process.env.LANGWATCH_ENDPOINT) != null ? _b : "https://app.langwatch.ai",
|
|
6
|
+
setupCalled: false,
|
|
7
|
+
skipOpenTelemetrySetup: false,
|
|
8
|
+
disableAutomaticInputCapture: false,
|
|
9
|
+
disableAutomaticOutputCapture: false,
|
|
10
|
+
baseAttributes: {}
|
|
11
|
+
};
|
|
12
|
+
function setConfig(options) {
|
|
13
|
+
var _a2, _b2, _c, _d, _e, _f;
|
|
14
|
+
config.setupCalled = true;
|
|
15
|
+
config.apiKey = options.apiKey !== void 0 ? options.apiKey : (_a2 = process.env.LANGWATCH_API_KEY) != null ? _a2 : config.apiKey;
|
|
16
|
+
config.endpoint = options.endpoint !== void 0 ? options.endpoint : (_b2 = process.env.LANGWATCH_ENDPOINT) != null ? _b2 : config.endpoint;
|
|
17
|
+
if (config.apiKey === "") {
|
|
18
|
+
console.warn("[langwatch setup] No API key provided. Please set the LANGWATCH_API_KEY environment variable or pass it to the setup function. The SDK will perform no operations.");
|
|
19
|
+
}
|
|
20
|
+
config.skipOpenTelemetrySetup = (_c = options.skipOpenTelemetrySetup) != null ? _c : config.skipOpenTelemetrySetup;
|
|
21
|
+
config.disableAutomaticInputCapture = (_d = options.disableAutomaticInputCapture) != null ? _d : config.disableAutomaticInputCapture;
|
|
22
|
+
config.disableAutomaticOutputCapture = (_e = options.disableAutomaticOutputCapture) != null ? _e : config.disableAutomaticOutputCapture;
|
|
23
|
+
config.baseAttributes = (_f = options.baseAttributes) != null ? _f : config.baseAttributes;
|
|
24
|
+
}
|
|
25
|
+
function getApiKey() {
|
|
26
|
+
return config.apiKey;
|
|
27
|
+
}
|
|
28
|
+
function getEndpoint() {
|
|
29
|
+
return config.endpoint;
|
|
30
|
+
}
|
|
31
|
+
function canAutomaticallyCaptureInput() {
|
|
32
|
+
return !config.disableAutomaticInputCapture;
|
|
33
|
+
}
|
|
34
|
+
function canAutomaticallyCaptureOutput() {
|
|
35
|
+
return !config.disableAutomaticOutputCapture;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
exports.setConfig = setConfig; exports.getApiKey = getApiKey; exports.getEndpoint = getEndpoint; exports.canAutomaticallyCaptureInput = canAutomaticallyCaptureInput; exports.canAutomaticallyCaptureOutput = canAutomaticallyCaptureOutput;
|
|
45
|
+
//# sourceMappingURL=chunk-PCQVQ7SB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-PCQVQ7SB.js","../src/client.ts"],"names":["_a","_b"],"mappings":"AAAA;ACAA,IAAA,EAAA,EAAA,EAAA;AAoEA,IAAM,OAAA,EAAyB;AAAA,EAC7B,MAAA,EAAA,CAAQ,GAAA,EAAA,OAAA,CAAQ,GAAA,CAAI,iBAAA,EAAA,GAAZ,KAAA,EAAA,GAAA,EAAiC,EAAA;AAAA,EACzC,QAAA,EAAA,CAAU,GAAA,EAAA,OAAA,CAAQ,GAAA,CAAI,kBAAA,EAAA,GAAZ,KAAA,EAAA,GAAA,EAAkC,0BAAA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A,CAAQ,6BAAA,EAAA,GAAR,KAAA,EAAA,GAAA,EAAyC,MAAA,CAAO,6BAAA;AAEvF,EAAA,MAAA,CAAO,eAAA,EAAA,CAAiB,GAAA,EAAA,OAAA,CAAQ,cAAA,EAAA,GAAR,KAAA,EAAA,GAAA,EAA0B,MAAA,CAAO,cAAA;AAC3D;AAEO,SAAS,SAAA,CAAA,EAAoB;AAClC,EAAA,OAAO,MAAA,CAAO,MAAA;AAChB;AAEO,SAAS,WAAA,CAAA,EAAsB;AACpC,EAAA,OAAO,MAAA,CAAO,QAAA;AAChB;AAEO,SAAS,4BAAA,CAAA,EAAwC;AACtD,EAAA,OAAO,CAAC,MAAA,CAAO,4BAAA;AACjB;AAEO,SAAS,6BAAA,CAAA,EAAyC;AACvD,EAAA,OAAO,CAAC,MAAA,CAAO,6BAAA;AACjB;AD9EA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,4OAAC","file":"/home/runner/work/langwatch/langwatch/typescript-sdk/dist/chunk-PCQVQ7SB.js","sourcesContent":[null,"import { SpanProcessor } from \"@opentelemetry/sdk-trace-base\";\nimport { SpanProcessingExcludeRule } from \"./observability\";\nimport { Attributes } from \"@opentelemetry/api\";\n\nexport interface SetupOptions {\n /**\n * The API key to use for the LangWatch API.\n */\n apiKey?: string;\n\n /**\n * The endpoint to use for the LangWatch API.\n */\n endpoint?: string;\n\n /**\n * The span processors to use for the OpenTelemetry SDK.\n *\n * If provided, these will be added to the OpenTelemetry SDK after the LangWatch SDK has\n * been initialized.\n */\n otelSpanProcessors?: SpanProcessor[];\n\n /**\n * The span processing exclude rules to use for the OpenTelemetry SDK.\n *\n * If provided, these will be added to the OpenTelemetry SDK after the LangWatch SDK has\n * been initialized.\n *\n * If you are using the `otelSpanProcessors` option, then these will be ignored.\n */\n otelSpanProcessingExcludeRules?: SpanProcessingExcludeRule[];\n\n /**\n * Whether to skip the automatic setup of the OpenTelemetry SDK. If this is set, then\n * the LangWatch SDK will not attempt to setup the OpenTelemetry SDK. You will need to\n * setup the OpenTelemetry yourself, and ensure that a SpanProcessor is added to the\n * OpenTelemetry SDK that will send traces to the LangWatch API.\n */\n skipOpenTelemetrySetup?: boolean;\n\n /**\n * Whether to disable the automatic capture of input.\n */\n disableAutomaticInputCapture?: boolean;\n\n /**\n * Whether to disable the automatic capture of output.\n */\n disableAutomaticOutputCapture?: boolean;\n\n /**\n * The base attributes to use for the OpenTelemetry SDK.\n */\n baseAttributes?: Attributes;\n}\n\ninterface InternalConfig {\n apiKey: string;\n endpoint: string;\n setupCalled: boolean;\n skipOpenTelemetrySetup: boolean;\n disableAutomaticInputCapture: boolean;\n disableAutomaticOutputCapture: boolean;\n\n baseAttributes: Attributes;\n}\n\nconst config: InternalConfig = {\n apiKey: process.env.LANGWATCH_API_KEY ?? \"\",\n endpoint: process.env.LANGWATCH_ENDPOINT ?? \"https://app.langwatch.ai\",\n setupCalled: false,\n skipOpenTelemetrySetup: false,\n disableAutomaticInputCapture: false,\n disableAutomaticOutputCapture: false,\n baseAttributes: {},\n};\n\nexport function setConfig(options: SetupOptions) {\n config.setupCalled = true;\n\n config.apiKey = options.apiKey !== void 0\n ? options.apiKey\n : (process.env.LANGWATCH_API_KEY ?? config.apiKey);\n\n config.endpoint = options.endpoint !== void 0\n ? options.endpoint\n : (process.env.LANGWATCH_ENDPOINT ?? config.endpoint);\n\n if (config.apiKey === \"\") {\n console.warn(\"[langwatch setup] No API key provided. Please set the LANGWATCH_API_KEY environment variable or pass it to the setup function. The SDK will perform no operations.\");\n }\n\n config.skipOpenTelemetrySetup = options.skipOpenTelemetrySetup ?? config.skipOpenTelemetrySetup;\n config.disableAutomaticInputCapture = options.disableAutomaticInputCapture ?? config.disableAutomaticInputCapture;\n config.disableAutomaticOutputCapture = options.disableAutomaticOutputCapture ?? config.disableAutomaticOutputCapture;\n\n config.baseAttributes = options.baseAttributes ?? config.baseAttributes;\n}\n\nexport function getApiKey(): string {\n return config.apiKey;\n}\n\nexport function getEndpoint(): string {\n return config.endpoint;\n}\n\nexport function canAutomaticallyCaptureInput(): boolean {\n return !config.disableAutomaticInputCapture;\n}\n\nexport function canAutomaticallyCaptureOutput(): boolean {\n return !config.disableAutomaticOutputCapture;\n}\n\nexport function isSetupCalled(): boolean {\n return config.setupCalled;\n}\n"]}
|