@bitfab/sdk 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
@@ -477,6 +477,7 @@ __export(index_exports, {
477
477
  BitfabFunction: () => BitfabFunction,
478
478
  BitfabLangChainCallbackHandler: () => BitfabLangGraphCallbackHandler,
479
479
  BitfabLangGraphCallbackHandler: () => BitfabLangGraphCallbackHandler,
480
+ BitfabOpenAIAgentHandler: () => BitfabOpenAIAgentHandler,
480
481
  BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
481
482
  DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
482
483
  ReplayEnvironment: () => ReplayEnvironment,
@@ -490,7 +491,7 @@ __export(index_exports, {
490
491
  module.exports = __toCommonJS(index_exports);
491
492
 
492
493
  // src/version.generated.ts
493
- var __version__ = "0.21.2";
494
+ var __version__ = "0.23.0";
494
495
 
495
496
  // src/constants.ts
496
497
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1941,8 +1942,9 @@ function extractLangGraphMetadata(metadata) {
1941
1942
  var BitfabLangGraphCallbackHandler = class {
1942
1943
  constructor(config) {
1943
1944
  this.name = "BitfabLangGraphCallbackHandler";
1944
- this.ignoreRetriever = true;
1945
1945
  this.ignoreRetry = true;
1946
+ // Retriever callbacks ARE captured (retriever queries -> function spans).
1947
+ this.ignoreRetriever = false;
1946
1948
  this.ignoreCustomEvent = true;
1947
1949
  this.runToSpan = /* @__PURE__ */ new Map();
1948
1950
  this.invocations = /* @__PURE__ */ new Map();
@@ -2272,6 +2274,39 @@ var BitfabLangGraphCallbackHandler = class {
2272
2274
  }
2273
2275
  };
2274
2276
 
2277
+ // src/openaiAgentSdk.ts
2278
+ var BitfabOpenAIAgentHandler = class {
2279
+ constructor(config) {
2280
+ this.traceFunctionKey = config.traceFunctionKey;
2281
+ this.withSpanFn = config.withSpan;
2282
+ }
2283
+ async wrapRun(agent, input, options) {
2284
+ const { run } = await import("@openai/agents");
2285
+ const isStreaming = options?.stream === true;
2286
+ const finalize = async (result) => {
2287
+ const res = result;
2288
+ if (isStreaming && res?.completed) {
2289
+ try {
2290
+ await res.completed;
2291
+ } catch {
2292
+ }
2293
+ }
2294
+ return res?.finalOutput;
2295
+ };
2296
+ const options_ = { type: "agent", finalize };
2297
+ const traced = this.withSpanFn(
2298
+ this.traceFunctionKey,
2299
+ options_,
2300
+ (agentInput) => run(
2301
+ agent,
2302
+ agentInput,
2303
+ options
2304
+ )
2305
+ );
2306
+ return traced(input);
2307
+ }
2308
+ };
2309
+
2275
2310
  // src/client.ts
2276
2311
  init_replayContext();
2277
2312
 
@@ -2965,6 +3000,34 @@ var Bitfab = class {
2965
3000
  }
2966
3001
  });
2967
3002
  }
3003
+ /**
3004
+ * Get an OpenAI Agents SDK handler that records a replayable root span.
3005
+ *
3006
+ * The processor from {@link getOpenAiTracingProcessor} captures everything
3007
+ * inside a run (LLM calls, tools, handoffs) but never sees the caller's
3008
+ * input, so a processor-only run records an empty-input root and is not
3009
+ * replayable. This handler's `wrapRun` is a drop-in for `run()` that opens a
3010
+ * `withSpan` root carrying the input and final output; the processor's spans
3011
+ * nest beneath it. Register the processor once at startup, then call
3012
+ * `handler.wrapRun(agent, input)` in place of `run(agent, input)`.
3013
+ *
3014
+ * ```typescript
3015
+ * import { addTraceProcessor, Agent, run } from "@openai/agents";
3016
+ *
3017
+ * addTraceProcessor(client.getOpenAiTracingProcessor());
3018
+ * const handler = client.getOpenAiAgentHandler("research-topic");
3019
+ * const result = await handler.wrapRun(agent, "Find X");
3020
+ * ```
3021
+ *
3022
+ * @param traceFunctionKey - Groups traces under this key in Bitfab
3023
+ * @returns A BitfabOpenAIAgentHandler configured for this client
3024
+ */
3025
+ getOpenAiAgentHandler(traceFunctionKey) {
3026
+ return new BitfabOpenAIAgentHandler({
3027
+ traceFunctionKey,
3028
+ withSpan: this.withSpan.bind(this)
3029
+ });
3030
+ }
2968
3031
  /**
2969
3032
  * Get a LangGraph/LangChain callback handler for tracing.
2970
3033
  *
@@ -3715,6 +3778,7 @@ var finalizers = {
3715
3778
  BitfabFunction,
3716
3779
  BitfabLangChainCallbackHandler,
3717
3780
  BitfabLangGraphCallbackHandler,
3781
+ BitfabOpenAIAgentHandler,
3718
3782
  BitfabOpenAITracingProcessor,
3719
3783
  DEFAULT_SERVICE_URL,
3720
3784
  ReplayEnvironment,