@bitfab/sdk 0.23.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
@@ -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.23.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
@@ -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.23.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-QOPP5TSO.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.23.0";
508
+ var __version__ = "0.23.1";
509
509
 
510
510
  // src/constants.ts
511
511
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -2293,9 +2293,17 @@ var BitfabOpenAIAgentHandler = class {
2293
2293
  constructor(config) {
2294
2294
  this.traceFunctionKey = config.traceFunctionKey;
2295
2295
  this.withSpanFn = config.withSpan;
2296
+ this.getActiveSpanContext = config.getActiveSpanContext;
2296
2297
  }
2297
2298
  async wrapRun(agent, input, options) {
2298
2299
  const { run } = await import("@openai/agents");
2300
+ if (this.getActiveSpanContext?.() != null) {
2301
+ return run(
2302
+ agent,
2303
+ input,
2304
+ options
2305
+ );
2306
+ }
2299
2307
  const isStreaming = options?.stream === true;
2300
2308
  const finalize = async (result) => {
2301
2309
  const res = result;
@@ -3039,7 +3047,11 @@ var Bitfab = class {
3039
3047
  getOpenAiAgentHandler(traceFunctionKey) {
3040
3048
  return new BitfabOpenAIAgentHandler({
3041
3049
  traceFunctionKey,
3042
- 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
+ }
3043
3055
  });
3044
3056
  }
3045
3057
  /**
@@ -3664,7 +3676,7 @@ var Bitfab = class {
3664
3676
  if (wrappedKey === void 0) {
3665
3677
  replayFn = this.withSpan(
3666
3678
  traceFunctionKey,
3667
- { name: fn.name || "Replay", type: "agent" },
3679
+ { name: traceFunctionKey, type: "agent" },
3668
3680
  fn
3669
3681
  );
3670
3682
  } else if (wrappedKey !== traceFunctionKey) {