bitfab 0.21.2 → 0.23.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/dist/index.cjs CHANGED
@@ -486,6 +486,7 @@ __export(index_exports, {
486
486
  BitfabFunction: () => BitfabFunction,
487
487
  BitfabLangChainCallbackHandler: () => BitfabLangGraphCallbackHandler,
488
488
  BitfabLangGraphCallbackHandler: () => BitfabLangGraphCallbackHandler,
489
+ BitfabOpenAIAgentHandler: () => BitfabOpenAIAgentHandler,
489
490
  BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
490
491
  DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
491
492
  ReplayEnvironment: () => ReplayEnvironment,
@@ -499,7 +500,7 @@ __export(index_exports, {
499
500
  module.exports = __toCommonJS(index_exports);
500
501
 
501
502
  // src/version.generated.ts
502
- var __version__ = "0.21.2";
503
+ var __version__ = "0.23.0";
503
504
 
504
505
  // src/constants.ts
505
506
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1950,8 +1951,9 @@ function extractLangGraphMetadata(metadata) {
1950
1951
  var BitfabLangGraphCallbackHandler = class {
1951
1952
  constructor(config) {
1952
1953
  this.name = "BitfabLangGraphCallbackHandler";
1953
- this.ignoreRetriever = true;
1954
1954
  this.ignoreRetry = true;
1955
+ // Retriever callbacks ARE captured (retriever queries -> function spans).
1956
+ this.ignoreRetriever = false;
1955
1957
  this.ignoreCustomEvent = true;
1956
1958
  this.runToSpan = /* @__PURE__ */ new Map();
1957
1959
  this.invocations = /* @__PURE__ */ new Map();
@@ -2281,6 +2283,39 @@ var BitfabLangGraphCallbackHandler = class {
2281
2283
  }
2282
2284
  };
2283
2285
 
2286
+ // src/openaiAgentSdk.ts
2287
+ var BitfabOpenAIAgentHandler = class {
2288
+ constructor(config) {
2289
+ this.traceFunctionKey = config.traceFunctionKey;
2290
+ this.withSpanFn = config.withSpan;
2291
+ }
2292
+ async wrapRun(agent, input, options) {
2293
+ const { run } = await import("@openai/agents");
2294
+ const isStreaming = options?.stream === true;
2295
+ const finalize = async (result) => {
2296
+ const res = result;
2297
+ if (isStreaming && res?.completed) {
2298
+ try {
2299
+ await res.completed;
2300
+ } catch {
2301
+ }
2302
+ }
2303
+ return res?.finalOutput;
2304
+ };
2305
+ const options_ = { type: "agent", finalize };
2306
+ const traced = this.withSpanFn(
2307
+ this.traceFunctionKey,
2308
+ options_,
2309
+ (agentInput) => run(
2310
+ agent,
2311
+ agentInput,
2312
+ options
2313
+ )
2314
+ );
2315
+ return traced(input);
2316
+ }
2317
+ };
2318
+
2284
2319
  // src/client.ts
2285
2320
  init_replayContext();
2286
2321
 
@@ -2974,6 +3009,34 @@ var Bitfab = class {
2974
3009
  }
2975
3010
  });
2976
3011
  }
3012
+ /**
3013
+ * Get an OpenAI Agents SDK handler that records a replayable root span.
3014
+ *
3015
+ * The processor from {@link getOpenAiTracingProcessor} captures everything
3016
+ * inside a run (LLM calls, tools, handoffs) but never sees the caller's
3017
+ * input, so a processor-only run records an empty-input root and is not
3018
+ * replayable. This handler's `wrapRun` is a drop-in for `run()` that opens a
3019
+ * `withSpan` root carrying the input and final output; the processor's spans
3020
+ * nest beneath it. Register the processor once at startup, then call
3021
+ * `handler.wrapRun(agent, input)` in place of `run(agent, input)`.
3022
+ *
3023
+ * ```typescript
3024
+ * import { addTraceProcessor, Agent, run } from "@openai/agents";
3025
+ *
3026
+ * addTraceProcessor(client.getOpenAiTracingProcessor());
3027
+ * const handler = client.getOpenAiAgentHandler("research-topic");
3028
+ * const result = await handler.wrapRun(agent, "Find X");
3029
+ * ```
3030
+ *
3031
+ * @param traceFunctionKey - Groups traces under this key in Bitfab
3032
+ * @returns A BitfabOpenAIAgentHandler configured for this client
3033
+ */
3034
+ getOpenAiAgentHandler(traceFunctionKey) {
3035
+ return new BitfabOpenAIAgentHandler({
3036
+ traceFunctionKey,
3037
+ withSpan: this.withSpan.bind(this)
3038
+ });
3039
+ }
2977
3040
  /**
2978
3041
  * Get a LangGraph/LangChain callback handler for tracing.
2979
3042
  *
@@ -3724,6 +3787,7 @@ var finalizers = {
3724
3787
  BitfabFunction,
3725
3788
  BitfabLangChainCallbackHandler,
3726
3789
  BitfabLangGraphCallbackHandler,
3790
+ BitfabOpenAIAgentHandler,
3727
3791
  BitfabOpenAITracingProcessor,
3728
3792
  DEFAULT_SERVICE_URL,
3729
3793
  ReplayEnvironment,