@neutrome/open-ai-router 0.1.16 → 0.1.17
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/package.json +1 -1
- package/src/observer.test.ts +27 -0
- package/src/observer.ts +6 -1
package/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { createTraceCollector } from "./observer.ts";
|
|
3
|
+
|
|
4
|
+
describe("createTraceCollector", () => {
|
|
5
|
+
it("prefixes raw trace chunks with event comments", () => {
|
|
6
|
+
const collector = createTraceCollector("00000000-0000-4000-8000-000000000001");
|
|
7
|
+
|
|
8
|
+
collector.observe({
|
|
9
|
+
kind: "request.received",
|
|
10
|
+
requestId: "request-1",
|
|
11
|
+
executionId: "request-1",
|
|
12
|
+
timestamp: "2026-06-24T12:00:00.000Z",
|
|
13
|
+
data: { lilText: "MSG_START" },
|
|
14
|
+
});
|
|
15
|
+
collector.observe({
|
|
16
|
+
kind: "provider.started",
|
|
17
|
+
requestId: "request-1",
|
|
18
|
+
executionId: "provider-1",
|
|
19
|
+
timestamp: "2026-06-24T12:00:01.000Z",
|
|
20
|
+
data: { lilText: "SET_MODEL \"gpt-4o\"" },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(collector.getTrace().rawTrace).toBe(
|
|
24
|
+
';request:0\nMSG_START\n\n;provider:1\nSET_MODEL "gpt-4o"',
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
});
|
package/src/observer.ts
CHANGED
|
@@ -45,6 +45,7 @@ export function createTraceCollector(spanId = crypto.randomUUID()): {
|
|
|
45
45
|
const executorSpans = new Map<string, TraceSpan>();
|
|
46
46
|
const rawSegments: string[] = [];
|
|
47
47
|
const startedAt = new Date().toISOString();
|
|
48
|
+
let rawSegmentIndex = 0;
|
|
48
49
|
let finishedAt: string | undefined;
|
|
49
50
|
let error: string | undefined;
|
|
50
51
|
|
|
@@ -152,10 +153,14 @@ export function createTraceCollector(spanId = crypto.randomUUID()): {
|
|
|
152
153
|
function appendLilSegment(event: AuditEvent): void {
|
|
153
154
|
const lilText = asString(event.data?.lilText)?.trim();
|
|
154
155
|
if (!lilText) return;
|
|
155
|
-
rawSegments.push(lilText);
|
|
156
|
+
rawSegments.push(`;${traceSegmentLabel(event)}:${rawSegmentIndex++}\n${lilText}`);
|
|
156
157
|
}
|
|
157
158
|
}
|
|
158
159
|
|
|
160
|
+
function traceSegmentLabel(event: AuditEvent): string {
|
|
161
|
+
return event.kind.split(".", 1)[0] || "trace";
|
|
162
|
+
}
|
|
163
|
+
|
|
159
164
|
export function renderProgramAsLil(program: Program): string {
|
|
160
165
|
return program.code
|
|
161
166
|
.map((instruction) => {
|