@bitfab/sdk 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-QEQXIG5A.js → chunk-4LMLPCYL.js} +11 -2
- package/dist/{chunk-QEQXIG5A.js.map → chunk-4LMLPCYL.js.map} +1 -1
- package/dist/{chunk-BXLEJW7C.js → chunk-GJWKOJGJ.js} +3 -3
- package/dist/{chunk-2ZUDLA5T.js → chunk-L4SB4W3Z.js} +90 -24
- package/dist/chunk-L4SB4W3Z.js.map +1 -0
- package/dist/{chunk-P3FTTOAG.js → chunk-LMKQBRSP.js} +11 -2
- package/dist/{chunk-P3FTTOAG.js.map → chunk-LMKQBRSP.js.map} +1 -1
- package/dist/{chunk-2J7QZHRC.js → chunk-M2AEKEZE.js} +2 -2
- package/dist/{http-PJEFWDKR.js → http-3WCRPXRQ.js} +2 -2
- package/dist/{http-KLQ5KEUQ.js → http-JPJBWD5Z.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-YQQHMR5K.js → replay-2JBBAJUG.js} +3 -3
- package/dist/replayCli.js +2 -2
- package/dist/seedCli.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-2ZUDLA5T.js.map +0 -1
- /package/dist/{chunk-BXLEJW7C.js.map → chunk-GJWKOJGJ.js.map} +0 -0
- /package/dist/{chunk-2J7QZHRC.js.map → chunk-M2AEKEZE.js.map} +0 -0
- /package/dist/{http-KLQ5KEUQ.js.map → http-3WCRPXRQ.js.map} +0 -0
- /package/dist/{http-PJEFWDKR.js.map → http-JPJBWD5Z.js.map} +0 -0
- /package/dist/{replay-YQQHMR5K.js.map → replay-2JBBAJUG.js.map} +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
replayContextReady,
|
|
7
7
|
runWithReplayContext,
|
|
8
8
|
warnOnce
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4LMLPCYL.js";
|
|
10
10
|
import {
|
|
11
11
|
runWithCaptureSuppressed
|
|
12
12
|
} from "./chunk-VCRFFCLY.js";
|
|
@@ -1212,4 +1212,4 @@ export {
|
|
|
1212
1212
|
sleepForReplayPersistence,
|
|
1213
1213
|
replay
|
|
1214
1214
|
};
|
|
1215
|
-
//# sourceMappingURL=chunk-
|
|
1215
|
+
//# sourceMappingURL=chunk-M2AEKEZE.js.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
flushTraces,
|
|
7
7
|
parseRetryAfterMs,
|
|
8
8
|
serializePayloadBody
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-LMKQBRSP.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-3WCRPXRQ.js.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
flushTraces,
|
|
7
7
|
parseRetryAfterMs,
|
|
8
8
|
serializePayloadBody
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-4LMLPCYL.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-JPJBWD5Z.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -42,7 +42,7 @@ var __version__, __packageName__;
|
|
|
42
42
|
var init_version_generated = __esm({
|
|
43
43
|
"src/version.generated.ts"() {
|
|
44
44
|
"use strict";
|
|
45
|
-
__version__ = "0.54.
|
|
45
|
+
__version__ = "0.54.8";
|
|
46
46
|
__packageName__ = "@bitfab/sdk";
|
|
47
47
|
}
|
|
48
48
|
});
|
|
@@ -2313,6 +2313,15 @@ var init_http = __esm({
|
|
|
2313
2313
|
resolveApiKey() {
|
|
2314
2314
|
return typeof this.apiKey === "function" ? this.apiKey() : this.apiKey;
|
|
2315
2315
|
}
|
|
2316
|
+
/** @internal Whether this client currently has credentials for trace delivery. */
|
|
2317
|
+
hasApiKey() {
|
|
2318
|
+
try {
|
|
2319
|
+
const apiKey = this.resolveApiKey();
|
|
2320
|
+
return apiKey !== void 0 && apiKey.trim() !== "";
|
|
2321
|
+
} catch {
|
|
2322
|
+
return false;
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2316
2325
|
/**
|
|
2317
2326
|
* This client's span transport, built on first use.
|
|
2318
2327
|
*
|
|
@@ -4490,6 +4499,7 @@ var BitfabClaudeAgentHandler = class {
|
|
|
4490
4499
|
});
|
|
4491
4500
|
this.traceFunctionKey = config.traceFunctionKey;
|
|
4492
4501
|
this.getActiveSpanContext = config.getActiveSpanContext ?? null;
|
|
4502
|
+
this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
|
|
4493
4503
|
this.preToolUseHook = this.preToolUseHook.bind(this);
|
|
4494
4504
|
this.postToolUseHook = this.postToolUseHook.bind(this);
|
|
4495
4505
|
this.postToolUseFailureHook = this.postToolUseFailureHook.bind(this);
|
|
@@ -4594,6 +4604,9 @@ var BitfabClaudeAgentHandler = class {
|
|
|
4594
4604
|
this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
|
|
4595
4605
|
}
|
|
4596
4606
|
sendSpan(spanInfo) {
|
|
4607
|
+
if (!this.shouldRecord()) {
|
|
4608
|
+
return;
|
|
4609
|
+
}
|
|
4597
4610
|
const spanData = {
|
|
4598
4611
|
name: spanInfo.name,
|
|
4599
4612
|
type: spanInfo.type
|
|
@@ -4637,6 +4650,9 @@ var BitfabClaudeAgentHandler = class {
|
|
|
4637
4650
|
}
|
|
4638
4651
|
}
|
|
4639
4652
|
sendTraceCompletion(endedAt, metadata) {
|
|
4653
|
+
if (!this.shouldRecord()) {
|
|
4654
|
+
return;
|
|
4655
|
+
}
|
|
4640
4656
|
if (this.traceId === null) {
|
|
4641
4657
|
return;
|
|
4642
4658
|
}
|
|
@@ -6178,6 +6194,7 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
6178
6194
|
});
|
|
6179
6195
|
this.traceFunctionKey = config.traceFunctionKey;
|
|
6180
6196
|
this.getActiveSpanContext = config.getActiveSpanContext ?? null;
|
|
6197
|
+
this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
|
|
6181
6198
|
this.captureTools = config.captureTools ?? true;
|
|
6182
6199
|
}
|
|
6183
6200
|
/**
|
|
@@ -6286,6 +6303,9 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
6286
6303
|
this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
|
|
6287
6304
|
}
|
|
6288
6305
|
sendSpan(spanInfo) {
|
|
6306
|
+
if (!this.shouldRecord()) {
|
|
6307
|
+
return;
|
|
6308
|
+
}
|
|
6289
6309
|
const spanData = {
|
|
6290
6310
|
name: spanInfo.name,
|
|
6291
6311
|
type: spanInfo.type
|
|
@@ -6329,6 +6349,9 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
6329
6349
|
}
|
|
6330
6350
|
}
|
|
6331
6351
|
sendTraceCompletion(rootSpan, activeContext) {
|
|
6352
|
+
if (!this.shouldRecord()) {
|
|
6353
|
+
return;
|
|
6354
|
+
}
|
|
6332
6355
|
const completed = activeContext === null;
|
|
6333
6356
|
const traceData = {
|
|
6334
6357
|
id: rootSpan.traceId,
|
|
@@ -6349,6 +6372,9 @@ var BitfabLangGraphCallbackHandler = class {
|
|
|
6349
6372
|
}
|
|
6350
6373
|
}
|
|
6351
6374
|
sendTraceStart(rootSpan) {
|
|
6375
|
+
if (!this.shouldRecord()) {
|
|
6376
|
+
return;
|
|
6377
|
+
}
|
|
6352
6378
|
const traceData = {
|
|
6353
6379
|
id: rootSpan.traceId,
|
|
6354
6380
|
type: "sdk-function",
|
|
@@ -7057,6 +7083,7 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7057
7083
|
timeout: config.timeout ?? 1e4
|
|
7058
7084
|
});
|
|
7059
7085
|
this.getActiveSpanContext = config.getActiveSpanContext ?? null;
|
|
7086
|
+
this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
|
|
7060
7087
|
}
|
|
7061
7088
|
getCanonicalTraceId(sourceTraceId) {
|
|
7062
7089
|
const existing = this.canonicalTraceIds[sourceTraceId];
|
|
@@ -7177,6 +7204,9 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7177
7204
|
* the OpenAI trace into an outer withSpan trace.
|
|
7178
7205
|
*/
|
|
7179
7206
|
sendTrace(trace, options = {}) {
|
|
7207
|
+
if (!this.shouldRecord()) {
|
|
7208
|
+
return;
|
|
7209
|
+
}
|
|
7180
7210
|
try {
|
|
7181
7211
|
const traceData = trace.toJSON();
|
|
7182
7212
|
if (options.sourceTraceId) {
|
|
@@ -7291,6 +7321,9 @@ var BitfabOpenAITracingProcessor = class {
|
|
|
7291
7321
|
* and parent_id are rewritten to link the span into the withSpan tree.
|
|
7292
7322
|
*/
|
|
7293
7323
|
sendSpan(span) {
|
|
7324
|
+
if (!this.shouldRecord()) {
|
|
7325
|
+
return;
|
|
7326
|
+
}
|
|
7294
7327
|
const errors = [];
|
|
7295
7328
|
const [serializedSpan, exportErrors] = this.exportSpan(span);
|
|
7296
7329
|
errors.push(...exportErrors);
|
|
@@ -7860,6 +7893,30 @@ function readEnv2(name) {
|
|
|
7860
7893
|
}
|
|
7861
7894
|
return void 0;
|
|
7862
7895
|
}
|
|
7896
|
+
var CAPTURE_ENABLED_ENV = "BITFAB_CAPTURE_ENABLED";
|
|
7897
|
+
var TRUE_ENV_VALUES = /* @__PURE__ */ new Set(["1", "true", "yes"]);
|
|
7898
|
+
var FALSE_ENV_VALUES = /* @__PURE__ */ new Set(["0", "false", "no"]);
|
|
7899
|
+
function readBooleanEnv(name) {
|
|
7900
|
+
const raw = readEnv2(name);
|
|
7901
|
+
if (raw === void 0) {
|
|
7902
|
+
return void 0;
|
|
7903
|
+
}
|
|
7904
|
+
const value = raw.trim().toLowerCase();
|
|
7905
|
+
if (value === "") {
|
|
7906
|
+
return void 0;
|
|
7907
|
+
}
|
|
7908
|
+
if (TRUE_ENV_VALUES.has(value)) {
|
|
7909
|
+
return true;
|
|
7910
|
+
}
|
|
7911
|
+
if (FALSE_ENV_VALUES.has(value)) {
|
|
7912
|
+
return false;
|
|
7913
|
+
}
|
|
7914
|
+
warnOnce(
|
|
7915
|
+
`unrecognized-boolean-env:${name}`,
|
|
7916
|
+
`${name}="${raw}" is not 0 or 1; ignoring it.`
|
|
7917
|
+
);
|
|
7918
|
+
return void 0;
|
|
7919
|
+
}
|
|
7863
7920
|
var DEFAULT_AUTO_TRACE_MAX_DEPTH = 30;
|
|
7864
7921
|
var DEFAULT_AUTO_TRACE_MAX_SPANS = 500;
|
|
7865
7922
|
var AUTO_TRACE_PROTOCOL = "ts-auto-v1";
|
|
@@ -7914,7 +7971,7 @@ var Bitfab = class {
|
|
|
7914
7971
|
"Bitfab({ enabled }) is deprecated; pass captureEnabled instead."
|
|
7915
7972
|
);
|
|
7916
7973
|
}
|
|
7917
|
-
this.
|
|
7974
|
+
this.captureConfiguredInCode = config.captureEnabled === void 0 && config.enabled === void 0 ? void 0 : (config.captureEnabled ?? true) && (config.enabled ?? true);
|
|
7918
7975
|
this.strict = config.strict ?? false;
|
|
7919
7976
|
this.bamlClient = config.bamlClient ?? null;
|
|
7920
7977
|
if (config.dbSnapshot) {
|
|
@@ -8368,7 +8425,7 @@ var Bitfab = class {
|
|
|
8368
8425
|
"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`."
|
|
8369
8426
|
);
|
|
8370
8427
|
}
|
|
8371
|
-
if (this.
|
|
8428
|
+
if (this.isCaptureConfigured() && !this.apiKeyWarned) {
|
|
8372
8429
|
this.apiKeyWarned = true;
|
|
8373
8430
|
console.warn(
|
|
8374
8431
|
"Bitfab: apiKey is empty - tracing is disabled. Provide a valid API key to enable tracing."
|
|
@@ -8376,18 +8433,32 @@ var Bitfab = class {
|
|
|
8376
8433
|
}
|
|
8377
8434
|
return void 0;
|
|
8378
8435
|
}
|
|
8436
|
+
isCaptureConfigured() {
|
|
8437
|
+
if (this.captureConfiguredInCode !== void 0) {
|
|
8438
|
+
return this.captureConfiguredInCode;
|
|
8439
|
+
}
|
|
8440
|
+
if (this.captureConfiguredFromEnv === void 0) {
|
|
8441
|
+
this.captureConfiguredFromEnv = readBooleanEnv(CAPTURE_ENABLED_ENV) ?? true;
|
|
8442
|
+
}
|
|
8443
|
+
return this.captureConfiguredFromEnv;
|
|
8444
|
+
}
|
|
8379
8445
|
isCaptureEnabled() {
|
|
8380
|
-
if (!this.
|
|
8446
|
+
if (!this.isCaptureConfigured()) {
|
|
8381
8447
|
return false;
|
|
8382
8448
|
}
|
|
8383
8449
|
return this.resolveApiKey() !== void 0;
|
|
8384
8450
|
}
|
|
8385
8451
|
shouldRecord() {
|
|
8386
|
-
if (!this.
|
|
8452
|
+
if (!this.isCaptureConfigured() && !getReplayContext() && !inSeedScope()) {
|
|
8387
8453
|
return false;
|
|
8388
8454
|
}
|
|
8389
8455
|
return this.resolveApiKey() !== void 0;
|
|
8390
8456
|
}
|
|
8457
|
+
prepareFrameworkIntegration() {
|
|
8458
|
+
if (this.isCaptureConfigured() && this.strict) {
|
|
8459
|
+
this.resolveApiKey();
|
|
8460
|
+
}
|
|
8461
|
+
}
|
|
8391
8462
|
get captureEnabled() {
|
|
8392
8463
|
return this.isCaptureEnabled();
|
|
8393
8464
|
}
|
|
@@ -8445,14 +8516,16 @@ var Bitfab = class {
|
|
|
8445
8516
|
resultStr = String(executionResult.result);
|
|
8446
8517
|
}
|
|
8447
8518
|
}
|
|
8448
|
-
this.
|
|
8449
|
-
|
|
8450
|
-
|
|
8451
|
-
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8519
|
+
if (this.shouldRecord()) {
|
|
8520
|
+
this.httpClient.sendInternalTrace(functionVersion.id, {
|
|
8521
|
+
result: resultStr,
|
|
8522
|
+
source: "typescript-sdk",
|
|
8523
|
+
...Object.keys(inputs).length > 0 && { inputs },
|
|
8524
|
+
...executionResult.rawCollector != null && {
|
|
8525
|
+
rawCollector: executionResult.rawCollector
|
|
8526
|
+
}
|
|
8527
|
+
});
|
|
8528
|
+
}
|
|
8456
8529
|
return executionResult.result;
|
|
8457
8530
|
} catch (error) {
|
|
8458
8531
|
if (error instanceof BitfabError) {
|
|
@@ -8482,11 +8555,10 @@ var Bitfab = class {
|
|
|
8482
8555
|
* @returns A BitfabOpenAITracingProcessor instance configured for this client
|
|
8483
8556
|
*/
|
|
8484
8557
|
getOpenAiTracingProcessor() {
|
|
8558
|
+
this.prepareFrameworkIntegration();
|
|
8485
8559
|
return new BitfabOpenAITracingProcessor({
|
|
8486
|
-
// Resolved at getter-call time (framework handlers are set up after env
|
|
8487
|
-
// loads); the withSpan path stays lazy via the constructor HttpClient thunk.
|
|
8488
|
-
apiKey: this.resolveApiKey(),
|
|
8489
8560
|
serviceUrl: this.serviceUrl,
|
|
8561
|
+
shouldRecord: () => this.shouldRecord(),
|
|
8490
8562
|
getActiveSpanContext: () => {
|
|
8491
8563
|
const stack = getSpanStack();
|
|
8492
8564
|
return stack[stack.length - 1] ?? null;
|
|
@@ -8544,10 +8616,11 @@ var Bitfab = class {
|
|
|
8544
8616
|
* @returns A BitfabLangGraphCallbackHandler configured for this client
|
|
8545
8617
|
*/
|
|
8546
8618
|
getLangGraphCallbackHandler(traceFunctionKey) {
|
|
8619
|
+
this.prepareFrameworkIntegration();
|
|
8547
8620
|
return new BitfabLangGraphCallbackHandler({
|
|
8548
|
-
apiKey: this.resolveApiKey(),
|
|
8549
8621
|
traceFunctionKey,
|
|
8550
8622
|
serviceUrl: this.serviceUrl,
|
|
8623
|
+
shouldRecord: () => this.shouldRecord(),
|
|
8551
8624
|
getActiveSpanContext: () => {
|
|
8552
8625
|
const stack = getSpanStack();
|
|
8553
8626
|
return stack[stack.length - 1] ?? null;
|
|
@@ -8586,10 +8659,11 @@ var Bitfab = class {
|
|
|
8586
8659
|
* @experimental This API may change before it is stable.
|
|
8587
8660
|
*/
|
|
8588
8661
|
getLangGraphIntegration(traceFunctionKey, options) {
|
|
8662
|
+
this.prepareFrameworkIntegration();
|
|
8589
8663
|
const callbackHandler = new BitfabLangGraphCallbackHandler({
|
|
8590
|
-
apiKey: this.resolveApiKey(),
|
|
8591
8664
|
traceFunctionKey,
|
|
8592
8665
|
serviceUrl: this.serviceUrl,
|
|
8666
|
+
shouldRecord: () => this.shouldRecord(),
|
|
8593
8667
|
getActiveSpanContext: () => {
|
|
8594
8668
|
const stack = getSpanStack();
|
|
8595
8669
|
return stack[stack.length - 1] ?? null;
|
|
@@ -8628,10 +8702,11 @@ var Bitfab = class {
|
|
|
8628
8702
|
* @returns A BitfabClaudeAgentHandler configured for this client
|
|
8629
8703
|
*/
|
|
8630
8704
|
getClaudeAgentHandler(traceFunctionKey) {
|
|
8705
|
+
this.prepareFrameworkIntegration();
|
|
8631
8706
|
return new BitfabClaudeAgentHandler({
|
|
8632
|
-
apiKey: this.resolveApiKey(),
|
|
8633
8707
|
traceFunctionKey,
|
|
8634
8708
|
serviceUrl: this.serviceUrl,
|
|
8709
|
+
shouldRecord: () => this.shouldRecord(),
|
|
8635
8710
|
getActiveSpanContext: () => {
|
|
8636
8711
|
const stack = getSpanStack();
|
|
8637
8712
|
return stack[stack.length - 1] ?? null;
|