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