bitfab 0.27.2 → 0.28.1
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-DW246LVL.js → chunk-3YNAPGPA.js} +89 -27
- package/dist/chunk-3YNAPGPA.js.map +1 -0
- package/dist/{chunk-MD4XQGAF.js → chunk-FTXZWRTG.js} +10 -2
- package/dist/chunk-FTXZWRTG.js.map +1 -0
- package/dist/index.cjs +95 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +157 -85
- package/dist/index.d.ts +157 -85
- package/dist/index.js +2 -2
- package/dist/node.cjs +95 -25
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +2 -2
- package/dist/{replay-J3YTYE7V.js → replay-HBOBYYR3.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-DW246LVL.js.map +0 -1
- package/dist/chunk-MD4XQGAF.js.map +0 -1
- /package/dist/{replay-J3YTYE7V.js.map → replay-HBOBYYR3.js.map} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -30,6 +30,91 @@ type AllowedEnvVars = {
|
|
|
30
30
|
OPENAI_API_KEY?: string;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Per-trace database snapshot ref capture.
|
|
35
|
+
*
|
|
36
|
+
* Every root span carries a `DbSnapshotRef` that pins the DB state at trace
|
|
37
|
+
* open by wall-clock timestamp. Capturing the timestamp is free (no IO) and
|
|
38
|
+
* harmless, so it happens on every trace regardless of configuration: that
|
|
39
|
+
* lets any trace be replayed against a historical branch later. A `provider`
|
|
40
|
+
* is attached only when the customer configured `dbSnapshot`; when absent it
|
|
41
|
+
* is resolved at replay time. The Bitfab service uses the timestamp to
|
|
42
|
+
* materialize an ephemeral branch from `customer-main`.
|
|
43
|
+
*/
|
|
44
|
+
declare const SUPPORTED_PROVIDERS: readonly ["neon"];
|
|
45
|
+
type DbSnapshotProvider = (typeof SUPPORTED_PROVIDERS)[number];
|
|
46
|
+
interface DbSnapshotConfig {
|
|
47
|
+
/** Discriminator for the server-side resolver. */
|
|
48
|
+
provider: DbSnapshotProvider;
|
|
49
|
+
}
|
|
50
|
+
interface DbSnapshotRef {
|
|
51
|
+
/**
|
|
52
|
+
* The wall-clock ISO timestamp the SDK observed immediately before
|
|
53
|
+
* invoking the wrapped function. The name encodes its provenance:
|
|
54
|
+
* SDK-observed, wall clock (not monotonic), captured before user code
|
|
55
|
+
* began executing. Always present.
|
|
56
|
+
*/
|
|
57
|
+
sdkWallClockBeforeFn: string;
|
|
58
|
+
/**
|
|
59
|
+
* The configured provider for server-side branch resolution. Only set when
|
|
60
|
+
* the customer configured `dbSnapshot`; otherwise the provider is resolved
|
|
61
|
+
* at replay time.
|
|
62
|
+
*/
|
|
63
|
+
provider?: DbSnapshotProvider;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Shared error type for Bitfab SDK runtime errors. Lives in its own
|
|
68
|
+
* module to avoid import cycles between `http.ts` and modules that need
|
|
69
|
+
* to throw structured errors (e.g. `dbSnapshot.ts` validation).
|
|
70
|
+
*/
|
|
71
|
+
declare class BitfabError extends Error {
|
|
72
|
+
readonly url?: string | undefined;
|
|
73
|
+
constructor(message: string, url?: string | undefined);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* HTTP client utilities for Bitfab API requests.
|
|
78
|
+
*
|
|
79
|
+
* This module provides:
|
|
80
|
+
* - HttpClient class for making API requests
|
|
81
|
+
* - awaitOnExit helper for fire-and-forget operations that must complete before process exit
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Wait for all pending fire-and-forget operations (spans, traces) to complete.
|
|
86
|
+
* Useful in tests and scripts to ensure all data has been sent before asserting or exiting.
|
|
87
|
+
*
|
|
88
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
|
|
89
|
+
*/
|
|
90
|
+
declare function flushTraces(timeoutMs?: number): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* How the API key is supplied internally: either a literal string or a
|
|
93
|
+
* function resolved each time the key is needed (at request/send time). The
|
|
94
|
+
* function form is what defers key resolution past module-load construction
|
|
95
|
+
* so an env var loaded after the client is built (the ESM dotenv-hoisting
|
|
96
|
+
* case) is still picked up.
|
|
97
|
+
*/
|
|
98
|
+
type ApiKeyInput = string | (() => string | undefined);
|
|
99
|
+
interface TokenUsage {
|
|
100
|
+
input: number | null;
|
|
101
|
+
output: number | null;
|
|
102
|
+
cached: number | null;
|
|
103
|
+
total: number | null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Describes a single file edited as part of a code change.
|
|
107
|
+
*
|
|
108
|
+
* - `path`: file path (relative to the repo root, or any consistent root)
|
|
109
|
+
* - `before`: file contents before the change ("" for newly created files)
|
|
110
|
+
* - `after`: file contents after the change ("" for deleted files)
|
|
111
|
+
*/
|
|
112
|
+
interface CodeChangeFile {
|
|
113
|
+
path: string;
|
|
114
|
+
before: string;
|
|
115
|
+
after: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
33
118
|
/**
|
|
34
119
|
* Claude Agent SDK handler for Bitfab tracing.
|
|
35
120
|
*
|
|
@@ -40,6 +125,7 @@ type AllowedEnvVars = {
|
|
|
40
125
|
* 1. SDK hooks (PreToolUse, PostToolUse, etc.) for tool/subagent lifecycle
|
|
41
126
|
* 2. Stream wrapping for LLM turn capture from the message stream
|
|
42
127
|
*/
|
|
128
|
+
|
|
43
129
|
interface ActiveSpanContext$2 {
|
|
44
130
|
traceId: string;
|
|
45
131
|
spanId: string;
|
|
@@ -96,7 +182,7 @@ declare class BitfabClaudeAgentHandler {
|
|
|
96
182
|
private rootInput;
|
|
97
183
|
private rootOutput;
|
|
98
184
|
constructor(config: {
|
|
99
|
-
apiKey?:
|
|
185
|
+
apiKey?: ApiKeyInput;
|
|
100
186
|
traceFunctionKey: string;
|
|
101
187
|
serviceUrl?: string;
|
|
102
188
|
timeout?: number;
|
|
@@ -285,83 +371,6 @@ declare class BitfabVercelAiHandler {
|
|
|
285
371
|
get middleware(): BitfabLanguageModelMiddleware;
|
|
286
372
|
}
|
|
287
373
|
|
|
288
|
-
/**
|
|
289
|
-
* Per-trace database snapshot ref capture.
|
|
290
|
-
*
|
|
291
|
-
* Every root span carries a `DbSnapshotRef` that pins the DB state at trace
|
|
292
|
-
* open by wall-clock timestamp. Capturing the timestamp is free (no IO) and
|
|
293
|
-
* harmless, so it happens on every trace regardless of configuration: that
|
|
294
|
-
* lets any trace be replayed against a historical branch later. A `provider`
|
|
295
|
-
* is attached only when the customer configured `dbSnapshot`; when absent it
|
|
296
|
-
* is resolved at replay time. The Bitfab service uses the timestamp to
|
|
297
|
-
* materialize an ephemeral branch from `customer-main`.
|
|
298
|
-
*/
|
|
299
|
-
declare const SUPPORTED_PROVIDERS: readonly ["neon"];
|
|
300
|
-
type DbSnapshotProvider = (typeof SUPPORTED_PROVIDERS)[number];
|
|
301
|
-
interface DbSnapshotConfig {
|
|
302
|
-
/** Discriminator for the server-side resolver. */
|
|
303
|
-
provider: DbSnapshotProvider;
|
|
304
|
-
}
|
|
305
|
-
interface DbSnapshotRef {
|
|
306
|
-
/**
|
|
307
|
-
* The wall-clock ISO timestamp the SDK observed immediately before
|
|
308
|
-
* invoking the wrapped function. The name encodes its provenance:
|
|
309
|
-
* SDK-observed, wall clock (not monotonic), captured before user code
|
|
310
|
-
* began executing. Always present.
|
|
311
|
-
*/
|
|
312
|
-
sdkWallClockBeforeFn: string;
|
|
313
|
-
/**
|
|
314
|
-
* The configured provider for server-side branch resolution. Only set when
|
|
315
|
-
* the customer configured `dbSnapshot`; otherwise the provider is resolved
|
|
316
|
-
* at replay time.
|
|
317
|
-
*/
|
|
318
|
-
provider?: DbSnapshotProvider;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Shared error type for Bitfab SDK runtime errors. Lives in its own
|
|
323
|
-
* module to avoid import cycles between `http.ts` and modules that need
|
|
324
|
-
* to throw structured errors (e.g. `dbSnapshot.ts` validation).
|
|
325
|
-
*/
|
|
326
|
-
declare class BitfabError extends Error {
|
|
327
|
-
readonly url?: string | undefined;
|
|
328
|
-
constructor(message: string, url?: string | undefined);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* HTTP client utilities for Bitfab API requests.
|
|
333
|
-
*
|
|
334
|
-
* This module provides:
|
|
335
|
-
* - HttpClient class for making API requests
|
|
336
|
-
* - awaitOnExit helper for fire-and-forget operations that must complete before process exit
|
|
337
|
-
*/
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Wait for all pending fire-and-forget operations (spans, traces) to complete.
|
|
341
|
-
* Useful in tests and scripts to ensure all data has been sent before asserting or exiting.
|
|
342
|
-
*
|
|
343
|
-
* @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
|
|
344
|
-
*/
|
|
345
|
-
declare function flushTraces(timeoutMs?: number): Promise<void>;
|
|
346
|
-
interface TokenUsage {
|
|
347
|
-
input: number | null;
|
|
348
|
-
output: number | null;
|
|
349
|
-
cached: number | null;
|
|
350
|
-
total: number | null;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Describes a single file edited as part of a code change.
|
|
354
|
-
*
|
|
355
|
-
* - `path`: file path (relative to the repo root, or any consistent root)
|
|
356
|
-
* - `before`: file contents before the change ("" for newly created files)
|
|
357
|
-
* - `after`: file contents after the change ("" for deleted files)
|
|
358
|
-
*/
|
|
359
|
-
interface CodeChangeFile {
|
|
360
|
-
path: string;
|
|
361
|
-
before: string;
|
|
362
|
-
after: string;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
374
|
/**
|
|
366
375
|
* LangGraph/LangChain callback handler for Bitfab tracing.
|
|
367
376
|
*
|
|
@@ -372,6 +381,7 @@ interface CodeChangeFile {
|
|
|
372
381
|
* Duck-typed to match LangChain.js's BaseCallbackHandler interface.
|
|
373
382
|
* No @langchain/core dependency required.
|
|
374
383
|
*/
|
|
384
|
+
|
|
375
385
|
interface ActiveSpanContext$1 {
|
|
376
386
|
traceId: string;
|
|
377
387
|
spanId: string;
|
|
@@ -401,7 +411,7 @@ declare class BitfabLangGraphCallbackHandler {
|
|
|
401
411
|
private runToSpan;
|
|
402
412
|
private invocations;
|
|
403
413
|
constructor(config: {
|
|
404
|
-
apiKey?:
|
|
414
|
+
apiKey?: ApiKeyInput;
|
|
405
415
|
traceFunctionKey: string;
|
|
406
416
|
serviceUrl?: string;
|
|
407
417
|
timeout?: number;
|
|
@@ -670,6 +680,8 @@ interface ReplayOptions {
|
|
|
670
680
|
}
|
|
671
681
|
/** Running totals reported to {@link ReplayOptions.onProgress} as replay proceeds. */
|
|
672
682
|
interface ReplayProgress {
|
|
683
|
+
/** Test run ID created for this replay. */
|
|
684
|
+
testRunId?: string;
|
|
673
685
|
/** Items that have finished so far, whether they succeeded or errored. */
|
|
674
686
|
completed: number;
|
|
675
687
|
/** Total number of items in this replay run. */
|
|
@@ -687,9 +699,21 @@ interface ReplayProgress {
|
|
|
687
699
|
* {@link ReplayResult}.
|
|
688
700
|
*/
|
|
689
701
|
item?: {
|
|
702
|
+
/** Source (historical) trace ID being replayed. */
|
|
690
703
|
traceId: string | null;
|
|
704
|
+
/** Local SDK replay trace ID, before the server maps it to a row ID. */
|
|
705
|
+
replayTraceId?: string | null;
|
|
706
|
+
/** Deserialized inputs from the original trace. */
|
|
707
|
+
input?: unknown[];
|
|
708
|
+
/** The result returned by the replayed function, or undefined on error. */
|
|
709
|
+
result?: unknown;
|
|
710
|
+
/** The original output from the historical trace. */
|
|
711
|
+
originalOutput?: unknown;
|
|
691
712
|
error: string | null;
|
|
692
713
|
durationMs: number | null;
|
|
714
|
+
tokens?: TokenUsage | null;
|
|
715
|
+
model?: string | null;
|
|
716
|
+
dbSnapshotRef?: DbSnapshotRef | null;
|
|
693
717
|
};
|
|
694
718
|
}
|
|
695
719
|
/**
|
|
@@ -782,6 +806,7 @@ interface ReplayResult<T> {
|
|
|
782
806
|
* This module provides utilities for sending external traces (e.g., from OpenAI API calls)
|
|
783
807
|
* to Bitfab for monitoring and analysis.
|
|
784
808
|
*/
|
|
809
|
+
|
|
785
810
|
interface Trace {
|
|
786
811
|
traceId: string;
|
|
787
812
|
toJSON(): unknown;
|
|
@@ -842,7 +867,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
|
|
|
842
867
|
* @param config - Configuration options
|
|
843
868
|
*/
|
|
844
869
|
constructor(config: {
|
|
845
|
-
apiKey?:
|
|
870
|
+
apiKey?: ApiKeyInput;
|
|
846
871
|
serviceUrl?: string;
|
|
847
872
|
timeout?: number;
|
|
848
873
|
getActiveSpanContext?: () => ActiveSpanContext | null;
|
|
@@ -1009,8 +1034,19 @@ declare function getCurrentSpan(): CurrentSpan;
|
|
|
1009
1034
|
*/
|
|
1010
1035
|
declare function getCurrentTrace(): CurrentTrace;
|
|
1011
1036
|
interface BitfabConfig {
|
|
1012
|
-
/**
|
|
1013
|
-
|
|
1037
|
+
/**
|
|
1038
|
+
* The API key for Bitfab API authentication. Resolved lazily, the first
|
|
1039
|
+
* time a span actually needs it, not at construction. When it resolves
|
|
1040
|
+
* empty, tracing is disabled (a no-op, unless `strict` is set).
|
|
1041
|
+
*
|
|
1042
|
+
* Accepts either a string or a function returning the key. The function
|
|
1043
|
+
* form is resolved at first use, so it survives the ESM trap where a shim
|
|
1044
|
+
* built at module load runs before the script body's `dotenv.config()`:
|
|
1045
|
+
* `apiKey: () => process.env.BITFAB_API_KEY`. When omitted (or it resolves
|
|
1046
|
+
* empty), the SDK also falls back to reading `BITFAB_API_KEY` from the
|
|
1047
|
+
* environment itself, again at first use.
|
|
1048
|
+
*/
|
|
1049
|
+
apiKey?: string | (() => string | null | undefined);
|
|
1014
1050
|
/** The base URL for the Bitfab API (default: https://bitfab.ai) */
|
|
1015
1051
|
serviceUrl?: string;
|
|
1016
1052
|
/** Request timeout in milliseconds (default: 120000) */
|
|
@@ -1019,6 +1055,14 @@ interface BitfabConfig {
|
|
|
1019
1055
|
envVars?: AllowedEnvVars;
|
|
1020
1056
|
/** Whether the client is enabled. Defaults to true. When false, withSpan returns the original function unwrapped. */
|
|
1021
1057
|
enabled?: boolean;
|
|
1058
|
+
/**
|
|
1059
|
+
* Fail loud instead of degrading quietly. When true, the first traced call
|
|
1060
|
+
* with no resolvable API key throws a `BitfabError` rather than silently
|
|
1061
|
+
* disabling tracing. Off by default so a missing telemetry key never takes
|
|
1062
|
+
* down the host app; turn it on in standalone scripts where a run that
|
|
1063
|
+
* emits no traces is a failure you want surfaced immediately.
|
|
1064
|
+
*/
|
|
1065
|
+
strict?: boolean;
|
|
1022
1066
|
/** The generated BAML client instance (e.g., `b` from your baml_client). Used by wrapBAML() when no explicit client is passed. */
|
|
1023
1067
|
bamlClient?: unknown;
|
|
1024
1068
|
/**
|
|
@@ -1093,11 +1137,17 @@ declare class Bitfab {
|
|
|
1093
1137
|
* function to pick up the per-trace branch URL.
|
|
1094
1138
|
*/
|
|
1095
1139
|
static readonly ReplayEnvironment: typeof ReplayEnvironment;
|
|
1096
|
-
private readonly
|
|
1140
|
+
private readonly apiKeyConfig;
|
|
1141
|
+
/** Cached only once a non-empty key is found, so an early resolve (before env loaded) can't poison a later one. */
|
|
1142
|
+
private resolvedApiKey;
|
|
1143
|
+
/** Gate the empty-key warning to fire at most once. */
|
|
1144
|
+
private apiKeyWarned;
|
|
1097
1145
|
private readonly serviceUrl;
|
|
1098
1146
|
private readonly timeout;
|
|
1099
1147
|
private readonly envVars;
|
|
1100
|
-
|
|
1148
|
+
/** The user's on/off intent. The effective enabled state ANDs this with "a key resolved" (see isTracingEnabled). */
|
|
1149
|
+
private readonly explicitlyEnabled;
|
|
1150
|
+
private readonly strict;
|
|
1101
1151
|
private readonly httpClient;
|
|
1102
1152
|
private readonly bamlClient;
|
|
1103
1153
|
private readonly dbSnapshot;
|
|
@@ -1107,6 +1157,28 @@ declare class Bitfab {
|
|
|
1107
1157
|
* @param config - Configuration options for the client
|
|
1108
1158
|
*/
|
|
1109
1159
|
constructor(config: BitfabConfig);
|
|
1160
|
+
/**
|
|
1161
|
+
* Resolve the API key lazily, the first time a span actually needs it.
|
|
1162
|
+
*
|
|
1163
|
+
* The key is intentionally NOT read at construction. In ESM, a shim that
|
|
1164
|
+
* does `new Bitfab({ apiKey: process.env.BITFAB_API_KEY })` is hoisted and
|
|
1165
|
+
* evaluated before the importing script's body runs `dotenv.config()`, so
|
|
1166
|
+
* the key would be empty at construction even though it is set moments
|
|
1167
|
+
* later. Resolving here (at first `withSpan` call / first request) reads
|
|
1168
|
+
* the key after env loading has run.
|
|
1169
|
+
*
|
|
1170
|
+
* Resolution order: the configured value (string, or function called each
|
|
1171
|
+
* time it is still unresolved), then a fallback read of `BITFAB_API_KEY`
|
|
1172
|
+
* from the environment. Once a non-empty key is found it is cached, so an
|
|
1173
|
+
* early resolve that found nothing never poisons a later one.
|
|
1174
|
+
*/
|
|
1175
|
+
private resolveApiKey;
|
|
1176
|
+
/**
|
|
1177
|
+
* Whether tracing should run, decided lazily at call time (not frozen at
|
|
1178
|
+
* construction). An explicit `enabled: false` short-circuits without ever
|
|
1179
|
+
* touching the key.
|
|
1180
|
+
*/
|
|
1181
|
+
private isTracingEnabled;
|
|
1110
1182
|
/**
|
|
1111
1183
|
* Fetch the function with its current version and BAML prompt from the server.
|
|
1112
1184
|
*
|
|
@@ -1531,7 +1603,7 @@ declare class BitfabFunction {
|
|
|
1531
1603
|
/**
|
|
1532
1604
|
* SDK version from package.json (injected at build time)
|
|
1533
1605
|
*/
|
|
1534
|
-
declare const __version__ = "0.
|
|
1606
|
+
declare const __version__ = "0.28.1";
|
|
1535
1607
|
|
|
1536
1608
|
/**
|
|
1537
1609
|
* Constants for the Bitfab SDK.
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,91 @@ type AllowedEnvVars = {
|
|
|
30
30
|
OPENAI_API_KEY?: string;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Per-trace database snapshot ref capture.
|
|
35
|
+
*
|
|
36
|
+
* Every root span carries a `DbSnapshotRef` that pins the DB state at trace
|
|
37
|
+
* open by wall-clock timestamp. Capturing the timestamp is free (no IO) and
|
|
38
|
+
* harmless, so it happens on every trace regardless of configuration: that
|
|
39
|
+
* lets any trace be replayed against a historical branch later. A `provider`
|
|
40
|
+
* is attached only when the customer configured `dbSnapshot`; when absent it
|
|
41
|
+
* is resolved at replay time. The Bitfab service uses the timestamp to
|
|
42
|
+
* materialize an ephemeral branch from `customer-main`.
|
|
43
|
+
*/
|
|
44
|
+
declare const SUPPORTED_PROVIDERS: readonly ["neon"];
|
|
45
|
+
type DbSnapshotProvider = (typeof SUPPORTED_PROVIDERS)[number];
|
|
46
|
+
interface DbSnapshotConfig {
|
|
47
|
+
/** Discriminator for the server-side resolver. */
|
|
48
|
+
provider: DbSnapshotProvider;
|
|
49
|
+
}
|
|
50
|
+
interface DbSnapshotRef {
|
|
51
|
+
/**
|
|
52
|
+
* The wall-clock ISO timestamp the SDK observed immediately before
|
|
53
|
+
* invoking the wrapped function. The name encodes its provenance:
|
|
54
|
+
* SDK-observed, wall clock (not monotonic), captured before user code
|
|
55
|
+
* began executing. Always present.
|
|
56
|
+
*/
|
|
57
|
+
sdkWallClockBeforeFn: string;
|
|
58
|
+
/**
|
|
59
|
+
* The configured provider for server-side branch resolution. Only set when
|
|
60
|
+
* the customer configured `dbSnapshot`; otherwise the provider is resolved
|
|
61
|
+
* at replay time.
|
|
62
|
+
*/
|
|
63
|
+
provider?: DbSnapshotProvider;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Shared error type for Bitfab SDK runtime errors. Lives in its own
|
|
68
|
+
* module to avoid import cycles between `http.ts` and modules that need
|
|
69
|
+
* to throw structured errors (e.g. `dbSnapshot.ts` validation).
|
|
70
|
+
*/
|
|
71
|
+
declare class BitfabError extends Error {
|
|
72
|
+
readonly url?: string | undefined;
|
|
73
|
+
constructor(message: string, url?: string | undefined);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* HTTP client utilities for Bitfab API requests.
|
|
78
|
+
*
|
|
79
|
+
* This module provides:
|
|
80
|
+
* - HttpClient class for making API requests
|
|
81
|
+
* - awaitOnExit helper for fire-and-forget operations that must complete before process exit
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Wait for all pending fire-and-forget operations (spans, traces) to complete.
|
|
86
|
+
* Useful in tests and scripts to ensure all data has been sent before asserting or exiting.
|
|
87
|
+
*
|
|
88
|
+
* @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
|
|
89
|
+
*/
|
|
90
|
+
declare function flushTraces(timeoutMs?: number): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* How the API key is supplied internally: either a literal string or a
|
|
93
|
+
* function resolved each time the key is needed (at request/send time). The
|
|
94
|
+
* function form is what defers key resolution past module-load construction
|
|
95
|
+
* so an env var loaded after the client is built (the ESM dotenv-hoisting
|
|
96
|
+
* case) is still picked up.
|
|
97
|
+
*/
|
|
98
|
+
type ApiKeyInput = string | (() => string | undefined);
|
|
99
|
+
interface TokenUsage {
|
|
100
|
+
input: number | null;
|
|
101
|
+
output: number | null;
|
|
102
|
+
cached: number | null;
|
|
103
|
+
total: number | null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Describes a single file edited as part of a code change.
|
|
107
|
+
*
|
|
108
|
+
* - `path`: file path (relative to the repo root, or any consistent root)
|
|
109
|
+
* - `before`: file contents before the change ("" for newly created files)
|
|
110
|
+
* - `after`: file contents after the change ("" for deleted files)
|
|
111
|
+
*/
|
|
112
|
+
interface CodeChangeFile {
|
|
113
|
+
path: string;
|
|
114
|
+
before: string;
|
|
115
|
+
after: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
33
118
|
/**
|
|
34
119
|
* Claude Agent SDK handler for Bitfab tracing.
|
|
35
120
|
*
|
|
@@ -40,6 +125,7 @@ type AllowedEnvVars = {
|
|
|
40
125
|
* 1. SDK hooks (PreToolUse, PostToolUse, etc.) for tool/subagent lifecycle
|
|
41
126
|
* 2. Stream wrapping for LLM turn capture from the message stream
|
|
42
127
|
*/
|
|
128
|
+
|
|
43
129
|
interface ActiveSpanContext$2 {
|
|
44
130
|
traceId: string;
|
|
45
131
|
spanId: string;
|
|
@@ -96,7 +182,7 @@ declare class BitfabClaudeAgentHandler {
|
|
|
96
182
|
private rootInput;
|
|
97
183
|
private rootOutput;
|
|
98
184
|
constructor(config: {
|
|
99
|
-
apiKey?:
|
|
185
|
+
apiKey?: ApiKeyInput;
|
|
100
186
|
traceFunctionKey: string;
|
|
101
187
|
serviceUrl?: string;
|
|
102
188
|
timeout?: number;
|
|
@@ -285,83 +371,6 @@ declare class BitfabVercelAiHandler {
|
|
|
285
371
|
get middleware(): BitfabLanguageModelMiddleware;
|
|
286
372
|
}
|
|
287
373
|
|
|
288
|
-
/**
|
|
289
|
-
* Per-trace database snapshot ref capture.
|
|
290
|
-
*
|
|
291
|
-
* Every root span carries a `DbSnapshotRef` that pins the DB state at trace
|
|
292
|
-
* open by wall-clock timestamp. Capturing the timestamp is free (no IO) and
|
|
293
|
-
* harmless, so it happens on every trace regardless of configuration: that
|
|
294
|
-
* lets any trace be replayed against a historical branch later. A `provider`
|
|
295
|
-
* is attached only when the customer configured `dbSnapshot`; when absent it
|
|
296
|
-
* is resolved at replay time. The Bitfab service uses the timestamp to
|
|
297
|
-
* materialize an ephemeral branch from `customer-main`.
|
|
298
|
-
*/
|
|
299
|
-
declare const SUPPORTED_PROVIDERS: readonly ["neon"];
|
|
300
|
-
type DbSnapshotProvider = (typeof SUPPORTED_PROVIDERS)[number];
|
|
301
|
-
interface DbSnapshotConfig {
|
|
302
|
-
/** Discriminator for the server-side resolver. */
|
|
303
|
-
provider: DbSnapshotProvider;
|
|
304
|
-
}
|
|
305
|
-
interface DbSnapshotRef {
|
|
306
|
-
/**
|
|
307
|
-
* The wall-clock ISO timestamp the SDK observed immediately before
|
|
308
|
-
* invoking the wrapped function. The name encodes its provenance:
|
|
309
|
-
* SDK-observed, wall clock (not monotonic), captured before user code
|
|
310
|
-
* began executing. Always present.
|
|
311
|
-
*/
|
|
312
|
-
sdkWallClockBeforeFn: string;
|
|
313
|
-
/**
|
|
314
|
-
* The configured provider for server-side branch resolution. Only set when
|
|
315
|
-
* the customer configured `dbSnapshot`; otherwise the provider is resolved
|
|
316
|
-
* at replay time.
|
|
317
|
-
*/
|
|
318
|
-
provider?: DbSnapshotProvider;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Shared error type for Bitfab SDK runtime errors. Lives in its own
|
|
323
|
-
* module to avoid import cycles between `http.ts` and modules that need
|
|
324
|
-
* to throw structured errors (e.g. `dbSnapshot.ts` validation).
|
|
325
|
-
*/
|
|
326
|
-
declare class BitfabError extends Error {
|
|
327
|
-
readonly url?: string | undefined;
|
|
328
|
-
constructor(message: string, url?: string | undefined);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* HTTP client utilities for Bitfab API requests.
|
|
333
|
-
*
|
|
334
|
-
* This module provides:
|
|
335
|
-
* - HttpClient class for making API requests
|
|
336
|
-
* - awaitOnExit helper for fire-and-forget operations that must complete before process exit
|
|
337
|
-
*/
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Wait for all pending fire-and-forget operations (spans, traces) to complete.
|
|
341
|
-
* Useful in tests and scripts to ensure all data has been sent before asserting or exiting.
|
|
342
|
-
*
|
|
343
|
-
* @param timeoutMs - Maximum time to wait in milliseconds (default: 5000)
|
|
344
|
-
*/
|
|
345
|
-
declare function flushTraces(timeoutMs?: number): Promise<void>;
|
|
346
|
-
interface TokenUsage {
|
|
347
|
-
input: number | null;
|
|
348
|
-
output: number | null;
|
|
349
|
-
cached: number | null;
|
|
350
|
-
total: number | null;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Describes a single file edited as part of a code change.
|
|
354
|
-
*
|
|
355
|
-
* - `path`: file path (relative to the repo root, or any consistent root)
|
|
356
|
-
* - `before`: file contents before the change ("" for newly created files)
|
|
357
|
-
* - `after`: file contents after the change ("" for deleted files)
|
|
358
|
-
*/
|
|
359
|
-
interface CodeChangeFile {
|
|
360
|
-
path: string;
|
|
361
|
-
before: string;
|
|
362
|
-
after: string;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
374
|
/**
|
|
366
375
|
* LangGraph/LangChain callback handler for Bitfab tracing.
|
|
367
376
|
*
|
|
@@ -372,6 +381,7 @@ interface CodeChangeFile {
|
|
|
372
381
|
* Duck-typed to match LangChain.js's BaseCallbackHandler interface.
|
|
373
382
|
* No @langchain/core dependency required.
|
|
374
383
|
*/
|
|
384
|
+
|
|
375
385
|
interface ActiveSpanContext$1 {
|
|
376
386
|
traceId: string;
|
|
377
387
|
spanId: string;
|
|
@@ -401,7 +411,7 @@ declare class BitfabLangGraphCallbackHandler {
|
|
|
401
411
|
private runToSpan;
|
|
402
412
|
private invocations;
|
|
403
413
|
constructor(config: {
|
|
404
|
-
apiKey?:
|
|
414
|
+
apiKey?: ApiKeyInput;
|
|
405
415
|
traceFunctionKey: string;
|
|
406
416
|
serviceUrl?: string;
|
|
407
417
|
timeout?: number;
|
|
@@ -670,6 +680,8 @@ interface ReplayOptions {
|
|
|
670
680
|
}
|
|
671
681
|
/** Running totals reported to {@link ReplayOptions.onProgress} as replay proceeds. */
|
|
672
682
|
interface ReplayProgress {
|
|
683
|
+
/** Test run ID created for this replay. */
|
|
684
|
+
testRunId?: string;
|
|
673
685
|
/** Items that have finished so far, whether they succeeded or errored. */
|
|
674
686
|
completed: number;
|
|
675
687
|
/** Total number of items in this replay run. */
|
|
@@ -687,9 +699,21 @@ interface ReplayProgress {
|
|
|
687
699
|
* {@link ReplayResult}.
|
|
688
700
|
*/
|
|
689
701
|
item?: {
|
|
702
|
+
/** Source (historical) trace ID being replayed. */
|
|
690
703
|
traceId: string | null;
|
|
704
|
+
/** Local SDK replay trace ID, before the server maps it to a row ID. */
|
|
705
|
+
replayTraceId?: string | null;
|
|
706
|
+
/** Deserialized inputs from the original trace. */
|
|
707
|
+
input?: unknown[];
|
|
708
|
+
/** The result returned by the replayed function, or undefined on error. */
|
|
709
|
+
result?: unknown;
|
|
710
|
+
/** The original output from the historical trace. */
|
|
711
|
+
originalOutput?: unknown;
|
|
691
712
|
error: string | null;
|
|
692
713
|
durationMs: number | null;
|
|
714
|
+
tokens?: TokenUsage | null;
|
|
715
|
+
model?: string | null;
|
|
716
|
+
dbSnapshotRef?: DbSnapshotRef | null;
|
|
693
717
|
};
|
|
694
718
|
}
|
|
695
719
|
/**
|
|
@@ -782,6 +806,7 @@ interface ReplayResult<T> {
|
|
|
782
806
|
* This module provides utilities for sending external traces (e.g., from OpenAI API calls)
|
|
783
807
|
* to Bitfab for monitoring and analysis.
|
|
784
808
|
*/
|
|
809
|
+
|
|
785
810
|
interface Trace {
|
|
786
811
|
traceId: string;
|
|
787
812
|
toJSON(): unknown;
|
|
@@ -842,7 +867,7 @@ declare class BitfabOpenAITracingProcessor implements TracingProcessor {
|
|
|
842
867
|
* @param config - Configuration options
|
|
843
868
|
*/
|
|
844
869
|
constructor(config: {
|
|
845
|
-
apiKey?:
|
|
870
|
+
apiKey?: ApiKeyInput;
|
|
846
871
|
serviceUrl?: string;
|
|
847
872
|
timeout?: number;
|
|
848
873
|
getActiveSpanContext?: () => ActiveSpanContext | null;
|
|
@@ -1009,8 +1034,19 @@ declare function getCurrentSpan(): CurrentSpan;
|
|
|
1009
1034
|
*/
|
|
1010
1035
|
declare function getCurrentTrace(): CurrentTrace;
|
|
1011
1036
|
interface BitfabConfig {
|
|
1012
|
-
/**
|
|
1013
|
-
|
|
1037
|
+
/**
|
|
1038
|
+
* The API key for Bitfab API authentication. Resolved lazily, the first
|
|
1039
|
+
* time a span actually needs it, not at construction. When it resolves
|
|
1040
|
+
* empty, tracing is disabled (a no-op, unless `strict` is set).
|
|
1041
|
+
*
|
|
1042
|
+
* Accepts either a string or a function returning the key. The function
|
|
1043
|
+
* form is resolved at first use, so it survives the ESM trap where a shim
|
|
1044
|
+
* built at module load runs before the script body's `dotenv.config()`:
|
|
1045
|
+
* `apiKey: () => process.env.BITFAB_API_KEY`. When omitted (or it resolves
|
|
1046
|
+
* empty), the SDK also falls back to reading `BITFAB_API_KEY` from the
|
|
1047
|
+
* environment itself, again at first use.
|
|
1048
|
+
*/
|
|
1049
|
+
apiKey?: string | (() => string | null | undefined);
|
|
1014
1050
|
/** The base URL for the Bitfab API (default: https://bitfab.ai) */
|
|
1015
1051
|
serviceUrl?: string;
|
|
1016
1052
|
/** Request timeout in milliseconds (default: 120000) */
|
|
@@ -1019,6 +1055,14 @@ interface BitfabConfig {
|
|
|
1019
1055
|
envVars?: AllowedEnvVars;
|
|
1020
1056
|
/** Whether the client is enabled. Defaults to true. When false, withSpan returns the original function unwrapped. */
|
|
1021
1057
|
enabled?: boolean;
|
|
1058
|
+
/**
|
|
1059
|
+
* Fail loud instead of degrading quietly. When true, the first traced call
|
|
1060
|
+
* with no resolvable API key throws a `BitfabError` rather than silently
|
|
1061
|
+
* disabling tracing. Off by default so a missing telemetry key never takes
|
|
1062
|
+
* down the host app; turn it on in standalone scripts where a run that
|
|
1063
|
+
* emits no traces is a failure you want surfaced immediately.
|
|
1064
|
+
*/
|
|
1065
|
+
strict?: boolean;
|
|
1022
1066
|
/** The generated BAML client instance (e.g., `b` from your baml_client). Used by wrapBAML() when no explicit client is passed. */
|
|
1023
1067
|
bamlClient?: unknown;
|
|
1024
1068
|
/**
|
|
@@ -1093,11 +1137,17 @@ declare class Bitfab {
|
|
|
1093
1137
|
* function to pick up the per-trace branch URL.
|
|
1094
1138
|
*/
|
|
1095
1139
|
static readonly ReplayEnvironment: typeof ReplayEnvironment;
|
|
1096
|
-
private readonly
|
|
1140
|
+
private readonly apiKeyConfig;
|
|
1141
|
+
/** Cached only once a non-empty key is found, so an early resolve (before env loaded) can't poison a later one. */
|
|
1142
|
+
private resolvedApiKey;
|
|
1143
|
+
/** Gate the empty-key warning to fire at most once. */
|
|
1144
|
+
private apiKeyWarned;
|
|
1097
1145
|
private readonly serviceUrl;
|
|
1098
1146
|
private readonly timeout;
|
|
1099
1147
|
private readonly envVars;
|
|
1100
|
-
|
|
1148
|
+
/** The user's on/off intent. The effective enabled state ANDs this with "a key resolved" (see isTracingEnabled). */
|
|
1149
|
+
private readonly explicitlyEnabled;
|
|
1150
|
+
private readonly strict;
|
|
1101
1151
|
private readonly httpClient;
|
|
1102
1152
|
private readonly bamlClient;
|
|
1103
1153
|
private readonly dbSnapshot;
|
|
@@ -1107,6 +1157,28 @@ declare class Bitfab {
|
|
|
1107
1157
|
* @param config - Configuration options for the client
|
|
1108
1158
|
*/
|
|
1109
1159
|
constructor(config: BitfabConfig);
|
|
1160
|
+
/**
|
|
1161
|
+
* Resolve the API key lazily, the first time a span actually needs it.
|
|
1162
|
+
*
|
|
1163
|
+
* The key is intentionally NOT read at construction. In ESM, a shim that
|
|
1164
|
+
* does `new Bitfab({ apiKey: process.env.BITFAB_API_KEY })` is hoisted and
|
|
1165
|
+
* evaluated before the importing script's body runs `dotenv.config()`, so
|
|
1166
|
+
* the key would be empty at construction even though it is set moments
|
|
1167
|
+
* later. Resolving here (at first `withSpan` call / first request) reads
|
|
1168
|
+
* the key after env loading has run.
|
|
1169
|
+
*
|
|
1170
|
+
* Resolution order: the configured value (string, or function called each
|
|
1171
|
+
* time it is still unresolved), then a fallback read of `BITFAB_API_KEY`
|
|
1172
|
+
* from the environment. Once a non-empty key is found it is cached, so an
|
|
1173
|
+
* early resolve that found nothing never poisons a later one.
|
|
1174
|
+
*/
|
|
1175
|
+
private resolveApiKey;
|
|
1176
|
+
/**
|
|
1177
|
+
* Whether tracing should run, decided lazily at call time (not frozen at
|
|
1178
|
+
* construction). An explicit `enabled: false` short-circuits without ever
|
|
1179
|
+
* touching the key.
|
|
1180
|
+
*/
|
|
1181
|
+
private isTracingEnabled;
|
|
1110
1182
|
/**
|
|
1111
1183
|
* Fetch the function with its current version and BAML prompt from the server.
|
|
1112
1184
|
*
|
|
@@ -1531,7 +1603,7 @@ declare class BitfabFunction {
|
|
|
1531
1603
|
/**
|
|
1532
1604
|
* SDK version from package.json (injected at build time)
|
|
1533
1605
|
*/
|
|
1534
|
-
declare const __version__ = "0.
|
|
1606
|
+
declare const __version__ = "0.28.1";
|
|
1535
1607
|
|
|
1536
1608
|
/**
|
|
1537
1609
|
* Constants for the Bitfab SDK.
|