@neutrome/open-ai-router 0.1.16 → 0.1.18

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neutrome/open-ai-router",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -0,0 +1,34 @@
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.request",
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
+ collector.observe({
23
+ kind: "provider.response_chunk",
24
+ requestId: "request-1",
25
+ executionId: "provider-1",
26
+ timestamp: "2026-06-24T12:00:02.000Z",
27
+ data: { lilText: "STREAM_DELTA \"Hi\"" },
28
+ });
29
+
30
+ expect(collector.getTrace().rawTrace).toBe(
31
+ ';request:0\nMSG_START\n\n;provider-request:1\nSET_MODEL "gpt-4o"\n\n;provider-response-chunk:2\nSTREAM_DELTA "Hi"',
32
+ );
33
+ });
34
+ });
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,7 +153,24 @@ 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}`);
157
+ }
158
+ }
159
+
160
+ function traceSegmentLabel(event: AuditEvent): string {
161
+ switch (event.kind) {
162
+ case "request.received":
163
+ return "request";
164
+ case "provider.request":
165
+ return "provider-request";
166
+ case "provider.response":
167
+ return "provider-response";
168
+ case "provider.response_chunk":
169
+ return "provider-response-chunk";
170
+ case "tool.executed":
171
+ return "tool";
172
+ default:
173
+ return event.kind.replace(/\./g, "-") || "trace";
156
174
  }
157
175
  }
158
176