bitfab 0.9.2 → 0.11.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/README.md +10 -10
- package/dist/{chunk-WUJR72QY.js → chunk-6EZCV5TU.js} +1014 -3
- package/dist/chunk-6EZCV5TU.js.map +1 -0
- package/dist/{chunk-VGALEXKQ.js → chunk-C4KRLEXZ.js} +47 -47
- package/dist/chunk-C4KRLEXZ.js.map +1 -0
- package/dist/index.cjs +1059 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +221 -3
- package/dist/index.d.ts +221 -3
- package/dist/index.js +6 -2
- package/dist/node.cjs +1020 -1
- 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 +6 -2
- package/dist/node.js.map +1 -1
- package/dist/{replay-DJ2HXTHQ.js → replay-PIWVDXIF.js} +2 -2
- package/package.json +3 -3
- package/dist/chunk-VGALEXKQ.js.map +0 -1
- package/dist/chunk-WUJR72QY.js.map +0 -1
- /package/dist/{replay-DJ2HXTHQ.js.map → replay-PIWVDXIF.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -32,6 +32,118 @@ type AllowedEnvVars = {
|
|
|
32
32
|
OPENAI_API_KEY?: string;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Claude Agent SDK handler for Bitfab tracing.
|
|
37
|
+
*
|
|
38
|
+
* Hooks into the Claude Agent SDK's lifecycle to capture LLM turns,
|
|
39
|
+
* tool invocations, and subagent execution as Bitfab spans.
|
|
40
|
+
*
|
|
41
|
+
* Uses two integration surfaces:
|
|
42
|
+
* 1. SDK hooks (PreToolUse, PostToolUse, etc.) for tool/subagent lifecycle
|
|
43
|
+
* 2. Stream wrapping for LLM turn capture from the message stream
|
|
44
|
+
*/
|
|
45
|
+
interface ActiveSpanContext$2 {
|
|
46
|
+
traceId: string;
|
|
47
|
+
spanId: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Claude Agent SDK handler that sends traces to Bitfab.
|
|
51
|
+
*
|
|
52
|
+
* Captures LLM turns, tool invocations, and subagent execution as
|
|
53
|
+
* Bitfab spans with proper parent-child hierarchy.
|
|
54
|
+
*
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { Bitfab } from "bitfab";
|
|
57
|
+
* import { ClaudeSDKClient } from "@anthropic-ai/claude-agent-sdk";
|
|
58
|
+
*
|
|
59
|
+
* const bitfab = new Bitfab({ apiKey: "..." });
|
|
60
|
+
* const handler = bitfab.getClaudeAgentHandler("my-agent");
|
|
61
|
+
*
|
|
62
|
+
* const options = handler.instrumentOptions({
|
|
63
|
+
* model: "claude-sonnet-4-5-...",
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* const client = new ClaudeSDKClient(options);
|
|
67
|
+
* await client.connect();
|
|
68
|
+
* await client.query("Do something");
|
|
69
|
+
*
|
|
70
|
+
* for await (const message of handler.wrapResponse(client.receiveResponse())) {
|
|
71
|
+
* // process messages normally
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare class BitfabClaudeAgentHandler {
|
|
76
|
+
private readonly httpClient;
|
|
77
|
+
private readonly traceFunctionKey;
|
|
78
|
+
private readonly getActiveSpanContext;
|
|
79
|
+
private runToSpan;
|
|
80
|
+
private traceId;
|
|
81
|
+
private rootSpanId;
|
|
82
|
+
private activeContext;
|
|
83
|
+
private traceStartedAt;
|
|
84
|
+
private conversationHistory;
|
|
85
|
+
private pendingMessages;
|
|
86
|
+
private currentLlmSpanId;
|
|
87
|
+
private currentLlmMessageId;
|
|
88
|
+
private currentLlmContent;
|
|
89
|
+
private currentLlmModel;
|
|
90
|
+
private currentLlmUsage;
|
|
91
|
+
private currentLlmStartedAt;
|
|
92
|
+
private currentLlmHistorySnapshot;
|
|
93
|
+
private activeSubagentSpans;
|
|
94
|
+
constructor(config: {
|
|
95
|
+
apiKey?: string;
|
|
96
|
+
traceFunctionKey: string;
|
|
97
|
+
serviceUrl?: string;
|
|
98
|
+
timeout?: number;
|
|
99
|
+
getActiveSpanContext?: () => ActiveSpanContext$2 | null;
|
|
100
|
+
});
|
|
101
|
+
private ensureTrace;
|
|
102
|
+
private getParentId;
|
|
103
|
+
private startSpan;
|
|
104
|
+
private completeSpan;
|
|
105
|
+
private sendSpan;
|
|
106
|
+
private sendTraceCompletion;
|
|
107
|
+
private preToolUseHook;
|
|
108
|
+
private postToolUseHook;
|
|
109
|
+
private postToolUseFailureHook;
|
|
110
|
+
private subagentStartHook;
|
|
111
|
+
private subagentStopHook;
|
|
112
|
+
/**
|
|
113
|
+
* Inject Bitfab tracing hooks into Claude Agent SDK options.
|
|
114
|
+
*
|
|
115
|
+
* Modifies the options object and returns it for convenience.
|
|
116
|
+
* The SDK's `HookMatcher` is constructed as a plain object
|
|
117
|
+
* (`{ matcher: null, hooks: [callback] }`) to avoid requiring
|
|
118
|
+
* `@anthropic-ai/claude-agent-sdk` as a dependency.
|
|
119
|
+
*
|
|
120
|
+
* @param options - Options object with a `hooks` property
|
|
121
|
+
* @returns The modified options object with Bitfab hooks injected
|
|
122
|
+
*/
|
|
123
|
+
instrumentOptions<T extends Record<string, unknown>>(options: T): T;
|
|
124
|
+
/**
|
|
125
|
+
* Wrap a `ClaudeSDKClient.receiveResponse()` stream to capture LLM turns.
|
|
126
|
+
*
|
|
127
|
+
* Yields every message unchanged while capturing AssistantMessage
|
|
128
|
+
* content as LLM turn spans.
|
|
129
|
+
*/
|
|
130
|
+
wrapResponse(stream: AsyncIterable<unknown>): AsyncIterable<unknown>;
|
|
131
|
+
/**
|
|
132
|
+
* Wrap a `query()` async iterator to capture LLM turns.
|
|
133
|
+
*
|
|
134
|
+
* Same as `wrapResponse` but for the simpler `query()` API
|
|
135
|
+
* which does not support hooks (no tool/subagent spans).
|
|
136
|
+
*/
|
|
137
|
+
wrapQuery(stream: AsyncIterable<unknown>): AsyncIterable<unknown>;
|
|
138
|
+
private processStream;
|
|
139
|
+
private processMessage;
|
|
140
|
+
private handleAssistantMessage;
|
|
141
|
+
private handleUserMessage;
|
|
142
|
+
private handleResultMessage;
|
|
143
|
+
private flushLlmTurn;
|
|
144
|
+
private resetState;
|
|
145
|
+
}
|
|
146
|
+
|
|
35
147
|
/**
|
|
36
148
|
* HTTP client utilities for Bitfab API requests.
|
|
37
149
|
*
|
|
@@ -54,6 +166,71 @@ declare class BitfabError extends Error {
|
|
|
54
166
|
*/
|
|
55
167
|
declare function flushTraces(timeoutMs?: number): Promise<void>;
|
|
56
168
|
|
|
169
|
+
/**
|
|
170
|
+
* LangGraph/LangChain callback handler for Bitfab tracing.
|
|
171
|
+
*
|
|
172
|
+
* Hooks into LangGraph's callback system to capture graph node execution,
|
|
173
|
+
* LLM calls, and tool invocations as Bitfab spans — without requiring users
|
|
174
|
+
* to wrap their functions with withSpan (which fails on non-serializable args).
|
|
175
|
+
*
|
|
176
|
+
* Duck-typed to match LangChain.js's BaseCallbackHandler interface.
|
|
177
|
+
* No @langchain/core dependency required.
|
|
178
|
+
*/
|
|
179
|
+
interface ActiveSpanContext$1 {
|
|
180
|
+
traceId: string;
|
|
181
|
+
spanId: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* LangChain/LangGraph callback handler that sends traces to Bitfab.
|
|
185
|
+
*
|
|
186
|
+
* Duck-typed to match LangChain.js's BaseCallbackHandler — no
|
|
187
|
+
* `@langchain/core` dependency required. Pass as a callback:
|
|
188
|
+
*
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const handler = bitfab.getLangGraphCallbackHandler("my-agent");
|
|
191
|
+
* const result = await agent.invoke(
|
|
192
|
+
* { messages: [...] },
|
|
193
|
+
* { callbacks: [handler] },
|
|
194
|
+
* );
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
declare class BitfabLangGraphCallbackHandler {
|
|
198
|
+
name: string;
|
|
199
|
+
ignoreRetriever: boolean;
|
|
200
|
+
ignoreRetry: boolean;
|
|
201
|
+
ignoreCustomEvent: boolean;
|
|
202
|
+
private readonly httpClient;
|
|
203
|
+
private readonly traceFunctionKey;
|
|
204
|
+
private readonly getActiveSpanContext;
|
|
205
|
+
private runToSpan;
|
|
206
|
+
private invocations;
|
|
207
|
+
constructor(config: {
|
|
208
|
+
apiKey?: string;
|
|
209
|
+
traceFunctionKey: string;
|
|
210
|
+
serviceUrl?: string;
|
|
211
|
+
timeout?: number;
|
|
212
|
+
getActiveSpanContext?: () => ActiveSpanContext$1 | null;
|
|
213
|
+
});
|
|
214
|
+
private startSpan;
|
|
215
|
+
private completeSpan;
|
|
216
|
+
private sendSpan;
|
|
217
|
+
private sendTraceCompletion;
|
|
218
|
+
handleChainStart(chain: Record<string, unknown>, inputs: Record<string, unknown>, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
219
|
+
handleChainEnd(outputs: Record<string, unknown>, runId: string): Promise<void>;
|
|
220
|
+
handleChainError(error: unknown, runId: string): Promise<void>;
|
|
221
|
+
handleChatModelStart(llm: Record<string, unknown>, messages: unknown[][], runId: string, parentRunId?: string, _extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
222
|
+
handleLLMStart(llm: Record<string, unknown>, prompts: string[], runId: string, parentRunId?: string, _extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
223
|
+
handleLLMEnd(output: Record<string, unknown>, runId: string): Promise<void>;
|
|
224
|
+
handleLLMError(error: unknown, runId: string): Promise<void>;
|
|
225
|
+
handleLLMNewToken(): Promise<void>;
|
|
226
|
+
handleToolStart(tool: Record<string, unknown>, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
227
|
+
handleToolEnd(output: unknown, runId: string): Promise<void>;
|
|
228
|
+
handleToolError(error: unknown, runId: string): Promise<void>;
|
|
229
|
+
handleRetrieverStart(retriever: Record<string, unknown>, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
230
|
+
handleRetrieverEnd(documents: unknown, runId: string): Promise<void>;
|
|
231
|
+
handleRetrieverError(error: unknown, runId: string): Promise<void>;
|
|
232
|
+
}
|
|
233
|
+
|
|
57
234
|
/**
|
|
58
235
|
* Tracing utilities for external trace submission to Bitfab.
|
|
59
236
|
*
|
|
@@ -89,7 +266,7 @@ interface TracingProcessor {
|
|
|
89
266
|
*
|
|
90
267
|
* Example usage:
|
|
91
268
|
* ```typescript
|
|
92
|
-
* import { Bitfab } from '
|
|
269
|
+
* import { Bitfab } from 'bitfab';
|
|
93
270
|
* import { addTraceProcessor } from '@openai/agents';
|
|
94
271
|
*
|
|
95
272
|
* const client = new Bitfab({ apiKey: 'your-api-key' });
|
|
@@ -337,6 +514,47 @@ declare class Bitfab {
|
|
|
337
514
|
* @returns A BitfabOpenAITracingProcessor instance configured for this client
|
|
338
515
|
*/
|
|
339
516
|
getOpenAiTracingProcessor(): BitfabOpenAITracingProcessor;
|
|
517
|
+
/**
|
|
518
|
+
* Get a LangGraph/LangChain callback handler for tracing.
|
|
519
|
+
*
|
|
520
|
+
* The handler captures graph node execution, LLM calls, and tool
|
|
521
|
+
* invocations as Bitfab spans with proper parent-child hierarchy.
|
|
522
|
+
*
|
|
523
|
+
* ```typescript
|
|
524
|
+
* const handler = client.getLangGraphCallbackHandler("my-agent");
|
|
525
|
+
* const result = await agent.invoke(
|
|
526
|
+
* { messages: [...] },
|
|
527
|
+
* { callbacks: [handler] },
|
|
528
|
+
* );
|
|
529
|
+
* ```
|
|
530
|
+
*
|
|
531
|
+
* @param traceFunctionKey - Groups traces under this key in Bitfab
|
|
532
|
+
* @returns A BitfabLangGraphCallbackHandler configured for this client
|
|
533
|
+
*/
|
|
534
|
+
getLangGraphCallbackHandler(traceFunctionKey: string): BitfabLangGraphCallbackHandler;
|
|
535
|
+
/**
|
|
536
|
+
* Get a Claude Agent SDK handler for tracing.
|
|
537
|
+
*
|
|
538
|
+
* The handler captures LLM turns, tool invocations, and subagent
|
|
539
|
+
* execution as Bitfab spans with proper parent-child hierarchy.
|
|
540
|
+
*
|
|
541
|
+
* ```typescript
|
|
542
|
+
* const handler = client.getClaudeAgentHandler("my-agent");
|
|
543
|
+
* const options = handler.instrumentOptions({
|
|
544
|
+
* model: "claude-sonnet-4-5-...",
|
|
545
|
+
* });
|
|
546
|
+
* const sdkClient = new ClaudeSDKClient(options);
|
|
547
|
+
* await sdkClient.connect();
|
|
548
|
+
* await sdkClient.query("Do something");
|
|
549
|
+
* for await (const msg of handler.wrapResponse(sdkClient.receiveResponse())) {
|
|
550
|
+
* // process messages
|
|
551
|
+
* }
|
|
552
|
+
* ```
|
|
553
|
+
*
|
|
554
|
+
* @param traceFunctionKey - Groups traces under this key in Bitfab
|
|
555
|
+
* @returns A BitfabClaudeAgentHandler configured for this client
|
|
556
|
+
*/
|
|
557
|
+
getClaudeAgentHandler(traceFunctionKey: string): BitfabClaudeAgentHandler;
|
|
340
558
|
/**
|
|
341
559
|
* Wrap a BAML client method to automatically capture prompt and LLM metadata.
|
|
342
560
|
*
|
|
@@ -519,7 +737,7 @@ declare class BitfabFunction {
|
|
|
519
737
|
/**
|
|
520
738
|
* SDK version from package.json (injected at build time)
|
|
521
739
|
*/
|
|
522
|
-
declare const __version__ = "0.
|
|
740
|
+
declare const __version__ = "0.11.0";
|
|
523
741
|
|
|
524
742
|
/**
|
|
525
743
|
* Constants for the Bitfab SDK.
|
|
@@ -565,4 +783,4 @@ interface ReplayResult<T> {
|
|
|
565
783
|
testRunUrl: string;
|
|
566
784
|
}
|
|
567
785
|
|
|
568
|
-
export { type ActiveSpanContext, type AllowedEnvVars, type BamlExecutionResult, Bitfab, type BitfabConfig, BitfabError, BitfabFunction, BitfabOpenAITracingProcessor, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type ProviderDefinition, type ReplayItem, type ReplayOptions, type ReplayResult, type SpanOptions, type SpanType, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace };
|
|
786
|
+
export { type ActiveSpanContext, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type ProviderDefinition, type ReplayItem, type ReplayOptions, type ReplayResult, type SpanOptions, type SpanType, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace };
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,118 @@ type AllowedEnvVars = {
|
|
|
32
32
|
OPENAI_API_KEY?: string;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Claude Agent SDK handler for Bitfab tracing.
|
|
37
|
+
*
|
|
38
|
+
* Hooks into the Claude Agent SDK's lifecycle to capture LLM turns,
|
|
39
|
+
* tool invocations, and subagent execution as Bitfab spans.
|
|
40
|
+
*
|
|
41
|
+
* Uses two integration surfaces:
|
|
42
|
+
* 1. SDK hooks (PreToolUse, PostToolUse, etc.) for tool/subagent lifecycle
|
|
43
|
+
* 2. Stream wrapping for LLM turn capture from the message stream
|
|
44
|
+
*/
|
|
45
|
+
interface ActiveSpanContext$2 {
|
|
46
|
+
traceId: string;
|
|
47
|
+
spanId: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Claude Agent SDK handler that sends traces to Bitfab.
|
|
51
|
+
*
|
|
52
|
+
* Captures LLM turns, tool invocations, and subagent execution as
|
|
53
|
+
* Bitfab spans with proper parent-child hierarchy.
|
|
54
|
+
*
|
|
55
|
+
* ```typescript
|
|
56
|
+
* import { Bitfab } from "bitfab";
|
|
57
|
+
* import { ClaudeSDKClient } from "@anthropic-ai/claude-agent-sdk";
|
|
58
|
+
*
|
|
59
|
+
* const bitfab = new Bitfab({ apiKey: "..." });
|
|
60
|
+
* const handler = bitfab.getClaudeAgentHandler("my-agent");
|
|
61
|
+
*
|
|
62
|
+
* const options = handler.instrumentOptions({
|
|
63
|
+
* model: "claude-sonnet-4-5-...",
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* const client = new ClaudeSDKClient(options);
|
|
67
|
+
* await client.connect();
|
|
68
|
+
* await client.query("Do something");
|
|
69
|
+
*
|
|
70
|
+
* for await (const message of handler.wrapResponse(client.receiveResponse())) {
|
|
71
|
+
* // process messages normally
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare class BitfabClaudeAgentHandler {
|
|
76
|
+
private readonly httpClient;
|
|
77
|
+
private readonly traceFunctionKey;
|
|
78
|
+
private readonly getActiveSpanContext;
|
|
79
|
+
private runToSpan;
|
|
80
|
+
private traceId;
|
|
81
|
+
private rootSpanId;
|
|
82
|
+
private activeContext;
|
|
83
|
+
private traceStartedAt;
|
|
84
|
+
private conversationHistory;
|
|
85
|
+
private pendingMessages;
|
|
86
|
+
private currentLlmSpanId;
|
|
87
|
+
private currentLlmMessageId;
|
|
88
|
+
private currentLlmContent;
|
|
89
|
+
private currentLlmModel;
|
|
90
|
+
private currentLlmUsage;
|
|
91
|
+
private currentLlmStartedAt;
|
|
92
|
+
private currentLlmHistorySnapshot;
|
|
93
|
+
private activeSubagentSpans;
|
|
94
|
+
constructor(config: {
|
|
95
|
+
apiKey?: string;
|
|
96
|
+
traceFunctionKey: string;
|
|
97
|
+
serviceUrl?: string;
|
|
98
|
+
timeout?: number;
|
|
99
|
+
getActiveSpanContext?: () => ActiveSpanContext$2 | null;
|
|
100
|
+
});
|
|
101
|
+
private ensureTrace;
|
|
102
|
+
private getParentId;
|
|
103
|
+
private startSpan;
|
|
104
|
+
private completeSpan;
|
|
105
|
+
private sendSpan;
|
|
106
|
+
private sendTraceCompletion;
|
|
107
|
+
private preToolUseHook;
|
|
108
|
+
private postToolUseHook;
|
|
109
|
+
private postToolUseFailureHook;
|
|
110
|
+
private subagentStartHook;
|
|
111
|
+
private subagentStopHook;
|
|
112
|
+
/**
|
|
113
|
+
* Inject Bitfab tracing hooks into Claude Agent SDK options.
|
|
114
|
+
*
|
|
115
|
+
* Modifies the options object and returns it for convenience.
|
|
116
|
+
* The SDK's `HookMatcher` is constructed as a plain object
|
|
117
|
+
* (`{ matcher: null, hooks: [callback] }`) to avoid requiring
|
|
118
|
+
* `@anthropic-ai/claude-agent-sdk` as a dependency.
|
|
119
|
+
*
|
|
120
|
+
* @param options - Options object with a `hooks` property
|
|
121
|
+
* @returns The modified options object with Bitfab hooks injected
|
|
122
|
+
*/
|
|
123
|
+
instrumentOptions<T extends Record<string, unknown>>(options: T): T;
|
|
124
|
+
/**
|
|
125
|
+
* Wrap a `ClaudeSDKClient.receiveResponse()` stream to capture LLM turns.
|
|
126
|
+
*
|
|
127
|
+
* Yields every message unchanged while capturing AssistantMessage
|
|
128
|
+
* content as LLM turn spans.
|
|
129
|
+
*/
|
|
130
|
+
wrapResponse(stream: AsyncIterable<unknown>): AsyncIterable<unknown>;
|
|
131
|
+
/**
|
|
132
|
+
* Wrap a `query()` async iterator to capture LLM turns.
|
|
133
|
+
*
|
|
134
|
+
* Same as `wrapResponse` but for the simpler `query()` API
|
|
135
|
+
* which does not support hooks (no tool/subagent spans).
|
|
136
|
+
*/
|
|
137
|
+
wrapQuery(stream: AsyncIterable<unknown>): AsyncIterable<unknown>;
|
|
138
|
+
private processStream;
|
|
139
|
+
private processMessage;
|
|
140
|
+
private handleAssistantMessage;
|
|
141
|
+
private handleUserMessage;
|
|
142
|
+
private handleResultMessage;
|
|
143
|
+
private flushLlmTurn;
|
|
144
|
+
private resetState;
|
|
145
|
+
}
|
|
146
|
+
|
|
35
147
|
/**
|
|
36
148
|
* HTTP client utilities for Bitfab API requests.
|
|
37
149
|
*
|
|
@@ -54,6 +166,71 @@ declare class BitfabError extends Error {
|
|
|
54
166
|
*/
|
|
55
167
|
declare function flushTraces(timeoutMs?: number): Promise<void>;
|
|
56
168
|
|
|
169
|
+
/**
|
|
170
|
+
* LangGraph/LangChain callback handler for Bitfab tracing.
|
|
171
|
+
*
|
|
172
|
+
* Hooks into LangGraph's callback system to capture graph node execution,
|
|
173
|
+
* LLM calls, and tool invocations as Bitfab spans — without requiring users
|
|
174
|
+
* to wrap their functions with withSpan (which fails on non-serializable args).
|
|
175
|
+
*
|
|
176
|
+
* Duck-typed to match LangChain.js's BaseCallbackHandler interface.
|
|
177
|
+
* No @langchain/core dependency required.
|
|
178
|
+
*/
|
|
179
|
+
interface ActiveSpanContext$1 {
|
|
180
|
+
traceId: string;
|
|
181
|
+
spanId: string;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* LangChain/LangGraph callback handler that sends traces to Bitfab.
|
|
185
|
+
*
|
|
186
|
+
* Duck-typed to match LangChain.js's BaseCallbackHandler — no
|
|
187
|
+
* `@langchain/core` dependency required. Pass as a callback:
|
|
188
|
+
*
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const handler = bitfab.getLangGraphCallbackHandler("my-agent");
|
|
191
|
+
* const result = await agent.invoke(
|
|
192
|
+
* { messages: [...] },
|
|
193
|
+
* { callbacks: [handler] },
|
|
194
|
+
* );
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
declare class BitfabLangGraphCallbackHandler {
|
|
198
|
+
name: string;
|
|
199
|
+
ignoreRetriever: boolean;
|
|
200
|
+
ignoreRetry: boolean;
|
|
201
|
+
ignoreCustomEvent: boolean;
|
|
202
|
+
private readonly httpClient;
|
|
203
|
+
private readonly traceFunctionKey;
|
|
204
|
+
private readonly getActiveSpanContext;
|
|
205
|
+
private runToSpan;
|
|
206
|
+
private invocations;
|
|
207
|
+
constructor(config: {
|
|
208
|
+
apiKey?: string;
|
|
209
|
+
traceFunctionKey: string;
|
|
210
|
+
serviceUrl?: string;
|
|
211
|
+
timeout?: number;
|
|
212
|
+
getActiveSpanContext?: () => ActiveSpanContext$1 | null;
|
|
213
|
+
});
|
|
214
|
+
private startSpan;
|
|
215
|
+
private completeSpan;
|
|
216
|
+
private sendSpan;
|
|
217
|
+
private sendTraceCompletion;
|
|
218
|
+
handleChainStart(chain: Record<string, unknown>, inputs: Record<string, unknown>, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
219
|
+
handleChainEnd(outputs: Record<string, unknown>, runId: string): Promise<void>;
|
|
220
|
+
handleChainError(error: unknown, runId: string): Promise<void>;
|
|
221
|
+
handleChatModelStart(llm: Record<string, unknown>, messages: unknown[][], runId: string, parentRunId?: string, _extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
222
|
+
handleLLMStart(llm: Record<string, unknown>, prompts: string[], runId: string, parentRunId?: string, _extraParams?: Record<string, unknown>, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
223
|
+
handleLLMEnd(output: Record<string, unknown>, runId: string): Promise<void>;
|
|
224
|
+
handleLLMError(error: unknown, runId: string): Promise<void>;
|
|
225
|
+
handleLLMNewToken(): Promise<void>;
|
|
226
|
+
handleToolStart(tool: Record<string, unknown>, input: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
227
|
+
handleToolEnd(output: unknown, runId: string): Promise<void>;
|
|
228
|
+
handleToolError(error: unknown, runId: string): Promise<void>;
|
|
229
|
+
handleRetrieverStart(retriever: Record<string, unknown>, query: string, runId: string, parentRunId?: string, tags?: string[], metadata?: Record<string, unknown>): Promise<void>;
|
|
230
|
+
handleRetrieverEnd(documents: unknown, runId: string): Promise<void>;
|
|
231
|
+
handleRetrieverError(error: unknown, runId: string): Promise<void>;
|
|
232
|
+
}
|
|
233
|
+
|
|
57
234
|
/**
|
|
58
235
|
* Tracing utilities for external trace submission to Bitfab.
|
|
59
236
|
*
|
|
@@ -89,7 +266,7 @@ interface TracingProcessor {
|
|
|
89
266
|
*
|
|
90
267
|
* Example usage:
|
|
91
268
|
* ```typescript
|
|
92
|
-
* import { Bitfab } from '
|
|
269
|
+
* import { Bitfab } from 'bitfab';
|
|
93
270
|
* import { addTraceProcessor } from '@openai/agents';
|
|
94
271
|
*
|
|
95
272
|
* const client = new Bitfab({ apiKey: 'your-api-key' });
|
|
@@ -337,6 +514,47 @@ declare class Bitfab {
|
|
|
337
514
|
* @returns A BitfabOpenAITracingProcessor instance configured for this client
|
|
338
515
|
*/
|
|
339
516
|
getOpenAiTracingProcessor(): BitfabOpenAITracingProcessor;
|
|
517
|
+
/**
|
|
518
|
+
* Get a LangGraph/LangChain callback handler for tracing.
|
|
519
|
+
*
|
|
520
|
+
* The handler captures graph node execution, LLM calls, and tool
|
|
521
|
+
* invocations as Bitfab spans with proper parent-child hierarchy.
|
|
522
|
+
*
|
|
523
|
+
* ```typescript
|
|
524
|
+
* const handler = client.getLangGraphCallbackHandler("my-agent");
|
|
525
|
+
* const result = await agent.invoke(
|
|
526
|
+
* { messages: [...] },
|
|
527
|
+
* { callbacks: [handler] },
|
|
528
|
+
* );
|
|
529
|
+
* ```
|
|
530
|
+
*
|
|
531
|
+
* @param traceFunctionKey - Groups traces under this key in Bitfab
|
|
532
|
+
* @returns A BitfabLangGraphCallbackHandler configured for this client
|
|
533
|
+
*/
|
|
534
|
+
getLangGraphCallbackHandler(traceFunctionKey: string): BitfabLangGraphCallbackHandler;
|
|
535
|
+
/**
|
|
536
|
+
* Get a Claude Agent SDK handler for tracing.
|
|
537
|
+
*
|
|
538
|
+
* The handler captures LLM turns, tool invocations, and subagent
|
|
539
|
+
* execution as Bitfab spans with proper parent-child hierarchy.
|
|
540
|
+
*
|
|
541
|
+
* ```typescript
|
|
542
|
+
* const handler = client.getClaudeAgentHandler("my-agent");
|
|
543
|
+
* const options = handler.instrumentOptions({
|
|
544
|
+
* model: "claude-sonnet-4-5-...",
|
|
545
|
+
* });
|
|
546
|
+
* const sdkClient = new ClaudeSDKClient(options);
|
|
547
|
+
* await sdkClient.connect();
|
|
548
|
+
* await sdkClient.query("Do something");
|
|
549
|
+
* for await (const msg of handler.wrapResponse(sdkClient.receiveResponse())) {
|
|
550
|
+
* // process messages
|
|
551
|
+
* }
|
|
552
|
+
* ```
|
|
553
|
+
*
|
|
554
|
+
* @param traceFunctionKey - Groups traces under this key in Bitfab
|
|
555
|
+
* @returns A BitfabClaudeAgentHandler configured for this client
|
|
556
|
+
*/
|
|
557
|
+
getClaudeAgentHandler(traceFunctionKey: string): BitfabClaudeAgentHandler;
|
|
340
558
|
/**
|
|
341
559
|
* Wrap a BAML client method to automatically capture prompt and LLM metadata.
|
|
342
560
|
*
|
|
@@ -519,7 +737,7 @@ declare class BitfabFunction {
|
|
|
519
737
|
/**
|
|
520
738
|
* SDK version from package.json (injected at build time)
|
|
521
739
|
*/
|
|
522
|
-
declare const __version__ = "0.
|
|
740
|
+
declare const __version__ = "0.11.0";
|
|
523
741
|
|
|
524
742
|
/**
|
|
525
743
|
* Constants for the Bitfab SDK.
|
|
@@ -565,4 +783,4 @@ interface ReplayResult<T> {
|
|
|
565
783
|
testRunUrl: string;
|
|
566
784
|
}
|
|
567
785
|
|
|
568
|
-
export { type ActiveSpanContext, type AllowedEnvVars, type BamlExecutionResult, Bitfab, type BitfabConfig, BitfabError, BitfabFunction, BitfabOpenAITracingProcessor, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type ProviderDefinition, type ReplayItem, type ReplayOptions, type ReplayResult, type SpanOptions, type SpanType, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace };
|
|
786
|
+
export { type ActiveSpanContext, type AllowedEnvVars, type BamlExecutionResult, Bitfab, BitfabClaudeAgentHandler, type BitfabConfig, BitfabError, BitfabFunction, BitfabLangGraphCallbackHandler, BitfabOpenAITracingProcessor, type CurrentSpan, type CurrentTrace, DEFAULT_SERVICE_URL, type ProviderDefinition, type ReplayItem, type ReplayOptions, type ReplayResult, type SpanOptions, type SpanType, type TraceResponse, type TracingProcessor, type WrapBAMLOptions, type WrappedBamlFn, __version__, flushTraces, getCurrentSpan, getCurrentTrace };
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Bitfab,
|
|
3
|
+
BitfabClaudeAgentHandler,
|
|
3
4
|
BitfabFunction,
|
|
5
|
+
BitfabLangGraphCallbackHandler,
|
|
4
6
|
BitfabOpenAITracingProcessor,
|
|
5
7
|
getCurrentSpan,
|
|
6
8
|
getCurrentTrace
|
|
7
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-6EZCV5TU.js";
|
|
8
10
|
import {
|
|
9
11
|
BitfabError,
|
|
10
12
|
DEFAULT_SERVICE_URL,
|
|
11
13
|
__version__,
|
|
12
14
|
flushTraces
|
|
13
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-C4KRLEXZ.js";
|
|
14
16
|
export {
|
|
15
17
|
Bitfab,
|
|
18
|
+
BitfabClaudeAgentHandler,
|
|
16
19
|
BitfabError,
|
|
17
20
|
BitfabFunction,
|
|
21
|
+
BitfabLangGraphCallbackHandler,
|
|
18
22
|
BitfabOpenAITracingProcessor,
|
|
19
23
|
DEFAULT_SERVICE_URL,
|
|
20
24
|
__version__,
|