@llmops/sdk 0.5.3 → 0.6.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/dist/agents-exporter-BorGCb93.mjs +207 -0
- package/dist/agents-exporter-Ct3l12qS.cjs +213 -0
- package/dist/agents-exporter-DIoxRgjd.d.mts +155 -0
- package/dist/agents-exporter-DvECkYQd.d.cts +155 -0
- package/dist/agents.cjs +3 -0
- package/dist/agents.d.cts +2 -0
- package/dist/agents.d.mts +2 -0
- package/dist/agents.mjs +3 -0
- package/dist/express.d.cts +3 -2
- package/dist/express.d.mts +3 -2
- package/dist/express.mjs +1 -1
- package/dist/hono.d.cts +2 -1
- package/dist/hono.d.mts +2 -1
- package/dist/index-CelQx4B3.d.mts +26 -0
- package/dist/{index-bdFT7Yxj.d.mts → index-CmC2x4dU.d.mts} +1 -1
- package/dist/index-D49MVTAo.d.cts +26 -0
- package/dist/{index-CHeoSGK0.d.cts → index-DVTO0Hbl.d.cts} +1 -1
- package/dist/index.cjs +151 -8
- package/dist/index.d.cts +93 -3
- package/dist/index.d.mts +93 -3
- package/dist/index.mjs +151 -10
- package/dist/nextjs.d.cts +2 -1
- package/dist/nextjs.d.mts +2 -1
- package/package.json +13 -3
- package/dist/index-BkLZoEW_.d.mts +0 -16
- package/dist/index-De3QdpKX.d.cts +0 -16
- /package/dist/{express-Dz3xwxkh.mjs → express-ClEIbLM9.mjs} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { t as createLLMOpsMiddleware } from "./express-
|
|
2
|
-
import "
|
|
1
|
+
import { t as createLLMOpsMiddleware } from "./express-ClEIbLM9.mjs";
|
|
2
|
+
import { t as createLLMOpsAgentsExporter } from "./agents-exporter-BorGCb93.mjs";
|
|
3
|
+
import { LLMOPS_SPAN_NAME_HEADER, LLMOPS_TRACE_ID_HEADER, LLMOPS_TRACE_NAME_HEADER } from "@llmops/core";
|
|
3
4
|
import { createApp } from "@llmops/app";
|
|
4
5
|
|
|
5
6
|
//#region src/lib/auth/client.ts
|
|
@@ -19,22 +20,162 @@ const createLLMOps = (config) => {
|
|
|
19
20
|
const { app, config: validatedConfig } = createApp(config);
|
|
20
21
|
const handler = async (req) => app.fetch(req, void 0, void 0);
|
|
21
22
|
const basePath = validatedConfig.basePath;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const createInternalFetch = (getTraceContext) => {
|
|
24
|
+
return (input, init) => {
|
|
25
|
+
const request = new Request(input, init);
|
|
26
|
+
const url = new URL(request.url);
|
|
27
|
+
if (basePath && basePath !== "/" && url.pathname.startsWith(basePath)) url.pathname = url.pathname.slice(basePath.length) || "/";
|
|
28
|
+
if (getTraceContext) {
|
|
29
|
+
const ctx = getTraceContext();
|
|
30
|
+
if (ctx) {
|
|
31
|
+
const headers = new Headers(request.headers);
|
|
32
|
+
if (ctx.traceId) headers.set(LLMOPS_TRACE_ID_HEADER, ctx.traceId);
|
|
33
|
+
if (ctx.traceName) headers.set(LLMOPS_TRACE_NAME_HEADER, ctx.traceName);
|
|
34
|
+
if (ctx.spanName) headers.set(LLMOPS_SPAN_NAME_HEADER, ctx.spanName);
|
|
35
|
+
return handler(new Request(url.toString(), {
|
|
36
|
+
method: request.method,
|
|
37
|
+
headers,
|
|
38
|
+
body: request.body,
|
|
39
|
+
duplex: "half"
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return handler(new Request(url.toString(), request));
|
|
44
|
+
};
|
|
27
45
|
};
|
|
28
46
|
return {
|
|
29
47
|
handler,
|
|
30
48
|
config: Object.freeze(validatedConfig),
|
|
31
|
-
provider: () => ({
|
|
49
|
+
provider: (options) => ({
|
|
32
50
|
baseURL: `http://localhost${basePath}/api/genai/v1`,
|
|
33
51
|
apiKey: "llmops",
|
|
34
|
-
fetch:
|
|
52
|
+
fetch: createInternalFetch(options?.traceContext)
|
|
53
|
+
}),
|
|
54
|
+
agentsExporter: () => createLLMOpsAgentsExporter({
|
|
55
|
+
baseURL: `http://localhost${basePath}`,
|
|
56
|
+
apiKey: "llmops",
|
|
57
|
+
fetch: createInternalFetch()
|
|
35
58
|
})
|
|
36
59
|
};
|
|
37
60
|
};
|
|
38
61
|
|
|
39
62
|
//#endregion
|
|
40
|
-
|
|
63
|
+
//#region src/telemetry/exporter.ts
|
|
64
|
+
let ExportResultCode = /* @__PURE__ */ function(ExportResultCode$1) {
|
|
65
|
+
ExportResultCode$1[ExportResultCode$1["SUCCESS"] = 0] = "SUCCESS";
|
|
66
|
+
ExportResultCode$1[ExportResultCode$1["FAILED"] = 1] = "FAILED";
|
|
67
|
+
return ExportResultCode$1;
|
|
68
|
+
}({});
|
|
69
|
+
/**
|
|
70
|
+
* Convert a value to OTLP attribute value format
|
|
71
|
+
*/
|
|
72
|
+
function toOtlpValue(value) {
|
|
73
|
+
if (typeof value === "string") return { stringValue: value };
|
|
74
|
+
if (typeof value === "number") return Number.isInteger(value) ? { intValue: String(value) } : { doubleValue: value };
|
|
75
|
+
if (typeof value === "boolean") return { boolValue: value };
|
|
76
|
+
if (Array.isArray(value)) return { arrayValue: { values: value.map((v) => toOtlpValue(v)) } };
|
|
77
|
+
if (typeof value === "object" && value !== null) try {
|
|
78
|
+
return { stringValue: JSON.stringify(value) };
|
|
79
|
+
} catch {
|
|
80
|
+
return { stringValue: String(value) };
|
|
81
|
+
}
|
|
82
|
+
return { stringValue: String(value) };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Convert HrTime [seconds, nanoseconds] to nanosecond string
|
|
86
|
+
*/
|
|
87
|
+
function hrTimeToNano(hrTime) {
|
|
88
|
+
return (BigInt(hrTime[0]) * BigInt(1e9) + BigInt(hrTime[1])).toString();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create an OTel SpanExporter that sends spans to an LLMOps server.
|
|
92
|
+
*/
|
|
93
|
+
function createLLMOpsSpanExporter(config) {
|
|
94
|
+
const url = `${config.baseURL.replace(/\/$/, "")}/api/otlp/v1/traces`;
|
|
95
|
+
return {
|
|
96
|
+
export(spans, resultCallback) {
|
|
97
|
+
const resourceMap = /* @__PURE__ */ new Map();
|
|
98
|
+
for (const span of spans) {
|
|
99
|
+
const resourceKey = JSON.stringify(span.resource.attributes);
|
|
100
|
+
const group = resourceMap.get(resourceKey) ?? [];
|
|
101
|
+
group.push(span);
|
|
102
|
+
resourceMap.set(resourceKey, group);
|
|
103
|
+
}
|
|
104
|
+
const body = { resourceSpans: Array.from(resourceMap.entries()).map(([resourceKey, group]) => {
|
|
105
|
+
const resourceAttrs = JSON.parse(resourceKey);
|
|
106
|
+
const scopeMap = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const span of group) {
|
|
108
|
+
const scopeKey = `${span.instrumentationLibrary.name}:${span.instrumentationLibrary.version ?? ""}`;
|
|
109
|
+
const scopeGroup = scopeMap.get(scopeKey) ?? [];
|
|
110
|
+
scopeGroup.push(span);
|
|
111
|
+
scopeMap.set(scopeKey, scopeGroup);
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
resource: { attributes: Object.entries(resourceAttrs).filter(([, v]) => v !== void 0 && v !== null).map(([key, value]) => ({
|
|
115
|
+
key,
|
|
116
|
+
value: toOtlpValue(value)
|
|
117
|
+
})) },
|
|
118
|
+
scopeSpans: Array.from(scopeMap.entries()).map(([, scopeGroup]) => ({
|
|
119
|
+
scope: {
|
|
120
|
+
name: scopeGroup[0].instrumentationLibrary.name,
|
|
121
|
+
version: scopeGroup[0].instrumentationLibrary.version ?? void 0
|
|
122
|
+
},
|
|
123
|
+
spans: scopeGroup.map((span) => {
|
|
124
|
+
const ctx = span.spanContext();
|
|
125
|
+
return {
|
|
126
|
+
traceId: ctx.traceId,
|
|
127
|
+
spanId: ctx.spanId,
|
|
128
|
+
parentSpanId: span.parentSpanId || void 0,
|
|
129
|
+
name: span.name,
|
|
130
|
+
kind: span.kind,
|
|
131
|
+
startTimeUnixNano: hrTimeToNano(span.startTime),
|
|
132
|
+
endTimeUnixNano: hrTimeToNano(span.endTime),
|
|
133
|
+
attributes: Object.entries(span.attributes).filter(([, v]) => v !== void 0 && v !== null).map(([key, value]) => ({
|
|
134
|
+
key,
|
|
135
|
+
value: toOtlpValue(value)
|
|
136
|
+
})),
|
|
137
|
+
events: span.events.map((event) => ({
|
|
138
|
+
name: event.name,
|
|
139
|
+
timeUnixNano: hrTimeToNano(event.time),
|
|
140
|
+
attributes: event.attributes ? Object.entries(event.attributes).filter(([, v]) => v !== void 0 && v !== null).map(([key, value]) => ({
|
|
141
|
+
key,
|
|
142
|
+
value: toOtlpValue(value)
|
|
143
|
+
})) : []
|
|
144
|
+
})),
|
|
145
|
+
status: {
|
|
146
|
+
code: span.status.code,
|
|
147
|
+
message: span.status.message ?? void 0
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
})
|
|
151
|
+
}))
|
|
152
|
+
};
|
|
153
|
+
}) };
|
|
154
|
+
fetch(url, {
|
|
155
|
+
method: "POST",
|
|
156
|
+
headers: {
|
|
157
|
+
"Content-Type": "application/json",
|
|
158
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
159
|
+
...config.headers ?? {}
|
|
160
|
+
},
|
|
161
|
+
body: JSON.stringify(body)
|
|
162
|
+
}).then((res) => {
|
|
163
|
+
if (res.ok) resultCallback({ code: ExportResultCode.SUCCESS });
|
|
164
|
+
else resultCallback({
|
|
165
|
+
code: ExportResultCode.FAILED,
|
|
166
|
+
error: /* @__PURE__ */ new Error(`OTLP export failed: ${res.status}`)
|
|
167
|
+
});
|
|
168
|
+
}).catch((error) => {
|
|
169
|
+
resultCallback({
|
|
170
|
+
code: ExportResultCode.FAILED,
|
|
171
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
async shutdown() {},
|
|
176
|
+
async forceFlush() {}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
export { AuthFeatureNotAvailableError, createLLMOpsAgentsExporter, createLLMOpsMiddleware, createLLMOpsSpanExporter, createLLMOps as llmops };
|
package/dist/nextjs.d.cts
CHANGED
package/dist/nextjs.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmops/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "An LLMOps toolkit for TypeScript applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -38,6 +38,16 @@
|
|
|
38
38
|
"default": "./dist/index.cjs"
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
+
"./agents": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/agents.d.mts",
|
|
44
|
+
"default": "./dist/agents.mjs"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/agents.d.cts",
|
|
48
|
+
"default": "./dist/agents.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
41
51
|
"./express": {
|
|
42
52
|
"import": {
|
|
43
53
|
"types": "./dist/express.d.mts",
|
|
@@ -74,8 +84,8 @@
|
|
|
74
84
|
"access": "public"
|
|
75
85
|
},
|
|
76
86
|
"dependencies": {
|
|
77
|
-
"@llmops/app": "^0.
|
|
78
|
-
"@llmops/core": "^0.
|
|
87
|
+
"@llmops/app": "^0.6.0",
|
|
88
|
+
"@llmops/core": "^0.6.0"
|
|
79
89
|
},
|
|
80
90
|
"devDependencies": {
|
|
81
91
|
"@types/express": "^5.0.6",
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { LLMOpsConfig, ValidatedLLMOpsConfig } from "@llmops/core";
|
|
2
|
-
|
|
3
|
-
//#region src/client/index.d.ts
|
|
4
|
-
type ProviderConfig = {
|
|
5
|
-
baseURL: string;
|
|
6
|
-
apiKey: string;
|
|
7
|
-
fetch: typeof globalThis.fetch;
|
|
8
|
-
};
|
|
9
|
-
type LLMOpsClient = {
|
|
10
|
-
handler: (request: Request) => Promise<Response>;
|
|
11
|
-
config: ValidatedLLMOpsConfig;
|
|
12
|
-
provider: () => ProviderConfig;
|
|
13
|
-
};
|
|
14
|
-
declare const createLLMOps: (config?: LLMOpsConfig) => LLMOpsClient;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { createLLMOps as n, LLMOpsClient as t };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { LLMOpsConfig, ValidatedLLMOpsConfig } from "@llmops/core";
|
|
2
|
-
|
|
3
|
-
//#region src/client/index.d.ts
|
|
4
|
-
type ProviderConfig = {
|
|
5
|
-
baseURL: string;
|
|
6
|
-
apiKey: string;
|
|
7
|
-
fetch: typeof globalThis.fetch;
|
|
8
|
-
};
|
|
9
|
-
type LLMOpsClient = {
|
|
10
|
-
handler: (request: Request) => Promise<Response>;
|
|
11
|
-
config: ValidatedLLMOpsConfig;
|
|
12
|
-
provider: () => ProviderConfig;
|
|
13
|
-
};
|
|
14
|
-
declare const createLLMOps: (config?: LLMOpsConfig) => LLMOpsClient;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { createLLMOps as n, LLMOpsClient as t };
|
|
File without changes
|