@cetra-ai/sdk 0.0.0-stage → 0.0.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.
@@ -0,0 +1,52 @@
1
+ import { TracerProvider } from "@opentelemetry/api";
2
+ import { ReadableSpan, SpanProcessor } from "@opentelemetry/sdk-trace";
3
+ declare class ConfigError extends Error {
4
+ readonly option: string;
5
+ constructor(option: string, problem: string);
6
+ }
7
+ interface CetraOptions {
8
+ apiKey?: string;
9
+ baseUrl?: string;
10
+ environment?: string;
11
+ release?: string;
12
+ captureContent?: boolean;
13
+ sampleRate?: number;
14
+ mask?: (value: unknown) => unknown;
15
+ useGlobalProvider?: boolean;
16
+ exportFilter?: (span: ReadableSpan) => boolean;
17
+ instrument?: readonly Instrumentation[];
18
+ enabled?: boolean;
19
+ }
20
+ type ScoreDataType = "numeric" | "boolean" | "categorical" | "text";
21
+ interface ScoreOptions {
22
+ name: string;
23
+ value: boolean | number | string;
24
+ traceId?: string;
25
+ spanId?: string;
26
+ sessionId?: string;
27
+ reason?: string;
28
+ dataType?: ScoreDataType;
29
+ metadata?: Readonly<Record<string, unknown>>;
30
+ userId?: string;
31
+ scoreId?: string;
32
+ }
33
+ /**
34
+ * Queue one score and return its id, or `undefined` when nothing was queued:
35
+ * before `init()`, after `shutdown()`, without `crypto`, on invalid input
36
+ * (one warning), or when the buffer is full (one warning per minute).
37
+ */
38
+ declare function score(options: ScoreOptions): string | undefined;
39
+ declare function init(options?: CetraOptions): void;
40
+ declare function flush(): Promise<void>;
41
+ declare function shutdown(): Promise<void>;
42
+ /** The provider in use; a no-op proxy when not running (spec 10 rule 1). */
43
+ declare function tracerProvider(): TracerProvider;
44
+ /** Our span processor, for apps that build their own OTel pipeline. */
45
+ declare function spanProcessor(): SpanProcessor | undefined;
46
+ /** What `init({ instrument: [...] })` accepts; OTel instrumentations satisfy it. */
47
+ interface Instrumentation {
48
+ setTracerProvider(provider: TracerProvider): void;
49
+ enable(): void;
50
+ disable(): void;
51
+ }
52
+ export { spanProcessor as a, ScoreOptions as c, ConfigError as d, shutdown as i, score as l, flush as n, tracerProvider as o, init as r, ScoreDataType as s, Instrumentation as t, CetraOptions as u };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The LangChain helper (D-F-7): builds the OpenInference instrumentation for
3
+ * LangChain and patches the callbacks module by hand, so ESM works without
4
+ * loader flags. Pass the result to `init({ instrument: [...] })`; the patch is
5
+ * active immediately, but spans reach cetra only once `init` has bound our
6
+ * tracer provider.
7
+ *
8
+ * `captureContent` defaults to `true` and is not re-read by `init`: pass the
9
+ * same value as `init`'s `captureContent` option.
10
+ */
11
+ import { t as Instrumentation } from "./instrument-YhFFywwZ.js";
12
+ import * as CallbackManagerModule from "@langchain/core/callbacks/manager";
13
+ export declare function langchain(module: typeof CallbackManagerModule, options?: {
14
+ captureContent?: boolean;
15
+ }): Instrumentation;
@@ -0,0 +1,25 @@
1
+ import { LangChainInstrumentation } from "@arizeai/openinference-instrumentation-langchain";
2
+ // src/langchain.ts
3
+ /**
4
+ * The LangChain helper (D-F-7): builds the OpenInference instrumentation for
5
+ * LangChain and patches the callbacks module by hand, so ESM works without
6
+ * loader flags. Pass the result to `init({ instrument: [...] })`; the patch is
7
+ * active immediately, but spans reach cetra only once `init` has bound our
8
+ * tracer provider.
9
+ *
10
+ * `captureContent` defaults to `true` and is not re-read by `init`: pass the
11
+ * same value as `init`'s `captureContent` option.
12
+ */
13
+ function langchain(module, options) {
14
+ const capture = options?.captureContent ?? true;
15
+ const instrumentation = new LangChainInstrumentation({
16
+ instrumentationConfig: { enabled: false },
17
+ traceConfig: {
18
+ hideInputs: !capture,
19
+ hideOutputs: !capture
20
+ }
21
+ });
22
+ instrumentation.manuallyInstrument(module);
23
+ return instrumentation;
24
+ }
25
+ export { langchain };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The OpenAI helper (D-F-7): builds the OpenInference instrumentation for the
3
+ * OpenAI SDK and patches the module by hand, so ESM works without loader
4
+ * flags. Pass the result to `init({ instrument: [...] })`; the patch is active
5
+ * immediately, but spans reach cetra only once `init` has bound our tracer
6
+ * provider.
7
+ *
8
+ * `captureContent` defaults to `true` and is not re-read by `init`: pass the
9
+ * same value as `init`'s `captureContent` option.
10
+ */
11
+ import { t as Instrumentation } from "./instrument-YhFFywwZ.js";
12
+ import OpenAI from "openai";
13
+ export declare function openai(module: typeof OpenAI, options?: {
14
+ captureContent?: boolean;
15
+ }): Instrumentation;
package/dist/openai.js ADDED
@@ -0,0 +1,25 @@
1
+ import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
2
+ // src/openai.ts
3
+ /**
4
+ * The OpenAI helper (D-F-7): builds the OpenInference instrumentation for the
5
+ * OpenAI SDK and patches the module by hand, so ESM works without loader
6
+ * flags. Pass the result to `init({ instrument: [...] })`; the patch is active
7
+ * immediately, but spans reach cetra only once `init` has bound our tracer
8
+ * provider.
9
+ *
10
+ * `captureContent` defaults to `true` and is not re-read by `init`: pass the
11
+ * same value as `init`'s `captureContent` option.
12
+ */
13
+ function openai(module, options) {
14
+ const capture = options?.captureContent ?? true;
15
+ const instrumentation = new OpenAIInstrumentation({
16
+ instrumentationConfig: { enabled: false },
17
+ traceConfig: {
18
+ hideInputs: !capture,
19
+ hideOutputs: !capture
20
+ }
21
+ });
22
+ instrumentation.manuallyInstrument(module);
23
+ return instrumentation;
24
+ }
25
+ export { openai };
@@ -0,0 +1,44 @@
1
+ // src/web.ts
2
+ function runtimeGlobals() {
3
+ return globalThis;
4
+ }
5
+ /** `fetch` bound to globalThis, when the runtime has one. */
6
+ function getFetch() {
7
+ return runtimeGlobals().fetch?.bind(globalThis);
8
+ }
9
+ /** Gzip `bytes`; `undefined` when CompressionStream/Response/Blob are missing. */
10
+ async function gzip(bytes) {
11
+ const { Blob, CompressionStream, Response } = runtimeGlobals();
12
+ if (Blob === void 0 || CompressionStream === void 0 || Response === void 0) return;
13
+ const buffer = await new Response(new Blob([bytes]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer();
14
+ return new Uint8Array(buffer);
15
+ }
16
+ /** `AbortSignal.timeout(ms)` or undefined. */
17
+ function timeoutSignal(ms) {
18
+ return runtimeGlobals().AbortSignal?.timeout?.(ms);
19
+ }
20
+ /** UTF-8 encode through the runtime's TextEncoder. */
21
+ function utf8Encode(text) {
22
+ const { TextEncoder } = runtimeGlobals();
23
+ if (TextEncoder === void 0) throw new Error("TextEncoder is not available");
24
+ return new TextEncoder().encode(text);
25
+ }
26
+ /** UTF-8 decode through the runtime's TextDecoder. */
27
+ function utf8Decode(bytes) {
28
+ const { TextDecoder } = runtimeGlobals();
29
+ if (TextDecoder === void 0) throw new Error("TextDecoder is not available");
30
+ return new TextDecoder().decode(bytes);
31
+ }
32
+ const BRACKET_HOST = /^\[[0-9A-Fa-f:.]+\](?::[0-9]*)?$/;
33
+ /** `http(s)://` plus a host. No DOM `URL` in this build. */
34
+ function hasHttpAuthority(value) {
35
+ const authority = /^(https?):\/\/([^/?#]+)/i.exec(value)?.[2];
36
+ if (authority === void 0 || authority === "") return false;
37
+ const at = authority.lastIndexOf("@");
38
+ const host = at === -1 ? authority : authority.slice(at + 1);
39
+ if (host.startsWith("[")) return BRACKET_HOST.test(host);
40
+ if (host.includes("[") || host.includes("]")) return false;
41
+ const name = host.split(":", 1)[0];
42
+ return name !== void 0 && name !== "";
43
+ }
44
+ export { timeoutSignal as a, runtimeGlobals as i, gzip as n, utf8Decode as o, hasHttpAuthority as r, utf8Encode as s, getFetch as t };
package/package.json CHANGED
@@ -1,6 +1,111 @@
1
1
  {
2
2
  "name": "@cetra-ai/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.0",
4
+ "description": "TypeScript SDK for cetra.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "llm",
8
+ "observability",
9
+ "opentelemetry",
10
+ "tracing",
11
+ "evaluation"
12
+ ],
13
+ "homepage": "https://cetra.sh/docs/reference/typescript/",
14
+ "bugs": "https://github.com/cetra-ai/cetra/issues",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/cetra-ai/cetra.git",
18
+ "directory": "sdks/typescript"
19
+ },
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "engines": {
23
+ "node": ">=22.12"
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ },
30
+ "./anthropic": {
31
+ "types": "./dist/anthropic.d.ts",
32
+ "default": "./dist/anthropic.js"
33
+ },
34
+ "./browser": {
35
+ "types": "./dist/browser.d.ts",
36
+ "default": "./dist/browser.js"
37
+ },
38
+ "./langchain": {
39
+ "types": "./dist/langchain.d.ts",
40
+ "default": "./dist/langchain.js"
41
+ },
42
+ "./openai": {
43
+ "types": "./dist/openai.d.ts",
44
+ "default": "./dist/openai.js"
45
+ }
46
+ },
47
+ "files": [
48
+ "dist"
49
+ ],
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "scripts": {
54
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
55
+ "test": "vitest run",
56
+ "build": "tsdown",
57
+ "check:package": "publint && attw --pack . --profile esm-only",
58
+ "check": "biome check . && pnpm typecheck && pnpm test && pnpm build && pnpm check:package"
59
+ },
60
+ "devDependencies": {
61
+ "@anthropic-ai/sdk": "1.6.0",
62
+ "@arethetypeswrong/cli": "0.18.5",
63
+ "@arizeai/openinference-instrumentation-anthropic": "1.0.1",
64
+ "@arizeai/openinference-instrumentation-langchain": "4.1.5",
65
+ "@arizeai/openinference-instrumentation-openai": "4.4.3",
66
+ "@langchain/core": "1.3.5",
67
+ "@opentelemetry/api": "1.9.1",
68
+ "@types/node": "26.6.6",
69
+ "openai": "7.53.0",
70
+ "publint": "0.3.25",
71
+ "tsdown": "0.23.7",
72
+ "typescript": "5.9.3",
73
+ "vitest": "5.1.0"
74
+ },
75
+ "dependencies": {
76
+ "@opentelemetry/context-async-hooks": "2.12.0",
77
+ "@opentelemetry/core": "2.12.0",
78
+ "@opentelemetry/otlp-transformer": "0.223.0",
79
+ "@opentelemetry/resources": "2.12.0",
80
+ "@opentelemetry/sdk-trace": "2.12.0"
81
+ },
82
+ "peerDependencies": {
83
+ "@anthropic-ai/sdk": "^1.0.0",
84
+ "@arizeai/openinference-instrumentation-anthropic": "^1.0.0",
85
+ "@arizeai/openinference-instrumentation-langchain": "^4.1.5",
86
+ "@arizeai/openinference-instrumentation-openai": "^4.4.3",
87
+ "@langchain/core": "^1.0.0",
88
+ "@opentelemetry/api": ">=1.9.0 <1.10.0",
89
+ "openai": "^7.0.0"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "@anthropic-ai/sdk": {
93
+ "optional": true
94
+ },
95
+ "@arizeai/openinference-instrumentation-anthropic": {
96
+ "optional": true
97
+ },
98
+ "@arizeai/openinference-instrumentation-langchain": {
99
+ "optional": true
100
+ },
101
+ "@arizeai/openinference-instrumentation-openai": {
102
+ "optional": true
103
+ },
104
+ "@langchain/core": {
105
+ "optional": true
106
+ },
107
+ "openai": {
108
+ "optional": true
109
+ }
110
+ }
111
+ }