retrace-sdk 0.2.3 → 0.3.1
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/README.md +6 -0
- package/dist/recorder.d.ts +1 -0
- package/dist/recorder.js +2 -0
- package/dist/trace.d.ts +4 -0
- package/dist/trace.js +2 -0
- package/dist/transport.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,6 +101,12 @@ configure({ apiKey: "rt_live_...", sampleRate: 0.1 }); // Record 10% of traces
|
|
|
101
101
|
|
|
102
102
|
## Changelog
|
|
103
103
|
|
|
104
|
+
### 0.3.0
|
|
105
|
+
|
|
106
|
+
- **Sessions** — `sessionId` option in `TraceRecorder` and `trace()` to group multi-turn conversations
|
|
107
|
+
- **Multi-Agent** — `setAgentId()` on `SpanBuilder` for cross-agent tracing
|
|
108
|
+
- **Guardrail support** — SDK respects HALT commands from server-side guardrail policies
|
|
109
|
+
|
|
104
110
|
### 0.2.2
|
|
105
111
|
|
|
106
112
|
- **Fixed** — OpenAI interceptor no longer creates dummy client instance to find prototype
|
package/dist/recorder.d.ts
CHANGED
package/dist/recorder.js
CHANGED
|
@@ -18,6 +18,8 @@ export class TraceRecorder {
|
|
|
18
18
|
this.builder.setProjectId(cfg.projectId);
|
|
19
19
|
if (opts?.metadata)
|
|
20
20
|
this.builder.setMetadata(opts.metadata);
|
|
21
|
+
if (opts?.sessionId)
|
|
22
|
+
this.builder.setSessionId(opts.sessionId);
|
|
21
23
|
if (opts?.name || opts?.input) {
|
|
22
24
|
this.builder.start(opts.name, opts.input);
|
|
23
25
|
}
|
package/dist/trace.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export interface SpanData {
|
|
|
26
26
|
cost?: number;
|
|
27
27
|
duration_ms?: number;
|
|
28
28
|
metadata?: Record<string, unknown>;
|
|
29
|
+
agent_id?: string;
|
|
29
30
|
started_at: string;
|
|
30
31
|
ended_at?: string;
|
|
31
32
|
error?: string;
|
|
@@ -40,6 +41,7 @@ export interface TraceData {
|
|
|
40
41
|
total_cost: number;
|
|
41
42
|
total_duration_ms: number;
|
|
42
43
|
metadata?: Record<string, unknown>;
|
|
44
|
+
session_id?: string;
|
|
43
45
|
started_at: string;
|
|
44
46
|
ended_at?: string;
|
|
45
47
|
spans?: SpanData[];
|
|
@@ -55,6 +57,7 @@ export declare class SpanBuilder {
|
|
|
55
57
|
setParentId(id: string): this;
|
|
56
58
|
setTraceId(id: string): this;
|
|
57
59
|
setMetadata(m: Record<string, unknown>): this;
|
|
60
|
+
setAgentId(id: string): this;
|
|
58
61
|
start(): this;
|
|
59
62
|
end(output?: unknown, error?: string): SpanData;
|
|
60
63
|
get id(): string;
|
|
@@ -69,6 +72,7 @@ export declare class TraceBuilder {
|
|
|
69
72
|
addSpan(span: SpanData): void;
|
|
70
73
|
get id(): string;
|
|
71
74
|
setProjectId(id: string): void;
|
|
75
|
+
setSessionId(id: string): void;
|
|
72
76
|
setMetadata(m: Record<string, unknown>): void;
|
|
73
77
|
toDict(): TraceData;
|
|
74
78
|
}
|
package/dist/trace.js
CHANGED
|
@@ -27,6 +27,7 @@ export class SpanBuilder {
|
|
|
27
27
|
setParentId(id) { this.data.parent_id = id; return this; }
|
|
28
28
|
setTraceId(id) { this.data.trace_id = id; return this; }
|
|
29
29
|
setMetadata(m) { this.data.metadata = m; return this; }
|
|
30
|
+
setAgentId(id) { this.data.agent_id = id; return this; }
|
|
30
31
|
start() {
|
|
31
32
|
this._startTime = utcNow();
|
|
32
33
|
this.data.started_at = this._startTime.toISOString();
|
|
@@ -88,6 +89,7 @@ export class TraceBuilder {
|
|
|
88
89
|
}
|
|
89
90
|
get id() { return this.data.id; }
|
|
90
91
|
setProjectId(id) { this.data.project_id = id; }
|
|
92
|
+
setSessionId(id) { this.data.session_id = id; }
|
|
91
93
|
setMetadata(m) { this.data.metadata = m; }
|
|
92
94
|
toDict() { return this.data; }
|
|
93
95
|
}
|
package/dist/transport.js
CHANGED
|
@@ -43,12 +43,17 @@ export class WSTransport {
|
|
|
43
43
|
handleResume(cmd);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
+
else if (msg.type === "halt") {
|
|
47
|
+
const reason = msg.data?.reason || "Guardrail triggered";
|
|
48
|
+
this.onError?.("halt", reason);
|
|
49
|
+
this.close();
|
|
50
|
+
}
|
|
46
51
|
});
|
|
47
52
|
this.ws.on("close", () => {
|
|
48
53
|
this.connected = false;
|
|
49
54
|
this.ws = null;
|
|
50
55
|
if (!this.closed) {
|
|
51
|
-
setTimeout(() => this.reconnect(), this.backoff);
|
|
56
|
+
setTimeout(() => this.reconnect(), this.backoff * (0.5 + Math.random() * 0.5));
|
|
52
57
|
this.backoff = Math.min(this.backoff * 2, 30000);
|
|
53
58
|
}
|
|
54
59
|
});
|