@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/{chunk-3YKMCCDV.js → chunk-QOPP5TSO.js} +66 -3
- package/dist/chunk-QOPP5TSO.js.map +1 -0
- package/dist/index.cjs +66 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -4
- package/dist/index.d.ts +97 -4
- package/dist/index.js +3 -1
- package/dist/node.cjs +66 -2
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +3 -1
- package/dist/node.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-3YKMCCDV.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Trace, Span } from '@openai/agents';
|
|
1
|
+
import { Agent, AgentInputItem, RunState, NonStreamRunOptions, RunResult, StreamRunOptions, StreamedRunResult, Trace, Span } from '@openai/agents';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* BAML execution utilities for the Bitfab TypeScript SDK.
|
|
@@ -278,8 +278,8 @@ interface ActiveSpanContext$1 {
|
|
|
278
278
|
*/
|
|
279
279
|
declare class BitfabLangGraphCallbackHandler {
|
|
280
280
|
name: string;
|
|
281
|
-
ignoreRetriever: boolean;
|
|
282
281
|
ignoreRetry: boolean;
|
|
282
|
+
ignoreRetriever: boolean;
|
|
283
283
|
ignoreCustomEvent: boolean;
|
|
284
284
|
private readonly httpClient;
|
|
285
285
|
private readonly traceFunctionKey;
|
|
@@ -313,6 +313,76 @@ declare class BitfabLangGraphCallbackHandler {
|
|
|
313
313
|
handleRetrieverError(error: unknown, runId: string): Promise<void>;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
/**
|
|
317
|
+
* OpenAI Agents SDK handler for Bitfab tracing.
|
|
318
|
+
*
|
|
319
|
+
* The OpenAI Agents SDK is instrumented in two layers:
|
|
320
|
+
*
|
|
321
|
+
* 1. A process-wide `TracingProcessor` (see `getOpenAiTracingProcessor` /
|
|
322
|
+
* `BitfabOpenAITracingProcessor`) registered once with `addTraceProcessor`.
|
|
323
|
+
* It captures everything *inside* a run — LLM calls, tool calls, handoffs —
|
|
324
|
+
* as Bitfab spans.
|
|
325
|
+
* 2. This handler's `wrapRun`, which owns the *root*. The processor never sees
|
|
326
|
+
* the caller's input (the SDK's trace events don't carry it), so a
|
|
327
|
+
* processor-only run records a root span with an empty input and is not
|
|
328
|
+
* replayable. `wrapRun` is a thin drop-in for `run()` that opens a
|
|
329
|
+
* `withSpan` root carrying the input and final output, so the run is
|
|
330
|
+
* replayable with no hand-written `withSpan`. The processor's spans nest
|
|
331
|
+
* underneath it automatically (it remaps onto the active span context).
|
|
332
|
+
*
|
|
333
|
+
* Use both together: register the processor once at startup, then call
|
|
334
|
+
* `handler.wrapRun(agent, input)` instead of `run(agent, input)`.
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
type RootSpanOptions = {
|
|
338
|
+
type: "agent";
|
|
339
|
+
finalize: (result: unknown) => unknown | Promise<unknown>;
|
|
340
|
+
};
|
|
341
|
+
type WithSpanFn = <TArgs extends unknown[], TReturn>(traceFunctionKey: string, options: RootSpanOptions, fn: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
|
|
342
|
+
type RunInput<TContext, TAgent extends Agent<any, any>> = string | AgentInputItem[] | RunState<TContext, TAgent>;
|
|
343
|
+
/**
|
|
344
|
+
* OpenAI Agents SDK handler that records a replayable root span around a run.
|
|
345
|
+
*
|
|
346
|
+
* ```typescript
|
|
347
|
+
* import { Bitfab } from "@bitfab/sdk";
|
|
348
|
+
* import { addTraceProcessor, Agent, run } from "@openai/agents";
|
|
349
|
+
*
|
|
350
|
+
* const bitfab = new Bitfab({ apiKey: "..." });
|
|
351
|
+
* addTraceProcessor(bitfab.getOpenAiTracingProcessor()); // captures internals
|
|
352
|
+
*
|
|
353
|
+
* const agent = new Agent({ name: "Researcher", instructions: "..." });
|
|
354
|
+
* const handler = bitfab.getOpenAiAgentHandler("research-topic");
|
|
355
|
+
*
|
|
356
|
+
* // Swap run(agent, input) -> handler.wrapRun(agent, input)
|
|
357
|
+
* const result = await handler.wrapRun(agent, "Find X");
|
|
358
|
+
* return result.finalOutput;
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
declare class BitfabOpenAIAgentHandler {
|
|
362
|
+
private readonly traceFunctionKey;
|
|
363
|
+
private readonly withSpanFn;
|
|
364
|
+
constructor(config: {
|
|
365
|
+
traceFunctionKey: string;
|
|
366
|
+
withSpan: WithSpanFn;
|
|
367
|
+
});
|
|
368
|
+
/**
|
|
369
|
+
* Drop-in replacement for the OpenAI Agents SDK's `run()` that records a
|
|
370
|
+
* replayable root `agent` span.
|
|
371
|
+
*
|
|
372
|
+
* The `input` is captured as the root span's input (as a single positional
|
|
373
|
+
* argument, so `replay(key, fn)` re-feeds it), and the run's `finalOutput`
|
|
374
|
+
* is recorded as the root output. For streaming runs (`{ stream: true }`),
|
|
375
|
+
* the result is handed back immediately and the final output is recorded
|
|
376
|
+
* once the stream completes — first-byte latency is untouched.
|
|
377
|
+
*
|
|
378
|
+
* The process-wide tracing processor (`getOpenAiTracingProcessor`) must still
|
|
379
|
+
* be registered: it captures the LLM/tool/handoff spans that nest beneath
|
|
380
|
+
* this root.
|
|
381
|
+
*/
|
|
382
|
+
wrapRun<TAgent extends Agent<any, any>, TContext = undefined>(agent: TAgent, input: RunInput<TContext, TAgent>, options?: NonStreamRunOptions<TContext>): Promise<RunResult<TContext, TAgent>>;
|
|
383
|
+
wrapRun<TAgent extends Agent<any, any>, TContext = undefined>(agent: TAgent, input: RunInput<TContext, TAgent>, options: StreamRunOptions<TContext>): Promise<StreamedRunResult<TContext, TAgent>>;
|
|
384
|
+
}
|
|
385
|
+
|
|
316
386
|
/**
|
|
317
387
|
* Per-trace environment exposed to customer code during replay.
|
|
318
388
|
*
|
|
@@ -863,6 +933,29 @@ declare class Bitfab {
|
|
|
863
933
|
* @returns A BitfabOpenAITracingProcessor instance configured for this client
|
|
864
934
|
*/
|
|
865
935
|
getOpenAiTracingProcessor(): BitfabOpenAITracingProcessor;
|
|
936
|
+
/**
|
|
937
|
+
* Get an OpenAI Agents SDK handler that records a replayable root span.
|
|
938
|
+
*
|
|
939
|
+
* The processor from {@link getOpenAiTracingProcessor} captures everything
|
|
940
|
+
* inside a run (LLM calls, tools, handoffs) but never sees the caller's
|
|
941
|
+
* input, so a processor-only run records an empty-input root and is not
|
|
942
|
+
* replayable. This handler's `wrapRun` is a drop-in for `run()` that opens a
|
|
943
|
+
* `withSpan` root carrying the input and final output; the processor's spans
|
|
944
|
+
* nest beneath it. Register the processor once at startup, then call
|
|
945
|
+
* `handler.wrapRun(agent, input)` in place of `run(agent, input)`.
|
|
946
|
+
*
|
|
947
|
+
* ```typescript
|
|
948
|
+
* import { addTraceProcessor, Agent, run } from "@openai/agents";
|
|
949
|
+
*
|
|
950
|
+
* addTraceProcessor(client.getOpenAiTracingProcessor());
|
|
951
|
+
* const handler = client.getOpenAiAgentHandler("research-topic");
|
|
952
|
+
* const result = await handler.wrapRun(agent, "Find X");
|
|
953
|
+
* ```
|
|
954
|
+
*
|
|
955
|
+
* @param traceFunctionKey - Groups traces under this key in Bitfab
|
|
956
|
+
* @returns A BitfabOpenAIAgentHandler configured for this client
|
|
957
|
+
*/
|
|
958
|
+
getOpenAiAgentHandler(traceFunctionKey: string): BitfabOpenAIAgentHandler;
|
|
866
959
|
/**
|
|
867
960
|
* Get a LangGraph/LangChain callback handler for tracing.
|
|
868
961
|
*
|
|
@@ -1117,7 +1210,7 @@ declare class BitfabFunction {
|
|
|
1117
1210
|
/**
|
|
1118
1211
|
* SDK version from package.json (injected at build time)
|
|
1119
1212
|
*/
|
|
1120
|
-
declare const __version__ = "0.
|
|
1213
|
+
declare const __version__ = "0.23.0";
|
|
1121
1214
|
|
|
1122
1215
|
/**
|
|
1123
1216
|
* Constants for the Bitfab SDK.
|
|
@@ -1185,4 +1278,4 @@ declare const finalizers: {
|
|
|
1185
1278
|
readableStream: typeof readableStream;
|
|
1186
1279
|
};
|
|
1187
1280
|
|
|
1188
|
-
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace };
|
|
1281
|
+
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Trace, Span } from '@openai/agents';
|
|
1
|
+
import { Agent, AgentInputItem, RunState, NonStreamRunOptions, RunResult, StreamRunOptions, StreamedRunResult, Trace, Span } from '@openai/agents';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* BAML execution utilities for the Bitfab TypeScript SDK.
|
|
@@ -278,8 +278,8 @@ interface ActiveSpanContext$1 {
|
|
|
278
278
|
*/
|
|
279
279
|
declare class BitfabLangGraphCallbackHandler {
|
|
280
280
|
name: string;
|
|
281
|
-
ignoreRetriever: boolean;
|
|
282
281
|
ignoreRetry: boolean;
|
|
282
|
+
ignoreRetriever: boolean;
|
|
283
283
|
ignoreCustomEvent: boolean;
|
|
284
284
|
private readonly httpClient;
|
|
285
285
|
private readonly traceFunctionKey;
|
|
@@ -313,6 +313,76 @@ declare class BitfabLangGraphCallbackHandler {
|
|
|
313
313
|
handleRetrieverError(error: unknown, runId: string): Promise<void>;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
/**
|
|
317
|
+
* OpenAI Agents SDK handler for Bitfab tracing.
|
|
318
|
+
*
|
|
319
|
+
* The OpenAI Agents SDK is instrumented in two layers:
|
|
320
|
+
*
|
|
321
|
+
* 1. A process-wide `TracingProcessor` (see `getOpenAiTracingProcessor` /
|
|
322
|
+
* `BitfabOpenAITracingProcessor`) registered once with `addTraceProcessor`.
|
|
323
|
+
* It captures everything *inside* a run — LLM calls, tool calls, handoffs —
|
|
324
|
+
* as Bitfab spans.
|
|
325
|
+
* 2. This handler's `wrapRun`, which owns the *root*. The processor never sees
|
|
326
|
+
* the caller's input (the SDK's trace events don't carry it), so a
|
|
327
|
+
* processor-only run records a root span with an empty input and is not
|
|
328
|
+
* replayable. `wrapRun` is a thin drop-in for `run()` that opens a
|
|
329
|
+
* `withSpan` root carrying the input and final output, so the run is
|
|
330
|
+
* replayable with no hand-written `withSpan`. The processor's spans nest
|
|
331
|
+
* underneath it automatically (it remaps onto the active span context).
|
|
332
|
+
*
|
|
333
|
+
* Use both together: register the processor once at startup, then call
|
|
334
|
+
* `handler.wrapRun(agent, input)` instead of `run(agent, input)`.
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
type RootSpanOptions = {
|
|
338
|
+
type: "agent";
|
|
339
|
+
finalize: (result: unknown) => unknown | Promise<unknown>;
|
|
340
|
+
};
|
|
341
|
+
type WithSpanFn = <TArgs extends unknown[], TReturn>(traceFunctionKey: string, options: RootSpanOptions, fn: (...args: TArgs) => TReturn) => (...args: TArgs) => TReturn;
|
|
342
|
+
type RunInput<TContext, TAgent extends Agent<any, any>> = string | AgentInputItem[] | RunState<TContext, TAgent>;
|
|
343
|
+
/**
|
|
344
|
+
* OpenAI Agents SDK handler that records a replayable root span around a run.
|
|
345
|
+
*
|
|
346
|
+
* ```typescript
|
|
347
|
+
* import { Bitfab } from "@bitfab/sdk";
|
|
348
|
+
* import { addTraceProcessor, Agent, run } from "@openai/agents";
|
|
349
|
+
*
|
|
350
|
+
* const bitfab = new Bitfab({ apiKey: "..." });
|
|
351
|
+
* addTraceProcessor(bitfab.getOpenAiTracingProcessor()); // captures internals
|
|
352
|
+
*
|
|
353
|
+
* const agent = new Agent({ name: "Researcher", instructions: "..." });
|
|
354
|
+
* const handler = bitfab.getOpenAiAgentHandler("research-topic");
|
|
355
|
+
*
|
|
356
|
+
* // Swap run(agent, input) -> handler.wrapRun(agent, input)
|
|
357
|
+
* const result = await handler.wrapRun(agent, "Find X");
|
|
358
|
+
* return result.finalOutput;
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
declare class BitfabOpenAIAgentHandler {
|
|
362
|
+
private readonly traceFunctionKey;
|
|
363
|
+
private readonly withSpanFn;
|
|
364
|
+
constructor(config: {
|
|
365
|
+
traceFunctionKey: string;
|
|
366
|
+
withSpan: WithSpanFn;
|
|
367
|
+
});
|
|
368
|
+
/**
|
|
369
|
+
* Drop-in replacement for the OpenAI Agents SDK's `run()` that records a
|
|
370
|
+
* replayable root `agent` span.
|
|
371
|
+
*
|
|
372
|
+
* The `input` is captured as the root span's input (as a single positional
|
|
373
|
+
* argument, so `replay(key, fn)` re-feeds it), and the run's `finalOutput`
|
|
374
|
+
* is recorded as the root output. For streaming runs (`{ stream: true }`),
|
|
375
|
+
* the result is handed back immediately and the final output is recorded
|
|
376
|
+
* once the stream completes — first-byte latency is untouched.
|
|
377
|
+
*
|
|
378
|
+
* The process-wide tracing processor (`getOpenAiTracingProcessor`) must still
|
|
379
|
+
* be registered: it captures the LLM/tool/handoff spans that nest beneath
|
|
380
|
+
* this root.
|
|
381
|
+
*/
|
|
382
|
+
wrapRun<TAgent extends Agent<any, any>, TContext = undefined>(agent: TAgent, input: RunInput<TContext, TAgent>, options?: NonStreamRunOptions<TContext>): Promise<RunResult<TContext, TAgent>>;
|
|
383
|
+
wrapRun<TAgent extends Agent<any, any>, TContext = undefined>(agent: TAgent, input: RunInput<TContext, TAgent>, options: StreamRunOptions<TContext>): Promise<StreamedRunResult<TContext, TAgent>>;
|
|
384
|
+
}
|
|
385
|
+
|
|
316
386
|
/**
|
|
317
387
|
* Per-trace environment exposed to customer code during replay.
|
|
318
388
|
*
|
|
@@ -863,6 +933,29 @@ declare class Bitfab {
|
|
|
863
933
|
* @returns A BitfabOpenAITracingProcessor instance configured for this client
|
|
864
934
|
*/
|
|
865
935
|
getOpenAiTracingProcessor(): BitfabOpenAITracingProcessor;
|
|
936
|
+
/**
|
|
937
|
+
* Get an OpenAI Agents SDK handler that records a replayable root span.
|
|
938
|
+
*
|
|
939
|
+
* The processor from {@link getOpenAiTracingProcessor} captures everything
|
|
940
|
+
* inside a run (LLM calls, tools, handoffs) but never sees the caller's
|
|
941
|
+
* input, so a processor-only run records an empty-input root and is not
|
|
942
|
+
* replayable. This handler's `wrapRun` is a drop-in for `run()` that opens a
|
|
943
|
+
* `withSpan` root carrying the input and final output; the processor's spans
|
|
944
|
+
* nest beneath it. Register the processor once at startup, then call
|
|
945
|
+
* `handler.wrapRun(agent, input)` in place of `run(agent, input)`.
|
|
946
|
+
*
|
|
947
|
+
* ```typescript
|
|
948
|
+
* import { addTraceProcessor, Agent, run } from "@openai/agents";
|
|
949
|
+
*
|
|
950
|
+
* addTraceProcessor(client.getOpenAiTracingProcessor());
|
|
951
|
+
* const handler = client.getOpenAiAgentHandler("research-topic");
|
|
952
|
+
* const result = await handler.wrapRun(agent, "Find X");
|
|
953
|
+
* ```
|
|
954
|
+
*
|
|
955
|
+
* @param traceFunctionKey - Groups traces under this key in Bitfab
|
|
956
|
+
* @returns A BitfabOpenAIAgentHandler configured for this client
|
|
957
|
+
*/
|
|
958
|
+
getOpenAiAgentHandler(traceFunctionKey: string): BitfabOpenAIAgentHandler;
|
|
866
959
|
/**
|
|
867
960
|
* Get a LangGraph/LangChain callback handler for tracing.
|
|
868
961
|
*
|
|
@@ -1117,7 +1210,7 @@ declare class BitfabFunction {
|
|
|
1117
1210
|
/**
|
|
1118
1211
|
* SDK version from package.json (injected at build time)
|
|
1119
1212
|
*/
|
|
1120
|
-
declare const __version__ = "0.
|
|
1213
|
+
declare const __version__ = "0.23.0";
|
|
1121
1214
|
|
|
1122
1215
|
/**
|
|
1123
1216
|
* Constants for the Bitfab SDK.
|
|
@@ -1185,4 +1278,4 @@ declare const finalizers: {
|
|
|
1185
1278
|
readableStream: typeof readableStream;
|
|
1186
1279
|
};
|
|
1187
1280
|
|
|
1188
|
-
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace };
|
|
1281
|
+
export { type ActiveSpanContext, type AdaptContext, type AdaptInputsFn, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler, BitfabLangGraphCallbackHandler, BitfabOpenAIAgentHandler, BitfabOpenAITracingProcessor, type CodeChangeFile, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type DbSnapshotConfig, type DbSnapshotProvider, type DbSnapshotRef, type DetachedTrace, type MockStrategy, type ProviderDefinition, ReplayEnvironment, type ReplayEnvironmentSnapshot, type ReplayItem, type ReplayOptions, type ReplayResult, SUPPORTED_PROVIDERS, type SpanOptions, type SpanType, type TokenUsage, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, finalizers, flushTraces, getCurrentSpan, getCurrentTrace };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
BitfabClaudeAgentHandler,
|
|
4
4
|
BitfabFunction,
|
|
5
5
|
BitfabLangGraphCallbackHandler,
|
|
6
|
+
BitfabOpenAIAgentHandler,
|
|
6
7
|
BitfabOpenAITracingProcessor,
|
|
7
8
|
DEFAULT_SERVICE_URL,
|
|
8
9
|
ReplayEnvironment,
|
|
@@ -12,7 +13,7 @@ import {
|
|
|
12
13
|
flushTraces,
|
|
13
14
|
getCurrentSpan,
|
|
14
15
|
getCurrentTrace
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-QOPP5TSO.js";
|
|
16
17
|
import {
|
|
17
18
|
BitfabError
|
|
18
19
|
} from "./chunk-EQI6ZJC3.js";
|
|
@@ -23,6 +24,7 @@ export {
|
|
|
23
24
|
BitfabFunction,
|
|
24
25
|
BitfabLangGraphCallbackHandler as BitfabLangChainCallbackHandler,
|
|
25
26
|
BitfabLangGraphCallbackHandler,
|
|
27
|
+
BitfabOpenAIAgentHandler,
|
|
26
28
|
BitfabOpenAITracingProcessor,
|
|
27
29
|
DEFAULT_SERVICE_URL,
|
|
28
30
|
ReplayEnvironment,
|
package/dist/node.cjs
CHANGED
|
@@ -484,6 +484,7 @@ __export(node_exports, {
|
|
|
484
484
|
BitfabFunction: () => BitfabFunction,
|
|
485
485
|
BitfabLangChainCallbackHandler: () => BitfabLangGraphCallbackHandler,
|
|
486
486
|
BitfabLangGraphCallbackHandler: () => BitfabLangGraphCallbackHandler,
|
|
487
|
+
BitfabOpenAIAgentHandler: () => BitfabOpenAIAgentHandler,
|
|
487
488
|
BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
|
|
488
489
|
DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
|
|
489
490
|
ReplayEnvironment: () => ReplayEnvironment,
|
|
@@ -504,7 +505,7 @@ registerAsyncLocalStorageClass(
|
|
|
504
505
|
);
|
|
505
506
|
|
|
506
507
|
// src/version.generated.ts
|
|
507
|
-
var __version__ = "0.
|
|
508
|
+
var __version__ = "0.23.0";
|
|
508
509
|
|
|
509
510
|
// src/constants.ts
|
|
510
511
|
var DEFAULT_SERVICE_URL = "https://bitfab.ai";
|
|
@@ -1955,8 +1956,9 @@ function extractLangGraphMetadata(metadata) {
|
|
|
1955
1956
|
var BitfabLangGraphCallbackHandler = class {
|
|
1956
1957
|
constructor(config) {
|
|
1957
1958
|
this.name = "BitfabLangGraphCallbackHandler";
|
|
1958
|
-
this.ignoreRetriever = true;
|
|
1959
1959
|
this.ignoreRetry = true;
|
|
1960
|
+
// Retriever callbacks ARE captured (retriever queries -> function spans).
|
|
1961
|
+
this.ignoreRetriever = false;
|
|
1960
1962
|
this.ignoreCustomEvent = true;
|
|
1961
1963
|
this.runToSpan = /* @__PURE__ */ new Map();
|
|
1962
1964
|
this.invocations = /* @__PURE__ */ new Map();
|
|
@@ -2286,6 +2288,39 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
2286
2288
|
}
|
|
2287
2289
|
};
|
|
2288
2290
|
|
|
2291
|
+
// src/openaiAgentSdk.ts
|
|
2292
|
+
var BitfabOpenAIAgentHandler = class {
|
|
2293
|
+
constructor(config) {
|
|
2294
|
+
this.traceFunctionKey = config.traceFunctionKey;
|
|
2295
|
+
this.withSpanFn = config.withSpan;
|
|
2296
|
+
}
|
|
2297
|
+
async wrapRun(agent, input, options) {
|
|
2298
|
+
const { run } = await import("@openai/agents");
|
|
2299
|
+
const isStreaming = options?.stream === true;
|
|
2300
|
+
const finalize = async (result) => {
|
|
2301
|
+
const res = result;
|
|
2302
|
+
if (isStreaming && res?.completed) {
|
|
2303
|
+
try {
|
|
2304
|
+
await res.completed;
|
|
2305
|
+
} catch {
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
return res?.finalOutput;
|
|
2309
|
+
};
|
|
2310
|
+
const options_ = { type: "agent", finalize };
|
|
2311
|
+
const traced = this.withSpanFn(
|
|
2312
|
+
this.traceFunctionKey,
|
|
2313
|
+
options_,
|
|
2314
|
+
(agentInput) => run(
|
|
2315
|
+
agent,
|
|
2316
|
+
agentInput,
|
|
2317
|
+
options
|
|
2318
|
+
)
|
|
2319
|
+
);
|
|
2320
|
+
return traced(input);
|
|
2321
|
+
}
|
|
2322
|
+
};
|
|
2323
|
+
|
|
2289
2324
|
// src/client.ts
|
|
2290
2325
|
init_replayContext();
|
|
2291
2326
|
|
|
@@ -2979,6 +3014,34 @@ var Bitfab = class {
|
|
|
2979
3014
|
}
|
|
2980
3015
|
});
|
|
2981
3016
|
}
|
|
3017
|
+
/**
|
|
3018
|
+
* Get an OpenAI Agents SDK handler that records a replayable root span.
|
|
3019
|
+
*
|
|
3020
|
+
* The processor from {@link getOpenAiTracingProcessor} captures everything
|
|
3021
|
+
* inside a run (LLM calls, tools, handoffs) but never sees the caller's
|
|
3022
|
+
* input, so a processor-only run records an empty-input root and is not
|
|
3023
|
+
* replayable. This handler's `wrapRun` is a drop-in for `run()` that opens a
|
|
3024
|
+
* `withSpan` root carrying the input and final output; the processor's spans
|
|
3025
|
+
* nest beneath it. Register the processor once at startup, then call
|
|
3026
|
+
* `handler.wrapRun(agent, input)` in place of `run(agent, input)`.
|
|
3027
|
+
*
|
|
3028
|
+
* ```typescript
|
|
3029
|
+
* import { addTraceProcessor, Agent, run } from "@openai/agents";
|
|
3030
|
+
*
|
|
3031
|
+
* addTraceProcessor(client.getOpenAiTracingProcessor());
|
|
3032
|
+
* const handler = client.getOpenAiAgentHandler("research-topic");
|
|
3033
|
+
* const result = await handler.wrapRun(agent, "Find X");
|
|
3034
|
+
* ```
|
|
3035
|
+
*
|
|
3036
|
+
* @param traceFunctionKey - Groups traces under this key in Bitfab
|
|
3037
|
+
* @returns A BitfabOpenAIAgentHandler configured for this client
|
|
3038
|
+
*/
|
|
3039
|
+
getOpenAiAgentHandler(traceFunctionKey) {
|
|
3040
|
+
return new BitfabOpenAIAgentHandler({
|
|
3041
|
+
traceFunctionKey,
|
|
3042
|
+
withSpan: this.withSpan.bind(this)
|
|
3043
|
+
});
|
|
3044
|
+
}
|
|
2982
3045
|
/**
|
|
2983
3046
|
* Get a LangGraph/LangChain callback handler for tracing.
|
|
2984
3047
|
*
|
|
@@ -3733,6 +3796,7 @@ assertAsyncStorageRegistered();
|
|
|
3733
3796
|
BitfabFunction,
|
|
3734
3797
|
BitfabLangChainCallbackHandler,
|
|
3735
3798
|
BitfabLangGraphCallbackHandler,
|
|
3799
|
+
BitfabOpenAIAgentHandler,
|
|
3736
3800
|
BitfabOpenAITracingProcessor,
|
|
3737
3801
|
DEFAULT_SERVICE_URL,
|
|
3738
3802
|
ReplayEnvironment,
|