bitfab 0.54.6 → 0.54.8
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 +2 -1
- package/dist/{chunk-5FRFNRFA.js → chunk-5H3D7J4K.js} +11 -2
- package/dist/{chunk-5FRFNRFA.js.map → chunk-5H3D7J4K.js.map} +1 -1
- package/dist/{chunk-WWE3W6HF.js → chunk-5LXZGUKW.js} +3 -3
- package/dist/{chunk-IKNIY7JV.js → chunk-RC3HOMLJ.js} +11 -2
- package/dist/{chunk-IKNIY7JV.js.map → chunk-RC3HOMLJ.js.map} +1 -1
- package/dist/{chunk-EBDVWYCV.js → chunk-RUCVJQBI.js} +2 -2
- package/dist/{chunk-FCJHKGEE.js → chunk-XPCVDQDS.js} +90 -24
- package/dist/chunk-XPCVDQDS.js.map +1 -0
- package/dist/{http-DRPXLTJS.js → http-4JG3XW5X.js} +2 -2
- package/dist/{http-EMAHQQ4A.js → http-7PL32JLX.js} +2 -2
- package/dist/index.cjs +94 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +3 -3
- package/dist/node.cjs +94 -19
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +3 -3
- package/dist/{replay-XG6LNUN4.js → replay-KWBZ2JQV.js} +3 -3
- package/dist/replayCli.js +2 -2
- package/dist/seedCli.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-FCJHKGEE.js.map +0 -1
- /package/dist/{chunk-WWE3W6HF.js.map → chunk-5LXZGUKW.js.map} +0 -0
- /package/dist/{chunk-EBDVWYCV.js.map → chunk-RUCVJQBI.js.map} +0 -0
- /package/dist/{http-DRPXLTJS.js.map → http-4JG3XW5X.js.map} +0 -0
- /package/dist/{http-EMAHQQ4A.js.map → http-7PL32JLX.js.map} +0 -0
- /package/dist/{replay-XG6LNUN4.js.map → replay-KWBZ2JQV.js.map} +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
flushTraces,
|
|
7
7
|
parseRetryAfterMs,
|
|
8
8
|
serializePayloadBody
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-RC3HOMLJ.js";
|
|
10
10
|
export {
|
|
11
11
|
BitfabError,
|
|
12
12
|
HttpClient,
|
|
@@ -16,4 +16,4 @@ export {
|
|
|
16
16
|
parseRetryAfterMs,
|
|
17
17
|
serializePayloadBody
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=http-
|
|
19
|
+
//# sourceMappingURL=http-4JG3XW5X.js.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
flushTraces,
|
|
7
7
|
parseRetryAfterMs,
|
|
8
8
|
serializePayloadBody
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-5H3D7J4K.js";
|
|
10
10
|
import "./chunk-VCRFFCLY.js";
|
|
11
11
|
export {
|
|
12
12
|
BitfabError,
|
|
@@ -17,4 +17,4 @@ export {
|
|
|
17
17
|
parseRetryAfterMs,
|
|
18
18
|
serializePayloadBody
|
|
19
19
|
};
|
|
20
|
-
//# sourceMappingURL=http-
|
|
20
|
+
//# sourceMappingURL=http-7PL32JLX.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -51,7 +51,7 @@ var __version__, __packageName__;
|
|
|
51
51
|
var init_version_generated = __esm({
|
|
52
52
|
"src/version.generated.ts"() {
|
|
53
53
|
"use strict";
|
|
54
|
-
__version__ = "0.54.
|
|
54
|
+
__version__ = "0.54.8";
|
|
55
55
|
__packageName__ = "bitfab";
|
|
56
56
|
}
|
|
57
57
|
});
|
|
@@ -2322,6 +2322,15 @@ var init_http = __esm({
|
|
|
2322
2322
|
resolveApiKey() {
|
|
2323
2323
|
return typeof this.apiKey === "function" ? this.apiKey() : this.apiKey;
|
|
2324
2324
|
}
|
|
2325
|
+
/** @internal Whether this client currently has credentials for trace delivery. */
|
|
2326
|
+
hasApiKey() {
|
|
2327
|
+
try {
|
|
2328
|
+
const apiKey = this.resolveApiKey();
|
|
2329
|
+
return apiKey !== void 0 && apiKey.trim() !== "";
|
|
2330
|
+
} catch {
|
|
2331
|
+
return false;
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2325
2334
|
/**
|
|
2326
2335
|
* This client's span transport, built on first use.
|
|
2327
2336
|
*
|
|
@@ -4499,6 +4508,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
4499
4508
|
});
|
|
4500
4509
|
this.traceFunctionKey = config.traceFunctionKey;
|
|
4501
4510
|
this.getActiveSpanContext = config.getActiveSpanContext ?? null;
|
|
4511
|
+
this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
|
|
4502
4512
|
this.preToolUseHook = this.preToolUseHook.bind(this);
|
|
4503
4513
|
this.postToolUseHook = this.postToolUseHook.bind(this);
|
|
4504
4514
|
this.postToolUseFailureHook = this.postToolUseFailureHook.bind(this);
|
|
@@ -4603,6 +4613,9 @@ var BitfabClaudeAgentHandler = class {
|
|
|
4603
4613
|
this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
|
|
4604
4614
|
}
|
|
4605
4615
|
sendSpan(spanInfo) {
|
|
4616
|
+
if (!this.shouldRecord()) {
|
|
4617
|
+
return;
|
|
4618
|
+
}
|
|
4606
4619
|
const spanData = {
|
|
4607
4620
|
name: spanInfo.name,
|
|
4608
4621
|
type: spanInfo.type
|
|
@@ -4646,6 +4659,9 @@ var BitfabClaudeAgentHandler = class {
|
|
|
4646
4659
|
}
|
|
4647
4660
|
}
|
|
4648
4661
|
sendTraceCompletion(endedAt, metadata) {
|
|
4662
|
+
if (!this.shouldRecord()) {
|
|
4663
|
+
return;
|
|
4664
|
+
}
|
|
4649
4665
|
if (this.traceId === null) {
|
|
4650
4666
|
return;
|
|
4651
4667
|
}
|
|
@@ -6187,6 +6203,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
6187
6203
|
});
|
|
6188
6204
|
this.traceFunctionKey = config.traceFunctionKey;
|
|
6189
6205
|
this.getActiveSpanContext = config.getActiveSpanContext ?? null;
|
|
6206
|
+
this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
|
|
6190
6207
|
this.captureTools = config.captureTools ?? true;
|
|
6191
6208
|
}
|
|
6192
6209
|
/**
|
|
@@ -6295,6 +6312,9 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
6295
6312
|
this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
|
|
6296
6313
|
}
|
|
6297
6314
|
sendSpan(spanInfo) {
|
|
6315
|
+
if (!this.shouldRecord()) {
|
|
6316
|
+
return;
|
|
6317
|
+
}
|
|
6298
6318
|
const spanData = {
|
|
6299
6319
|
name: spanInfo.name,
|
|
6300
6320
|
type: spanInfo.type
|
|
@@ -6338,6 +6358,9 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
6338
6358
|
}
|
|
6339
6359
|
}
|
|
6340
6360
|
sendTraceCompletion(rootSpan, activeContext) {
|
|
6361
|
+
if (!this.shouldRecord()) {
|
|
6362
|
+
return;
|
|
6363
|
+
}
|
|
6341
6364
|
const completed = activeContext === null;
|
|
6342
6365
|
const traceData = {
|
|
6343
6366
|
id: rootSpan.traceId,
|
|
@@ -6358,6 +6381,9 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
6358
6381
|
}
|
|
6359
6382
|
}
|
|
6360
6383
|
sendTraceStart(rootSpan) {
|
|
6384
|
+
if (!this.shouldRecord()) {
|
|
6385
|
+
return;
|
|
6386
|
+
}
|
|
6361
6387
|
const traceData = {
|
|
6362
6388
|
id: rootSpan.traceId,
|
|
6363
6389
|
type: "sdk-function",
|
|
@@ -7066,6 +7092,7 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7066
7092
|
timeout: config.timeout ?? 1e4
|
|
7067
7093
|
});
|
|
7068
7094
|
this.getActiveSpanContext = config.getActiveSpanContext ?? null;
|
|
7095
|
+
this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
|
|
7069
7096
|
}
|
|
7070
7097
|
getCanonicalTraceId(sourceTraceId) {
|
|
7071
7098
|
const existing = this.canonicalTraceIds[sourceTraceId];
|
|
@@ -7186,6 +7213,9 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7186
7213
|
* the OpenAI trace into an outer withSpan trace.
|
|
7187
7214
|
*/
|
|
7188
7215
|
sendTrace(trace, options = {}) {
|
|
7216
|
+
if (!this.shouldRecord()) {
|
|
7217
|
+
return;
|
|
7218
|
+
}
|
|
7189
7219
|
try {
|
|
7190
7220
|
const traceData = trace.toJSON();
|
|
7191
7221
|
if (options.sourceTraceId) {
|
|
@@ -7300,6 +7330,9 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7300
7330
|
* and parent_id are rewritten to link the span into the withSpan tree.
|
|
7301
7331
|
*/
|
|
7302
7332
|
sendSpan(span) {
|
|
7333
|
+
if (!this.shouldRecord()) {
|
|
7334
|
+
return;
|
|
7335
|
+
}
|
|
7303
7336
|
const errors = [];
|
|
7304
7337
|
const [serializedSpan, exportErrors] = this.exportSpan(span);
|
|
7305
7338
|
errors.push(...exportErrors);
|
|
@@ -7869,6 +7902,30 @@ function readEnv2(name) {
|
|
|
7869
7902
|
}
|
|
7870
7903
|
return void 0;
|
|
7871
7904
|
}
|
|
7905
|
+
var CAPTURE_ENABLED_ENV = "BITFAB_CAPTURE_ENABLED";
|
|
7906
|
+
var TRUE_ENV_VALUES = /* @__PURE__ */ new Set(["1", "true", "yes"]);
|
|
7907
|
+
var FALSE_ENV_VALUES = /* @__PURE__ */ new Set(["0", "false", "no"]);
|
|
7908
|
+
function readBooleanEnv(name) {
|
|
7909
|
+
const raw = readEnv2(name);
|
|
7910
|
+
if (raw === void 0) {
|
|
7911
|
+
return void 0;
|
|
7912
|
+
}
|
|
7913
|
+
const value = raw.trim().toLowerCase();
|
|
7914
|
+
if (value === "") {
|
|
7915
|
+
return void 0;
|
|
7916
|
+
}
|
|
7917
|
+
if (TRUE_ENV_VALUES.has(value)) {
|
|
7918
|
+
return true;
|
|
7919
|
+
}
|
|
7920
|
+
if (FALSE_ENV_VALUES.has(value)) {
|
|
7921
|
+
return false;
|
|
7922
|
+
}
|
|
7923
|
+
warnOnce(
|
|
7924
|
+
`unrecognized-boolean-env:${name}`,
|
|
7925
|
+
`${name}="${raw}" is not 0 or 1; ignoring it.`
|
|
7926
|
+
);
|
|
7927
|
+
return void 0;
|
|
7928
|
+
}
|
|
7872
7929
|
var DEFAULT_AUTO_TRACE_MAX_DEPTH = 30;
|
|
7873
7930
|
var DEFAULT_AUTO_TRACE_MAX_SPANS = 500;
|
|
7874
7931
|
var AUTO_TRACE_PROTOCOL = "ts-auto-v1";
|
|
@@ -7923,7 +7980,7 @@ var Bitfab = class {
|
|
|
7923
7980
|
"Bitfab({ enabled }) is deprecated; pass captureEnabled instead."
|
|
7924
7981
|
);
|
|
7925
7982
|
}
|
|
7926
|
-
this.
|
|
7983
|
+
this.captureConfiguredInCode = config.captureEnabled === void 0 && config.enabled === void 0 ? void 0 : (config.captureEnabled ?? true) && (config.enabled ?? true);
|
|
7927
7984
|
this.strict = config.strict ?? false;
|
|
7928
7985
|
this.bamlClient = config.bamlClient ?? null;
|
|
7929
7986
|
if (config.dbSnapshot) {
|
|
@@ -8377,7 +8434,7 @@ var Bitfab = class {
|
|
|
8377
8434
|
"Bitfab: no API key resolved. Set BITFAB_API_KEY or pass apiKey to new Bitfab(). If a script loads env with dotenv, load it before the module that constructs the client is imported (e.g. `node --env-file=.env script.ts`), or pass `apiKey: () => process.env.BITFAB_API_KEY`."
|
|
8378
8435
|
);
|
|
8379
8436
|
}
|
|
8380
|
-
if (this.
|
|
8437
|
+
if (this.isCaptureConfigured() && !this.apiKeyWarned) {
|
|
8381
8438
|
this.apiKeyWarned = true;
|
|
8382
8439
|
console.warn(
|
|
8383
8440
|
"Bitfab: apiKey is empty - tracing is disabled. Provide a valid API key to enable tracing."
|
|
@@ -8385,18 +8442,32 @@ var Bitfab = class {
|
|
|
8385
8442
|
}
|
|
8386
8443
|
return void 0;
|
|
8387
8444
|
}
|
|
8445
|
+
isCaptureConfigured() {
|
|
8446
|
+
if (this.captureConfiguredInCode !== void 0) {
|
|
8447
|
+
return this.captureConfiguredInCode;
|
|
8448
|
+
}
|
|
8449
|
+
if (this.captureConfiguredFromEnv === void 0) {
|
|
8450
|
+
this.captureConfiguredFromEnv = readBooleanEnv(CAPTURE_ENABLED_ENV) ?? true;
|
|
8451
|
+
}
|
|
8452
|
+
return this.captureConfiguredFromEnv;
|
|
8453
|
+
}
|
|
8388
8454
|
isCaptureEnabled() {
|
|
8389
|
-
if (!this.
|
|
8455
|
+
if (!this.isCaptureConfigured()) {
|
|
8390
8456
|
return false;
|
|
8391
8457
|
}
|
|
8392
8458
|
return this.resolveApiKey() !== void 0;
|
|
8393
8459
|
}
|
|
8394
8460
|
shouldRecord() {
|
|
8395
|
-
if (!this.
|
|
8461
|
+
if (!this.isCaptureConfigured() && !getReplayContext() && !inSeedScope()) {
|
|
8396
8462
|
return false;
|
|
8397
8463
|
}
|
|
8398
8464
|
return this.resolveApiKey() !== void 0;
|
|
8399
8465
|
}
|
|
8466
|
+
prepareFrameworkIntegration() {
|
|
8467
|
+
if (this.isCaptureConfigured() && this.strict) {
|
|
8468
|
+
this.resolveApiKey();
|
|
8469
|
+
}
|
|
8470
|
+
}
|
|
8400
8471
|
get captureEnabled() {
|
|
8401
8472
|
return this.isCaptureEnabled();
|
|
8402
8473
|
}
|
|
@@ -8454,14 +8525,16 @@ var Bitfab = class {
|
|
|
8454
8525
|
resultStr = String(executionResult.result);
|
|
8455
8526
|
}
|
|
8456
8527
|
}
|
|
8457
|
-
this.
|
|
8458
|
-
|
|
8459
|
-
|
|
8460
|
-
|
|
8461
|
-
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8528
|
+
if (this.shouldRecord()) {
|
|
8529
|
+
this.httpClient.sendInternalTrace(functionVersion.id, {
|
|
8530
|
+
result: resultStr,
|
|
8531
|
+
source: "typescript-sdk",
|
|
8532
|
+
...Object.keys(inputs).length > 0 && { inputs },
|
|
8533
|
+
...executionResult.rawCollector != null && {
|
|
8534
|
+
rawCollector: executionResult.rawCollector
|
|
8535
|
+
}
|
|
8536
|
+
});
|
|
8537
|
+
}
|
|
8465
8538
|
return executionResult.result;
|
|
8466
8539
|
} catch (error) {
|
|
8467
8540
|
if (error instanceof BitfabError) {
|
|
@@ -8491,11 +8564,10 @@ var Bitfab = class {
|
|
|
8491
8564
|
* @returns A BitfabOpenAITracingProcessor instance configured for this client
|
|
8492
8565
|
*/
|
|
8493
8566
|
getOpenAiTracingProcessor() {
|
|
8567
|
+
this.prepareFrameworkIntegration();
|
|
8494
8568
|
return new BitfabOpenAITracingProcessor({
|
|
8495
|
-
// Resolved at getter-call time (framework handlers are set up after env
|
|
8496
|
-
// loads); the withSpan path stays lazy via the constructor HttpClient thunk.
|
|
8497
|
-
apiKey: this.resolveApiKey(),
|
|
8498
8569
|
serviceUrl: this.serviceUrl,
|
|
8570
|
+
shouldRecord: () => this.shouldRecord(),
|
|
8499
8571
|
getActiveSpanContext: () => {
|
|
8500
8572
|
const stack = getSpanStack();
|
|
8501
8573
|
return stack[stack.length - 1] ?? null;
|
|
@@ -8553,10 +8625,11 @@ var Bitfab = class {
|
|
|
8553
8625
|
* @returns A BitfabLangGraphCallbackHandler configured for this client
|
|
8554
8626
|
*/
|
|
8555
8627
|
getLangGraphCallbackHandler(traceFunctionKey) {
|
|
8628
|
+
this.prepareFrameworkIntegration();
|
|
8556
8629
|
return new BitfabLangGraphCallbackHandler({
|
|
8557
|
-
apiKey: this.resolveApiKey(),
|
|
8558
8630
|
traceFunctionKey,
|
|
8559
8631
|
serviceUrl: this.serviceUrl,
|
|
8632
|
+
shouldRecord: () => this.shouldRecord(),
|
|
8560
8633
|
getActiveSpanContext: () => {
|
|
8561
8634
|
const stack = getSpanStack();
|
|
8562
8635
|
return stack[stack.length - 1] ?? null;
|
|
@@ -8595,10 +8668,11 @@ var Bitfab = class {
|
|
|
8595
8668
|
* @experimental This API may change before it is stable.
|
|
8596
8669
|
*/
|
|
8597
8670
|
getLangGraphIntegration(traceFunctionKey, options) {
|
|
8671
|
+
this.prepareFrameworkIntegration();
|
|
8598
8672
|
const callbackHandler = new BitfabLangGraphCallbackHandler({
|
|
8599
|
-
apiKey: this.resolveApiKey(),
|
|
8600
8673
|
traceFunctionKey,
|
|
8601
8674
|
serviceUrl: this.serviceUrl,
|
|
8675
|
+
shouldRecord: () => this.shouldRecord(),
|
|
8602
8676
|
getActiveSpanContext: () => {
|
|
8603
8677
|
const stack = getSpanStack();
|
|
8604
8678
|
return stack[stack.length - 1] ?? null;
|
|
@@ -8637,10 +8711,11 @@ var Bitfab = class {
|
|
|
8637
8711
|
* @returns A BitfabClaudeAgentHandler configured for this client
|
|
8638
8712
|
*/
|
|
8639
8713
|
getClaudeAgentHandler(traceFunctionKey) {
|
|
8714
|
+
this.prepareFrameworkIntegration();
|
|
8640
8715
|
return new BitfabClaudeAgentHandler({
|
|
8641
|
-
apiKey: this.resolveApiKey(),
|
|
8642
8716
|
traceFunctionKey,
|
|
8643
8717
|
serviceUrl: this.serviceUrl,
|
|
8718
|
+
shouldRecord: () => this.shouldRecord(),
|
|
8644
8719
|
getActiveSpanContext: () => {
|
|
8645
8720
|
const stack = getSpanStack();
|
|
8646
8721
|
return stack[stack.length - 1] ?? null;
|