@bitfab/sdk 0.22.0 → 0.23.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/dist/index.d.cts CHANGED
@@ -278,8 +278,8 @@ interface ActiveSpanContext$1 {
278
278
  */
279
279
  declare class BitfabLangGraphCallbackHandler {
280
280
  name: string;
281
- ignoreRetriever: boolean;
282
281
  ignoreRetry: boolean;
282
+ ignoreRetriever: boolean;
283
283
  ignoreCustomEvent: boolean;
284
284
  private readonly httpClient;
285
285
  private readonly traceFunctionKey;
@@ -330,6 +330,14 @@ declare class BitfabLangGraphCallbackHandler {
330
330
  * replayable with no hand-written `withSpan`. The processor's spans nest
331
331
  * underneath it automatically (it remaps onto the active span context).
332
332
  *
333
+ * When `wrapRun` runs inside an enclosing Bitfab span (the replay auto-wrap, or
334
+ * a caller's own `withSpan`), that span is already the replayable root: the
335
+ * handler skips opening a second one and lets the processor nest the run's spans
336
+ * under the existing root. This mirrors the Claude Agent SDK and LangGraph
337
+ * handlers, which no-op their root span under an enclosing span, and keeps a
338
+ * replayed run's span tree identical to the original (no doubled root agent
339
+ * span).
340
+ *
333
341
  * Use both together: register the processor once at startup, then call
334
342
  * `handler.wrapRun(agent, input)` instead of `run(agent, input)`.
335
343
  */
@@ -339,6 +347,7 @@ type RootSpanOptions = {
339
347
  finalize: (result: unknown) => unknown | Promise<unknown>;
340
348
  };
341
349
  type WithSpanFn = <TArgs extends unknown[], TReturn>(traceFunctionKey: string, options: RootSpanOptions, fn: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
350
+ type GetActiveSpanContextFn = () => unknown | null;
342
351
  type RunInput<TContext, TAgent extends Agent<any, any>> = string | AgentInputItem[] | RunState<TContext, TAgent>;
343
352
  /**
344
353
  * OpenAI Agents SDK handler that records a replayable root span around a run.
@@ -361,9 +370,11 @@ type RunInput<TContext, TAgent extends Agent<any, any>> = string | AgentInputIte
361
370
  declare class BitfabOpenAIAgentHandler {
362
371
  private readonly traceFunctionKey;
363
372
  private readonly withSpanFn;
373
+ private readonly getActiveSpanContext?;
364
374
  constructor(config: {
365
375
  traceFunctionKey: string;
366
376
  withSpan: WithSpanFn;
377
+ getActiveSpanContext?: GetActiveSpanContextFn;
367
378
  });
368
379
  /**
369
380
  * Drop-in replacement for the OpenAI Agents SDK's `run()` that records a
@@ -1210,7 +1221,7 @@ declare class BitfabFunction {
1210
1221
  /**
1211
1222
  * SDK version from package.json (injected at build time)
1212
1223
  */
1213
- declare const __version__ = "0.22.0";
1224
+ declare const __version__ = "0.23.1";
1214
1225
 
1215
1226
  /**
1216
1227
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -278,8 +278,8 @@ interface ActiveSpanContext$1 {
278
278
  */
279
279
  declare class BitfabLangGraphCallbackHandler {
280
280
  name: string;
281
- ignoreRetriever: boolean;
282
281
  ignoreRetry: boolean;
282
+ ignoreRetriever: boolean;
283
283
  ignoreCustomEvent: boolean;
284
284
  private readonly httpClient;
285
285
  private readonly traceFunctionKey;
@@ -330,6 +330,14 @@ declare class BitfabLangGraphCallbackHandler {
330
330
  * replayable with no hand-written `withSpan`. The processor's spans nest
331
331
  * underneath it automatically (it remaps onto the active span context).
332
332
  *
333
+ * When `wrapRun` runs inside an enclosing Bitfab span (the replay auto-wrap, or
334
+ * a caller's own `withSpan`), that span is already the replayable root: the
335
+ * handler skips opening a second one and lets the processor nest the run's spans
336
+ * under the existing root. This mirrors the Claude Agent SDK and LangGraph
337
+ * handlers, which no-op their root span under an enclosing span, and keeps a
338
+ * replayed run's span tree identical to the original (no doubled root agent
339
+ * span).
340
+ *
333
341
  * Use both together: register the processor once at startup, then call
334
342
  * `handler.wrapRun(agent, input)` instead of `run(agent, input)`.
335
343
  */
@@ -339,6 +347,7 @@ type RootSpanOptions = {
339
347
  finalize: (result: unknown) => unknown | Promise<unknown>;
340
348
  };
341
349
  type WithSpanFn = <TArgs extends unknown[], TReturn>(traceFunctionKey: string, options: RootSpanOptions, fn: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
350
+ type GetActiveSpanContextFn = () => unknown | null;
342
351
  type RunInput<TContext, TAgent extends Agent<any, any>> = string | AgentInputItem[] | RunState<TContext, TAgent>;
343
352
  /**
344
353
  * OpenAI Agents SDK handler that records a replayable root span around a run.
@@ -361,9 +370,11 @@ type RunInput<TContext, TAgent extends Agent<any, any>> = string | AgentInputIte
361
370
  declare class BitfabOpenAIAgentHandler {
362
371
  private readonly traceFunctionKey;
363
372
  private readonly withSpanFn;
373
+ private readonly getActiveSpanContext?;
364
374
  constructor(config: {
365
375
  traceFunctionKey: string;
366
376
  withSpan: WithSpanFn;
377
+ getActiveSpanContext?: GetActiveSpanContextFn;
367
378
  });
368
379
  /**
369
380
  * Drop-in replacement for the OpenAI Agents SDK's `run()` that records a
@@ -1210,7 +1221,7 @@ declare class BitfabFunction {
1210
1221
  /**
1211
1222
  * SDK version from package.json (injected at build time)
1212
1223
  */
1213
- declare const __version__ = "0.22.0";
1224
+ declare const __version__ = "0.23.1";
1214
1225
 
1215
1226
  /**
1216
1227
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  flushTraces,
14
14
  getCurrentSpan,
15
15
  getCurrentTrace
16
- } from "./chunk-4SLFC266.js";
16
+ } from "./chunk-2EDITKO2.js";
17
17
  import {
18
18
  BitfabError
19
19
  } from "./chunk-EQI6ZJC3.js";
package/dist/node.cjs CHANGED
@@ -505,7 +505,7 @@ registerAsyncLocalStorageClass(
505
505
  );
506
506
 
507
507
  // src/version.generated.ts
508
- var __version__ = "0.22.0";
508
+ var __version__ = "0.23.1";
509
509
 
510
510
  // src/constants.ts
511
511
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1956,8 +1956,9 @@ function extractLangGraphMetadata(metadata) {
1956
1956
  var BitfabLangGraphCallbackHandler = class {
1957
1957
  constructor(config) {
1958
1958
  this.name = "BitfabLangGraphCallbackHandler";
1959
- this.ignoreRetriever = true;
1960
1959
  this.ignoreRetry = true;
1960
+ // Retriever callbacks ARE captured (retriever queries -> function spans).
1961
+ this.ignoreRetriever = false;
1961
1962
  this.ignoreCustomEvent = true;
1962
1963
  this.runToSpan = /* @__PURE__ */ new Map();
1963
1964
  this.invocations = /* @__PURE__ */ new Map();
@@ -2292,9 +2293,17 @@ var BitfabOpenAIAgentHandler = class {
2292
2293
  constructor(config) {
2293
2294
  this.traceFunctionKey = config.traceFunctionKey;
2294
2295
  this.withSpanFn = config.withSpan;
2296
+ this.getActiveSpanContext = config.getActiveSpanContext;
2295
2297
  }
2296
2298
  async wrapRun(agent, input, options) {
2297
2299
  const { run } = await import("@openai/agents");
2300
+ if (this.getActiveSpanContext?.() != null) {
2301
+ return run(
2302
+ agent,
2303
+ input,
2304
+ options
2305
+ );
2306
+ }
2298
2307
  const isStreaming = options?.stream === true;
2299
2308
  const finalize = async (result) => {
2300
2309
  const res = result;
@@ -3038,7 +3047,11 @@ var Bitfab = class {
3038
3047
  getOpenAiAgentHandler(traceFunctionKey) {
3039
3048
  return new BitfabOpenAIAgentHandler({
3040
3049
  traceFunctionKey,
3041
- withSpan: this.withSpan.bind(this)
3050
+ withSpan: this.withSpan.bind(this),
3051
+ getActiveSpanContext: () => {
3052
+ const stack = getSpanStack();
3053
+ return stack[stack.length - 1] ?? null;
3054
+ }
3042
3055
  });
3043
3056
  }
3044
3057
  /**
@@ -3663,7 +3676,7 @@ var Bitfab = class {
3663
3676
  if (wrappedKey === void 0) {
3664
3677
  replayFn = this.withSpan(
3665
3678
  traceFunctionKey,
3666
- { name: fn.name || "Replay", type: "agent" },
3679
+ { name: traceFunctionKey, type: "agent" },
3667
3680
  fn
3668
3681
  );
3669
3682
  } else if (wrappedKey !== traceFunctionKey) {