@hebo-ai/gateway 0.4.0-beta.2 → 0.4.0-beta.3
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/endpoints/chat-completions/handler.js +2 -3
- package/dist/endpoints/embeddings/handler.js +2 -3
- package/dist/telemetry/otel.js +7 -3
- package/package.json +1 -1
- package/src/endpoints/chat-completions/handler.ts +2 -3
- package/src/endpoints/embeddings/handler.ts +2 -3
- package/src/telemetry/otel.ts +7 -3
|
@@ -20,15 +20,14 @@ export const chatCompletions = (config) => {
|
|
|
20
20
|
}
|
|
21
21
|
const requestId = resolveRequestId(ctx.request);
|
|
22
22
|
// Parse + validate input.
|
|
23
|
-
let body;
|
|
24
23
|
try {
|
|
25
|
-
body = await ctx.request.json();
|
|
24
|
+
ctx.body = await ctx.request.json();
|
|
26
25
|
}
|
|
27
26
|
catch {
|
|
28
27
|
throw new GatewayError("Invalid JSON", 400);
|
|
29
28
|
}
|
|
30
29
|
addSpanEvent("hebo.request.deserialized");
|
|
31
|
-
const parsed = ChatCompletionsBodySchema.safeParse(body);
|
|
30
|
+
const parsed = ChatCompletionsBodySchema.safeParse(ctx.body);
|
|
32
31
|
if (!parsed.success) {
|
|
33
32
|
throw new GatewayError(z.prettifyError(parsed.error), 400);
|
|
34
33
|
}
|
|
@@ -20,15 +20,14 @@ export const embeddings = (config) => {
|
|
|
20
20
|
}
|
|
21
21
|
const requestId = resolveRequestId(ctx.request);
|
|
22
22
|
// Parse + validate input.
|
|
23
|
-
let body;
|
|
24
23
|
try {
|
|
25
|
-
body = await ctx.request.json();
|
|
24
|
+
ctx.body = await ctx.request.json();
|
|
26
25
|
}
|
|
27
26
|
catch {
|
|
28
27
|
throw new GatewayError("Invalid JSON", 400);
|
|
29
28
|
}
|
|
30
29
|
addSpanEvent("hebo.request.deserialized");
|
|
31
|
-
const parsed = EmbeddingsBodySchema.safeParse(body);
|
|
30
|
+
const parsed = EmbeddingsBodySchema.safeParse(ctx.body);
|
|
32
31
|
if (!parsed.success) {
|
|
33
32
|
throw new GatewayError(z.prettifyError(parsed.error), 400);
|
|
34
33
|
}
|
package/dist/telemetry/otel.js
CHANGED
|
@@ -14,13 +14,17 @@ export const withOtel = (run, config) => async (ctx) => {
|
|
|
14
14
|
Object.assign(attrs, getRequestAttributes(ctx.request, config.telemetry?.attributes), getResponseAttributes(ctx.response, config.telemetry?.attributes));
|
|
15
15
|
}
|
|
16
16
|
Object.assign(attrs, getBaggageAttributes(ctx.request));
|
|
17
|
-
if (config.telemetry?.attributes
|
|
17
|
+
if (config.telemetry?.attributes !== "required") {
|
|
18
18
|
attrs["http.request.body.size"] = Number(ctx.request.headers.get("content-length") || 0);
|
|
19
19
|
attrs["http.response.body.size"] =
|
|
20
20
|
stats?.bytes ?? Number(attrs["http.response.header.content-length"] || 0);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
if (config.telemetry?.attributes === "full") {
|
|
23
|
+
attrs["http.request.body"] = JSON.stringify(ctx.body);
|
|
24
|
+
}
|
|
25
|
+
const realStatus = status === 200 ? (ctx.response?.status ?? status) : status;
|
|
26
|
+
attrs["http.response.status_code_effective"] = realStatus;
|
|
27
|
+
aiSpan.setStatus({ code: realStatus >= 500 ? SpanStatusCode.ERROR : SpanStatusCode.OK });
|
|
24
28
|
if (ctx.operation && ctx.modelId) {
|
|
25
29
|
aiSpan.updateName(`${ctx.operation} ${ctx.modelId}`);
|
|
26
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hebo-ai/gateway",
|
|
3
|
-
"version": "0.4.0-beta.
|
|
3
|
+
"version": "0.4.0-beta.3",
|
|
4
4
|
"description": "AI gateway as a framework. For full control over models, routing & lifecycle. OpenAI-compatible /chat/completions, /embeddings & /models.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -43,15 +43,14 @@ export const chatCompletions = (config: GatewayConfig): Endpoint => {
|
|
|
43
43
|
const requestId = resolveRequestId(ctx.request);
|
|
44
44
|
|
|
45
45
|
// Parse + validate input.
|
|
46
|
-
let body;
|
|
47
46
|
try {
|
|
48
|
-
body = await ctx.request.json();
|
|
47
|
+
ctx.body = await ctx.request.json();
|
|
49
48
|
} catch {
|
|
50
49
|
throw new GatewayError("Invalid JSON", 400);
|
|
51
50
|
}
|
|
52
51
|
addSpanEvent("hebo.request.deserialized");
|
|
53
52
|
|
|
54
|
-
const parsed = ChatCompletionsBodySchema.safeParse(body);
|
|
53
|
+
const parsed = ChatCompletionsBodySchema.safeParse(ctx.body);
|
|
55
54
|
if (!parsed.success) {
|
|
56
55
|
throw new GatewayError(z.prettifyError(parsed.error), 400);
|
|
57
56
|
}
|
|
@@ -36,15 +36,14 @@ export const embeddings = (config: GatewayConfig): Endpoint => {
|
|
|
36
36
|
const requestId = resolveRequestId(ctx.request);
|
|
37
37
|
|
|
38
38
|
// Parse + validate input.
|
|
39
|
-
let body;
|
|
40
39
|
try {
|
|
41
|
-
body = await ctx.request.json();
|
|
40
|
+
ctx.body = await ctx.request.json();
|
|
42
41
|
} catch {
|
|
43
42
|
throw new GatewayError("Invalid JSON", 400);
|
|
44
43
|
}
|
|
45
44
|
addSpanEvent("hebo.request.deserialized");
|
|
46
45
|
|
|
47
|
-
const parsed = EmbeddingsBodySchema.safeParse(body);
|
|
46
|
+
const parsed = EmbeddingsBodySchema.safeParse(ctx.body);
|
|
48
47
|
if (!parsed.success) {
|
|
49
48
|
throw new GatewayError(z.prettifyError(parsed.error), 400);
|
|
50
49
|
}
|
package/src/telemetry/otel.ts
CHANGED
|
@@ -43,15 +43,19 @@ export const withOtel =
|
|
|
43
43
|
|
|
44
44
|
Object.assign(attrs, getBaggageAttributes(ctx.request));
|
|
45
45
|
|
|
46
|
-
if (config.telemetry?.attributes
|
|
46
|
+
if (config.telemetry?.attributes !== "required") {
|
|
47
47
|
attrs["http.request.body.size"] = Number(ctx.request.headers.get("content-length") || 0);
|
|
48
48
|
attrs["http.response.body.size"] =
|
|
49
49
|
stats?.bytes ?? Number(attrs["http.response.header.content-length"] || 0);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
if (config.telemetry?.attributes === "full") {
|
|
53
|
+
attrs["http.request.body"] = JSON.stringify(ctx.body);
|
|
54
|
+
}
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
const realStatus = status === 200 ? (ctx.response?.status ?? status) : status;
|
|
57
|
+
attrs["http.response.status_code_effective"] = realStatus;
|
|
58
|
+
aiSpan.setStatus({ code: realStatus >= 500 ? SpanStatusCode.ERROR : SpanStatusCode.OK });
|
|
55
59
|
|
|
56
60
|
if (ctx.operation && ctx.modelId) {
|
|
57
61
|
aiSpan.updateName(`${ctx.operation} ${ctx.modelId}`);
|