retrace-sdk 0.2.2 → 0.3.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/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
@@ -3,6 +3,7 @@ export interface RecordOptions {
3
3
  name?: string;
4
4
  input?: unknown;
5
5
  metadata?: Record<string, unknown>;
6
+ sessionId?: string;
6
7
  }
7
8
  export declare class TraceRecorder {
8
9
  private builder;
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
  }
@@ -95,9 +97,16 @@ export class TraceRecorder {
95
97
  export function record(opts) {
96
98
  const cfg = getConfig();
97
99
  if (!cfg.enabled || Math.random() > cfg.sampleRate) {
98
- // Return a no-op proxy that doesn't require API key or connect
100
+ // Return a no-op that silently swallows all method calls
101
+ const methods = new Set(["start", "end", "startSpan", "endSpan", "addSpan"]);
99
102
  const noop = {};
100
- return new Proxy(noop, { get: (_t, prop) => typeof prop === "string" ? (() => noop) : undefined });
103
+ return new Proxy(noop, {
104
+ get: (_t, prop) => {
105
+ if (typeof prop === "string" && methods.has(prop))
106
+ return () => noop;
107
+ return undefined;
108
+ },
109
+ });
101
110
  }
102
111
  return new TraceRecorder(opts);
103
112
  }
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
@@ -48,7 +48,7 @@ export class WSTransport {
48
48
  this.connected = false;
49
49
  this.ws = null;
50
50
  if (!this.closed) {
51
- setTimeout(() => this.reconnect(), this.backoff);
51
+ setTimeout(() => this.reconnect(), this.backoff * (0.5 + Math.random() * 0.5));
52
52
  this.backoff = Math.min(this.backoff * 2, 30000);
53
53
  }
54
54
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retrace-sdk",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "The execution replay engine for AI agents. Record, replay, fork, and share agent executions.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",