retrace-sdk 0.5.4 → 0.6.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
@@ -111,6 +111,12 @@ configure({ apiKey: "rt_live_...", sampleRate: 0.1 }); // Record 10% of traces
111
111
 
112
112
  - **Fixed** — OpenAI interceptor no longer creates dummy client instance to find prototype
113
113
 
114
+ ### 0.6.0
115
+
116
+ - **Token ID capture** — Stores output token IDs + logprobs from OpenAI responses (enables speculative decoding during replay)
117
+ - **SpanData extended** — New `token_ids` and `logprobs` fields on SpanData interface
118
+ - **Shared schema** — SpanInputSchema updated with `token_ids` and `logprobs` optional arrays
119
+
114
120
  ### 0.2.1
115
121
 
116
122
  - **Offline buffer** — stores up to 1000 messages when WebSocket disconnects, flushes on reconnect
@@ -188,6 +188,12 @@ function createPatchedCreate() {
188
188
  const inputTokens = res?.usage?.prompt_tokens || 0;
189
189
  const outputTokens = res?.usage?.completion_tokens || 0;
190
190
  const output = res?.choices?.[0]?.message?.content || "";
191
+ // Extract token IDs and logprobs if available (requires logprobs: true in request)
192
+ const choiceLogprobs = res?.choices?.[0]?.logprobs?.content;
193
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
194
+ const tokenIds = choiceLogprobs?.map((t) => t.token_id ?? t.top_logprobs?.[0]?.token_id).filter(Boolean);
195
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
196
+ const logprobValues = choiceLogprobs?.map((t) => t.logprob).filter((v) => v !== undefined);
191
197
  const span = {
192
198
  id: spanId, trace_id: "", parent_id: null,
193
199
  span_type: SpanType.LLM_CALL, name: "openai.chat.completions.create", model,
@@ -196,6 +202,8 @@ function createPatchedCreate() {
196
202
  input_tokens: inputTokens, output_tokens: outputTokens,
197
203
  cost: calcCost(model, inputTokens, outputTokens),
198
204
  duration_ms: durationMs, started_at: startedAt, ended_at: nowIso(),
205
+ ...(tokenIds?.length ? { token_ids: tokenIds } : {}),
206
+ ...(logprobValues?.length ? { logprobs: logprobValues } : {}),
199
207
  ...(Object.keys(spanMetadata).length ? { metadata: spanMetadata } : {}),
200
208
  };
201
209
  onSpanCallback?.(span);
package/dist/trace.d.ts CHANGED
@@ -30,6 +30,8 @@ export interface SpanData {
30
30
  started_at: string;
31
31
  ended_at?: string;
32
32
  error?: string;
33
+ token_ids?: number[];
34
+ logprobs?: number[];
33
35
  }
34
36
  export interface TraceData {
35
37
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retrace-sdk",
3
- "version": "0.5.4",
3
+ "version": "0.6.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",