bitfab 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.
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-EQI6ZJC3.js";
11
11
 
12
12
  // src/version.generated.ts
13
- var __version__ = "0.21.2";
13
+ var __version__ = "0.22.0";
14
14
 
15
15
  // src/constants.ts
16
16
  var DEFAULT_SERVICE_URL = "https://bitfab.ai";
@@ -1785,6 +1785,39 @@ var BitfabLangGraphCallbackHandler = class {
1785
1785
  }
1786
1786
  };
1787
1787
 
1788
+ // src/openaiAgentSdk.ts
1789
+ var BitfabOpenAIAgentHandler = class {
1790
+ constructor(config) {
1791
+ this.traceFunctionKey = config.traceFunctionKey;
1792
+ this.withSpanFn = config.withSpan;
1793
+ }
1794
+ async wrapRun(agent, input, options) {
1795
+ const { run } = await import("@openai/agents");
1796
+ const isStreaming = options?.stream === true;
1797
+ const finalize = async (result) => {
1798
+ const res = result;
1799
+ if (isStreaming && res?.completed) {
1800
+ try {
1801
+ await res.completed;
1802
+ } catch {
1803
+ }
1804
+ }
1805
+ return res?.finalOutput;
1806
+ };
1807
+ const options_ = { type: "agent", finalize };
1808
+ const traced = this.withSpanFn(
1809
+ this.traceFunctionKey,
1810
+ options_,
1811
+ (agentInput) => run(
1812
+ agent,
1813
+ agentInput,
1814
+ options
1815
+ )
1816
+ );
1817
+ return traced(input);
1818
+ }
1819
+ };
1820
+
1788
1821
  // src/replayEnvironment.ts
1789
1822
  var ReplayEnvironment = class {
1790
1823
  /**
@@ -2471,6 +2504,34 @@ var Bitfab = class {
2471
2504
  }
2472
2505
  });
2473
2506
  }
2507
+ /**
2508
+ * Get an OpenAI Agents SDK handler that records a replayable root span.
2509
+ *
2510
+ * The processor from {@link getOpenAiTracingProcessor} captures everything
2511
+ * inside a run (LLM calls, tools, handoffs) but never sees the caller's
2512
+ * input, so a processor-only run records an empty-input root and is not
2513
+ * replayable. This handler's `wrapRun` is a drop-in for `run()` that opens a
2514
+ * `withSpan` root carrying the input and final output; the processor's spans
2515
+ * nest beneath it. Register the processor once at startup, then call
2516
+ * `handler.wrapRun(agent, input)` in place of `run(agent, input)`.
2517
+ *
2518
+ * ```typescript
2519
+ * import { addTraceProcessor, Agent, run } from "@openai/agents";
2520
+ *
2521
+ * addTraceProcessor(client.getOpenAiTracingProcessor());
2522
+ * const handler = client.getOpenAiAgentHandler("research-topic");
2523
+ * const result = await handler.wrapRun(agent, "Find X");
2524
+ * ```
2525
+ *
2526
+ * @param traceFunctionKey - Groups traces under this key in Bitfab
2527
+ * @returns A BitfabOpenAIAgentHandler configured for this client
2528
+ */
2529
+ getOpenAiAgentHandler(traceFunctionKey) {
2530
+ return new BitfabOpenAIAgentHandler({
2531
+ traceFunctionKey,
2532
+ withSpan: this.withSpan.bind(this)
2533
+ });
2534
+ }
2474
2535
  /**
2475
2536
  * Get a LangGraph/LangChain callback handler for tracing.
2476
2537
  *
@@ -3221,6 +3282,7 @@ export {
3221
3282
  BitfabClaudeAgentHandler,
3222
3283
  SUPPORTED_PROVIDERS,
3223
3284
  BitfabLangGraphCallbackHandler,
3285
+ BitfabOpenAIAgentHandler,
3224
3286
  ReplayEnvironment,
3225
3287
  BitfabOpenAITracingProcessor,
3226
3288
  getCurrentSpan,
@@ -3229,4 +3291,4 @@ export {
3229
3291
  BitfabFunction,
3230
3292
  finalizers
3231
3293
  };
3232
- //# sourceMappingURL=chunk-3YKMCCDV.js.map
3294
+ //# sourceMappingURL=chunk-4SLFC266.js.map