bitfab 0.57.5 → 0.57.7

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.
Files changed (33) hide show
  1. package/dist/{chunk-I5EG523G.js → chunk-IYGYSMSD.js} +3 -3
  2. package/dist/{chunk-WYNN6NY2.js → chunk-NRUFN7RZ.js} +26 -13
  3. package/dist/chunk-NRUFN7RZ.js.map +1 -0
  4. package/dist/{chunk-255I4PN4.js → chunk-P4R3NY2U.js} +36 -16
  5. package/dist/chunk-P4R3NY2U.js.map +1 -0
  6. package/dist/{chunk-VPZ2LTU6.js → chunk-VPU6U4WM.js} +2 -2
  7. package/dist/{chunk-YO3HKQX6.js → chunk-W3HLGZBO.js} +137 -67
  8. package/dist/chunk-W3HLGZBO.js.map +1 -0
  9. package/dist/{http-FQ76VRFF.js → http-AFLRC33F.js} +2 -2
  10. package/dist/{http-CHXMOVLK.js → http-ODKUB6M4.js} +2 -2
  11. package/dist/index.cjs +166 -77
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +125 -127
  14. package/dist/index.d.ts +125 -127
  15. package/dist/index.js +3 -5
  16. package/dist/node.cjs +166 -77
  17. package/dist/node.cjs.map +1 -1
  18. package/dist/node.d.cts +1 -1
  19. package/dist/node.d.ts +1 -1
  20. package/dist/node.js +3 -5
  21. package/dist/node.js.map +1 -1
  22. package/dist/{replay-CHM7OQ25.js → replay-2VGODDLA.js} +3 -3
  23. package/dist/replayCli.js +2 -2
  24. package/dist/seedCli.js +2 -2
  25. package/package.json +1 -1
  26. package/dist/chunk-255I4PN4.js.map +0 -1
  27. package/dist/chunk-WYNN6NY2.js.map +0 -1
  28. package/dist/chunk-YO3HKQX6.js.map +0 -1
  29. /package/dist/{chunk-I5EG523G.js.map → chunk-IYGYSMSD.js.map} +0 -0
  30. /package/dist/{chunk-VPZ2LTU6.js.map → chunk-VPU6U4WM.js.map} +0 -0
  31. /package/dist/{http-CHXMOVLK.js.map → http-AFLRC33F.js.map} +0 -0
  32. /package/dist/{http-FQ76VRFF.js.map → http-ODKUB6M4.js.map} +0 -0
  33. /package/dist/{replay-CHM7OQ25.js.map → replay-2VGODDLA.js.map} +0 -0
@@ -17,7 +17,7 @@ import {
17
17
  serializeValue,
18
18
  toJsonSafe,
19
19
  toJsonSafeReport
20
- } from "./chunk-VPZ2LTU6.js";
20
+ } from "./chunk-VPU6U4WM.js";
21
21
  import {
22
22
  BitfabError,
23
23
  CONTENT_OFF_KEY,
@@ -37,7 +37,7 @@ import {
37
37
  retireTraceMetadata,
38
38
  traceIdOf,
39
39
  warnOnce
40
- } from "./chunk-255I4PN4.js";
40
+ } from "./chunk-P4R3NY2U.js";
41
41
  import {
42
42
  __privateAdd,
43
43
  __privateGet,
@@ -296,6 +296,11 @@ var BitfabClaudeAgentHandler = class {
296
296
  }
297
297
  this.runToSpan.set(spanId, spanInfo);
298
298
  this.httpClient.traceCompletion.start(spanInfo.traceId, spanInfo.spanId);
299
+ this.httpClient.reserveFrameworkSpan(
300
+ spanInfo.traceId,
301
+ spanInfo.spanId,
302
+ spanInfo.parentId
303
+ );
299
304
  return spanInfo;
300
305
  }
301
306
  completeSpan(spanId, output, error, extraContexts) {
@@ -575,6 +580,11 @@ var BitfabClaudeAgentHandler = class {
575
580
  this.conversationHistory.push(...this.pendingMessages);
576
581
  this.pendingMessages = [];
577
582
  this.currentLlmSpanId = randomUuid();
583
+ this.httpClient.reserveFrameworkSpan(
584
+ this.ensureTrace(),
585
+ this.currentLlmSpanId,
586
+ this.getParentId()
587
+ );
578
588
  this.currentLlmMessageId = messageId ?? null;
579
589
  this.currentLlmContent = [];
580
590
  this.currentLlmModel = inner.model ?? null;
@@ -1453,6 +1463,9 @@ var GradersClient = class {
1453
1463
  // src/labels.ts
1454
1464
  var LABELS_PATH = "/api/sdk/traces/labels";
1455
1465
  var HUMAN_LABELS_PATH = "/api/sdk/traces/labels/human";
1466
+ function labelEvidencePath(traceId, assertionId) {
1467
+ return `/api/sdk/traces/${encodeURIComponent(traceId)}/assertions/${encodeURIComponent(assertionId)}/evidence`;
1468
+ }
1456
1469
  var LabelsClient = class {
1457
1470
  constructor(httpClient) {
1458
1471
  this.httpClient = httpClient;
@@ -1501,6 +1514,11 @@ var LabelsClient = class {
1501
1514
  );
1502
1515
  return response.labels;
1503
1516
  }
1517
+ /** Generate suggested evidence for an assertion on an original or replay trace. */
1518
+ async generateLabelEvidence(traceId, assertionId) {
1519
+ const response = await this.httpClient.get(labelEvidencePath(traceId, assertionId));
1520
+ return response.evidence;
1521
+ }
1504
1522
  };
1505
1523
 
1506
1524
  // src/langgraph.ts
@@ -1807,6 +1825,11 @@ var BitfabLangGraphCallbackHandler = class {
1807
1825
  this.runToSpan.set(runId, spanInfo);
1808
1826
  if (spanInfo.hidden !== true) {
1809
1827
  this.httpClient.traceCompletion.start(spanInfo.traceId, spanInfo.spanId);
1828
+ this.httpClient.reserveFrameworkSpan(
1829
+ spanInfo.traceId,
1830
+ spanInfo.spanId,
1831
+ spanInfo.parentId
1832
+ );
1810
1833
  }
1811
1834
  if (isRootInvocation) {
1812
1835
  this.sendTraceStart(spanInfo);
@@ -3185,23 +3208,9 @@ var SEARCH_PATH = "/api/sdk/traces/search";
3185
3208
  function traceAssertionsPath(traceId, suffix = "") {
3186
3209
  return `/api/sdk/traces/${encodeURIComponent(traceId)}/assertions${suffix}`;
3187
3210
  }
3188
- function assertionEvidencePath(assertionId) {
3189
- return `/api/sdk/traces/assertions/${encodeURIComponent(assertionId)}/evidence`;
3190
- }
3191
- var TraceAssertionsClient = class {
3192
- constructor(httpClient) {
3193
- this.httpClient = httpClient;
3194
- }
3195
- /** Suggest evidence for an assertion, enriched with its span context. */
3196
- async getAssertionEvidence(assertionId) {
3197
- const response = await this.httpClient.get(assertionEvidencePath(assertionId));
3198
- return response.evidence;
3199
- }
3200
- };
3201
3211
  var TracesClient = class {
3202
3212
  constructor(httpClient) {
3203
3213
  this.httpClient = httpClient;
3204
- this.assertions = new TraceAssertionsClient(httpClient);
3205
3214
  }
3206
3215
  async search(params) {
3207
3216
  return this.httpClient.request(SEARCH_PATH, params);
@@ -3337,8 +3346,14 @@ var BitfabOpenAITracingProcessor = class {
3337
3346
  async onSpanStart(span) {
3338
3347
  if (span.spanId !== void 0 && span.traceId !== null && span.traceId !== void 0) {
3339
3348
  this.startedSpans.set(span.spanId, span.traceId);
3340
- const traceId = this.activeSpanMappings[span.traceId]?.traceId ?? span.traceId;
3349
+ const mapping = this.activeSpanMappings[span.traceId];
3350
+ const traceId = mapping?.traceId ?? span.traceId;
3341
3351
  this.httpClient.traceCompletion.start(traceId, span.spanId);
3352
+ this.httpClient.reserveFrameworkSpan(
3353
+ traceId,
3354
+ span.spanId,
3355
+ span.parentId ?? mapping?.spanId
3356
+ );
3342
3357
  }
3343
3358
  }
3344
3359
  /**
@@ -3724,22 +3739,68 @@ var BitfabVercelAiHandler = class {
3724
3739
  };
3725
3740
 
3726
3741
  // src/client.ts
3742
+ var TRUNCATION_LIMIT_ORDER = [
3743
+ "max_depth",
3744
+ "max_spans",
3745
+ "max_captured_subtree_spans"
3746
+ ];
3727
3747
  var activeTraceStates = /* @__PURE__ */ new Map();
3728
- function fitsTraceSpanBudget(payload) {
3729
- if (!recordedByFramework(payload)) {
3730
- return true;
3748
+ var REFUSED_FRAMEWORK_SPAN_TRACES_RETAINED = 1024;
3749
+ var refusedFrameworkSpans = /* @__PURE__ */ new Map();
3750
+ function frameworkSpanRefused(traceId, spanId) {
3751
+ return refusedFrameworkSpans.get(traceId)?.has(spanId) === true;
3752
+ }
3753
+ function refuseFrameworkSpan(traceId, spanId) {
3754
+ const refused = refusedFrameworkSpans.get(traceId);
3755
+ if (refused !== void 0) {
3756
+ refused.add(spanId);
3757
+ return;
3731
3758
  }
3732
- const traceId = traceIdOf(payload);
3733
- const spanBudget = traceId === void 0 ? void 0 : activeTraceStates.get(traceId)?.spanBudget;
3734
- if (spanBudget === void 0) {
3735
- return true;
3759
+ refusedFrameworkSpans.set(traceId, /* @__PURE__ */ new Set([spanId]));
3760
+ while (refusedFrameworkSpans.size > REFUSED_FRAMEWORK_SPAN_TRACES_RETAINED) {
3761
+ const oldest = refusedFrameworkSpans.keys().next();
3762
+ if (oldest.done) {
3763
+ return;
3764
+ }
3765
+ refusedFrameworkSpans.delete(oldest.value);
3766
+ }
3767
+ }
3768
+ function reserveFrameworkSpan(traceId, spanId, parentSpanId) {
3769
+ const spanBudget = activeTraceStates.get(traceId)?.spanBudget;
3770
+ const parentRefused = parentSpanId !== null && frameworkSpanRefused(traceId, parentSpanId);
3771
+ if (!parentRefused && (spanBudget === void 0 || spanBudget.spansUsed < spanBudget.maxSpans)) {
3772
+ if (spanBudget !== void 0) {
3773
+ spanBudget.spansUsed += 1;
3774
+ }
3775
+ return;
3736
3776
  }
3737
- if (spanBudget.spansUsed >= spanBudget.maxSpans) {
3738
- spanBudget.truncate();
3777
+ refuseFrameworkSpan(traceId, spanId);
3778
+ spanBudget?.truncate("max_spans");
3779
+ }
3780
+ function isRefusedFrameworkSpan(payload) {
3781
+ if (!recordedByFramework(payload)) {
3782
+ return false;
3783
+ }
3784
+ const rawSpan = payload.rawSpan;
3785
+ const spanId = rawSpan?.id;
3786
+ if (typeof spanId !== "string") {
3739
3787
  return false;
3740
3788
  }
3741
- spanBudget.spansUsed += 1;
3742
- return true;
3789
+ const traceIds = [payload.sourceTraceId, traceIdOf(payload)];
3790
+ return traceIds.some(
3791
+ (traceId) => typeof traceId === "string" && frameworkSpanRefused(traceId, spanId)
3792
+ );
3793
+ }
3794
+ function truncationMetadata(truncation) {
3795
+ if (truncation === void 0 || truncation.limits.size === 0) {
3796
+ return void 0;
3797
+ }
3798
+ return {
3799
+ "bitfab.truncated_by": TRUNCATION_LIMIT_ORDER.filter(
3800
+ (limit) => truncation.limits.has(limit)
3801
+ ).join(","),
3802
+ "bitfab.dropped_spans": truncation.droppedSpans
3803
+ };
3743
3804
  }
3744
3805
  function rootTraceFunctionKeyOfTrace(traceId, fallback) {
3745
3806
  return activeTraceStates.get(traceId)?.traceFunctionKey ?? fallback;
@@ -4121,7 +4182,6 @@ function readBooleanEnv(name) {
4121
4182
  var DEFAULT_AUTO_TRACE_MAX_DEPTH = 30;
4122
4183
  var DEFAULT_AUTO_TRACE_MAX_SPANS = 2048;
4123
4184
  var DEFAULT_AUTO_TRACE_MAX_CAPTURED_SUBTREE_SPANS = 512;
4124
- var AUTO_TRACE_PROTOCOL = "ts-auto-v1";
4125
4185
  function spanOwnerName(receiver) {
4126
4186
  if (typeof receiver === "function") {
4127
4187
  return receiver.name !== "" ? receiver.name : void 0;
@@ -4187,7 +4247,8 @@ var Bitfab = class {
4187
4247
  this.httpClient,
4188
4248
  config.simulationPlan ?? true
4189
4249
  );
4190
- this.httpClient.externalSpanTransform = (payload, submit) => this.applySimulationPlan(payload, submit);
4250
+ this.httpClient.externalSpanTransform = (payload, submit, drop) => this.applySimulationPlan(payload, submit, drop);
4251
+ this.httpClient.frameworkSpanStart = reserveFrameworkSpan;
4191
4252
  this.httpClient.externalTraceTransform = (payload, submit) => this.simulationPlan.sendTrace(payload, submit);
4192
4253
  this.httpClient.releaseHeldExternalSpans = (timeoutMs) => this.simulationPlan.release(timeoutMs);
4193
4254
  this.httpClient.stopSimulationPlan = () => this.simulationPlan.stop();
@@ -4383,35 +4444,31 @@ var Bitfab = class {
4383
4444
  function(...args) {
4384
4445
  self.simulationPlan.refresh();
4385
4446
  let capturedSubtreeCount = 0;
4386
- let truncated = false;
4387
- const warnTruncated = () => {
4388
- if (!truncated) {
4389
- truncated = true;
4390
- getCurrentTrace().setMetadata({
4391
- bitfabAutoTrace: {
4392
- protocol: AUTO_TRACE_PROTOCOL,
4393
- truncated: true,
4394
- maxDepth,
4395
- maxSpans,
4396
- maxCapturedSubtreeSpans
4397
- }
4398
- });
4399
- }
4447
+ const rootSpanStack = getSpanStack();
4448
+ const rootSpan = rootSpanStack[rootSpanStack.length - 1];
4449
+ const rootTraceState = rootSpan === void 0 ? void 0 : activeTraceStates.get(rootSpan.traceId);
4450
+ const truncation = rootTraceState?.truncation ?? {
4451
+ limits: /* @__PURE__ */ new Set(),
4452
+ droppedSpans: 0
4453
+ };
4454
+ const truncate = (limit) => {
4455
+ truncation.limits.add(limit);
4456
+ truncation.droppedSpans += 1;
4400
4457
  warnOnce(
4401
4458
  `auto-trace-truncated:${traceFunctionKey}`,
4402
4459
  `"${traceFunctionKey}" hit an automatic subtree capture limit (maxDepth=${maxDepth}, maxCapturedSubtreeSpans=${maxCapturedSubtreeSpans}, maxSpans=${maxSpans}); its trace is incomplete. Raise the limits, declare the calls you need with node(), or narrow the subtree with exclude.`
4403
4460
  );
4404
4461
  };
4405
- const rootSpanStack = getSpanStack();
4406
4462
  const spanBudget = {
4407
4463
  spansUsed: 1,
4408
4464
  maxSpans,
4409
- truncate: () => runWithSpanStack(rootSpanStack, warnTruncated)
4465
+ truncate
4410
4466
  };
4411
- const rootSpan = rootSpanStack[rootSpanStack.length - 1];
4412
- const rootTraceState = rootSpan === void 0 ? void 0 : activeTraceStates.get(rootSpan.traceId);
4413
- if (rootTraceState !== void 0 && rootTraceState.spanBudget === void 0) {
4414
- rootTraceState.spanBudget = spanBudget;
4467
+ if (rootTraceState !== void 0) {
4468
+ rootTraceState.truncation = truncation;
4469
+ if (rootTraceState.spanBudget === void 0) {
4470
+ rootTraceState.spanBudget = spanBudget;
4471
+ }
4415
4472
  }
4416
4473
  const spanStackOf = (entry) => entry.spanStack;
4417
4474
  const openChild = (entry, childOptions, inputs, isAsync, invokeFn) => {
@@ -4451,15 +4508,16 @@ var Bitfab = class {
4451
4508
  rootTraceFunctionKeyOfEntry(entry),
4452
4509
  spanName
4453
4510
  );
4454
- if (entry.depth < maxDepth && spanBudget.spansUsed < maxSpans && (!countsTowardCapturedSubtree || capturedSubtreeCount < maxCapturedSubtreeSpans)) {
4455
- spanBudget.spansUsed += 1;
4456
- if (countsTowardCapturedSubtree) {
4457
- capturedSubtreeCount += 1;
4458
- }
4459
- return true;
4511
+ const refusedBy = entry.depth >= maxDepth ? "max_depth" : spanBudget.spansUsed >= maxSpans ? "max_spans" : countsTowardCapturedSubtree && capturedSubtreeCount >= maxCapturedSubtreeSpans ? "max_captured_subtree_spans" : void 0;
4512
+ if (refusedBy !== void 0) {
4513
+ truncate(refusedBy);
4514
+ return false;
4515
+ }
4516
+ spanBudget.spansUsed += 1;
4517
+ if (countsTowardCapturedSubtree) {
4518
+ capturedSubtreeCount += 1;
4460
4519
  }
4461
- runWithSpanStack(spanStackOf(entry), warnTruncated);
4462
- return false;
4520
+ return true;
4463
4521
  };
4464
4522
  const autoTraceContext = {
4465
4523
  traceFunctionKey,
@@ -4586,11 +4644,17 @@ var Bitfab = class {
4586
4644
  Object.defineProperty(autoTraceRoot, "_bitfabWrappedFn", { value: fn });
4587
4645
  return autoTraceRoot;
4588
4646
  }
4589
- applySimulationPlan(payload, submit) {
4590
- if (!fitsTraceSpanBudget(payload)) {
4647
+ applySimulationPlan(payload, submit, drop) {
4648
+ if (isRefusedFrameworkSpan(payload)) {
4649
+ drop();
4591
4650
  return;
4592
4651
  }
4593
- this.simulationPlan.send(payload, rootTraceFunctionKeyOf(payload), submit);
4652
+ this.simulationPlan.send(
4653
+ payload,
4654
+ rootTraceFunctionKeyOf(payload),
4655
+ submit,
4656
+ drop
4657
+ );
4594
4658
  }
4595
4659
  /**
4596
4660
  * Flush and permanently close this client's tracing resources: its pending
@@ -5259,6 +5323,9 @@ var Bitfab = class {
5259
5323
  registeredTraceId = traceId;
5260
5324
  }
5261
5325
  self.httpClient.traceCompletion.start(traceId, spanId);
5326
+ if (isFrameworkInstrumentation(options.instrumentation)) {
5327
+ reserveFrameworkSpan(traceId, spanId, parentSpanId);
5328
+ }
5262
5329
  startedSpan = { traceId, spanId };
5263
5330
  const functionName = fn.name !== "" ? fn.name : void 0;
5264
5331
  const rootTraceFunctionKey = rootTraceFunctionKeyOfTrace(
@@ -5303,6 +5370,10 @@ var Bitfab = class {
5303
5370
  }
5304
5371
  if (isRootSpan) {
5305
5372
  const traceState = activeTraceStates.get(traceId);
5373
+ const truncated = truncationMetadata(traceState?.truncation);
5374
+ if (truncated !== void 0) {
5375
+ recordCallerTraceMetadata(traceId, truncated);
5376
+ }
5306
5377
  self.sendTraceCompletion({
5307
5378
  traceFunctionKey,
5308
5379
  traceId,
@@ -5855,7 +5926,7 @@ var Bitfab = class {
5855
5926
  ...params.captureContent && params.contexts && params.contexts.length > 0 && {
5856
5927
  contexts: params.contexts
5857
5928
  },
5858
- ...params.captureContent && params.prompt !== void 0 && { prompt: params.prompt },
5929
+ ...buildsContent && params.prompt !== void 0 && { prompt: params.prompt },
5859
5930
  ...contentOff && { [CONTENT_OFF_KEY]: true }
5860
5931
  }
5861
5932
  };
@@ -6022,7 +6093,7 @@ var Bitfab = class {
6022
6093
  await runWithSeedContext({ traceId }, async () => target(...args));
6023
6094
  } finally {
6024
6095
  try {
6025
- const { flushTraces: flushTraces2 } = await import("./http-CHXMOVLK.js");
6096
+ const { flushTraces: flushTraces2 } = await import("./http-ODKUB6M4.js");
6026
6097
  await flushTraces2(3e4);
6027
6098
  } finally {
6028
6099
  unrecorded = activeTraceStates.delete(traceId);
@@ -6081,7 +6152,7 @@ var Bitfab = class {
6081
6152
  `Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
6082
6153
  );
6083
6154
  }
6084
- const { replay: doReplay } = await import("./replay-CHM7OQ25.js");
6155
+ const { replay: doReplay } = await import("./replay-2VGODDLA.js");
6085
6156
  return doReplay(
6086
6157
  this.httpClient,
6087
6158
  this.serviceUrl,
@@ -6401,7 +6472,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
6401
6472
  sessionId: seedCase.sessionId
6402
6473
  })
6403
6474
  );
6404
- const { flushTraces: flushTraces2 } = await import("./http-CHXMOVLK.js");
6475
+ const { flushTraces: flushTraces2 } = await import("./http-ODKUB6M4.js");
6405
6476
  await flushTraces2(3e4);
6406
6477
  return { pipeline, traceFunctionKey, traceIds };
6407
6478
  }
@@ -6427,7 +6498,6 @@ export {
6427
6498
  BitfabLangGraphIntegration,
6428
6499
  BitfabOpenAIAgentHandler,
6429
6500
  BitfabRivetIntegration,
6430
- TraceAssertionsClient,
6431
6501
  TracesClient,
6432
6502
  BitfabOpenAITracingProcessor,
6433
6503
  BitfabVercelAiHandler,
@@ -6441,4 +6511,4 @@ export {
6441
6511
  reseedFromRegistry,
6442
6512
  seedFromRegistry
6443
6513
  };
6444
- //# sourceMappingURL=chunk-YO3HKQX6.js.map
6514
+ //# sourceMappingURL=chunk-W3HLGZBO.js.map