bitfab 0.54.3 → 0.54.5

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 (32) hide show
  1. package/dist/{chunk-DL4KHJON.js → chunk-3O5MS4XJ.js} +2 -2
  2. package/dist/{chunk-ZO4NEEUA.js → chunk-GVK7AES5.js} +113 -6
  3. package/dist/chunk-GVK7AES5.js.map +1 -0
  4. package/dist/{chunk-PELZFWPC.js → chunk-NATC7L2W.js} +124 -54
  5. package/dist/chunk-NATC7L2W.js.map +1 -0
  6. package/dist/{chunk-NI6B2BP4.js → chunk-RA3J6A6K.js} +113 -6
  7. package/dist/chunk-RA3J6A6K.js.map +1 -0
  8. package/dist/{chunk-4H7E2S27.js → chunk-VAHFHCBT.js} +3 -3
  9. package/dist/{http-6WMGO7GB.js → http-K2H4547F.js} +2 -2
  10. package/dist/{http-A5BXPX5R.js → http-RW2JO6TU.js} +2 -2
  11. package/dist/index.cjs +236 -52
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +114 -73
  14. package/dist/index.d.ts +114 -73
  15. package/dist/index.js +3 -3
  16. package/dist/node.cjs +236 -52
  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 -3
  21. package/dist/{replay-FOVT4PNE.js → replay-MHYULXCH.js} +3 -3
  22. package/dist/replayCli.js +2 -2
  23. package/dist/seedCli.js +2 -2
  24. package/package.json +1 -1
  25. package/dist/chunk-NI6B2BP4.js.map +0 -1
  26. package/dist/chunk-PELZFWPC.js.map +0 -1
  27. package/dist/chunk-ZO4NEEUA.js.map +0 -1
  28. /package/dist/{chunk-DL4KHJON.js.map → chunk-3O5MS4XJ.js.map} +0 -0
  29. /package/dist/{chunk-4H7E2S27.js.map → chunk-VAHFHCBT.js.map} +0 -0
  30. /package/dist/{http-6WMGO7GB.js.map → http-K2H4547F.js.map} +0 -0
  31. /package/dist/{http-A5BXPX5R.js.map → http-RW2JO6TU.js.map} +0 -0
  32. /package/dist/{replay-FOVT4PNE.js.map → replay-MHYULXCH.js.map} +0 -0
@@ -18,7 +18,7 @@ import {
18
18
  serializeValue,
19
19
  toJsonSafe,
20
20
  toJsonSafeReport
21
- } from "./chunk-DL4KHJON.js";
21
+ } from "./chunk-3O5MS4XJ.js";
22
22
  import {
23
23
  BitfabError,
24
24
  DEFAULT_SERVICE_URL,
@@ -35,7 +35,7 @@ import {
35
35
  recordCallerTraceMetadata,
36
36
  retireTraceMetadata,
37
37
  warnOnce
38
- } from "./chunk-ZO4NEEUA.js";
38
+ } from "./chunk-GVK7AES5.js";
39
39
  import {
40
40
  __privateAdd,
41
41
  __privateGet,
@@ -76,45 +76,6 @@ var AssertionCategoriesClient = class {
76
76
  }
77
77
  };
78
78
 
79
- // src/assertions.ts
80
- var ASSERTIONS_PATH = "/api/sdk/traces/assertions";
81
- function traceAssertionsPath(traceId, suffix = "") {
82
- return `/api/sdk/traces/${encodeURIComponent(traceId)}/assertions${suffix}`;
83
- }
84
- var TracesClient = class {
85
- constructor(httpClient) {
86
- this.httpClient = httpClient;
87
- }
88
- async getAssertions(traceId) {
89
- return this.httpClient.get(
90
- traceAssertionsPath(traceId)
91
- );
92
- }
93
- async saveAssertions(params) {
94
- return this.saveAssertionsAll({
95
- updates: [{ traceId: params.traceId, assertions: params.assertions }],
96
- source: params.source
97
- });
98
- }
99
- async saveAssertionsAll(params) {
100
- if (params.updates.length === 0) {
101
- return [];
102
- }
103
- const response = await this.httpClient.request(ASSERTIONS_PATH, {
104
- updates: params.updates,
105
- source: params.source ?? "agent"
106
- });
107
- return response.assertions;
108
- }
109
- async archiveAssertions(params) {
110
- const response = await this.httpClient.request(
111
- traceAssertionsPath(params.traceId, "/archive"),
112
- { assertionIds: params.assertionIds }
113
- );
114
- return response.archived;
115
- }
116
- };
117
-
118
79
  // src/processorPayload.ts
119
80
  var SERIALIZATION_DEGRADED_STEP = "serialization_degraded";
120
81
  function degradedError(dropped) {
@@ -331,6 +292,7 @@ var BitfabClaudeAgentHandler = class {
331
292
  spanInfo.dropped = [...inputDropped];
332
293
  }
333
294
  this.runToSpan.set(spanId, spanInfo);
295
+ this.httpClient.traceCompletion.start(spanInfo.traceId, spanInfo.spanId);
334
296
  return spanInfo;
335
297
  }
336
298
  completeSpan(spanId, output, error, extraContexts) {
@@ -352,6 +314,7 @@ var BitfabClaudeAgentHandler = class {
352
314
  spanInfo.contexts.push(extraContexts);
353
315
  }
354
316
  this.sendSpan(spanInfo);
317
+ this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
355
318
  }
356
319
  sendSpan(spanInfo) {
357
320
  const spanData = {
@@ -1824,6 +1787,9 @@ var BitfabLangGraphCallbackHandler = class {
1824
1787
  spanInfo.hidden = true;
1825
1788
  }
1826
1789
  this.runToSpan.set(runId, spanInfo);
1790
+ if (spanInfo.hidden !== true) {
1791
+ this.httpClient.traceCompletion.start(spanInfo.traceId, spanInfo.spanId);
1792
+ }
1827
1793
  if (isRootInvocation) {
1828
1794
  this.sendTraceStart(spanInfo);
1829
1795
  }
@@ -1855,6 +1821,7 @@ var BitfabLangGraphCallbackHandler = class {
1855
1821
  this.sendTraceCompletion(spanInfo, invocation?.activeContext ?? null);
1856
1822
  this.invocations.delete(runId);
1857
1823
  }
1824
+ this.httpClient.traceCompletion.end(spanInfo.traceId, spanInfo.spanId);
1858
1825
  }
1859
1826
  sendSpan(spanInfo) {
1860
1827
  const spanData = {
@@ -2539,6 +2506,55 @@ var StreamFinalizationError = class extends Error {
2539
2506
  }
2540
2507
  };
2541
2508
 
2509
+ // src/traces.ts
2510
+ var ASSERTIONS_PATH = "/api/sdk/traces/assertions";
2511
+ var SEARCH_PATH = "/api/sdk/traces/search";
2512
+ function traceAssertionsPath(traceId, suffix = "") {
2513
+ return `/api/sdk/traces/${encodeURIComponent(traceId)}/assertions${suffix}`;
2514
+ }
2515
+ var TracesClient = class {
2516
+ constructor(httpClient) {
2517
+ this.httpClient = httpClient;
2518
+ }
2519
+ /**
2520
+ * Search traces by exact caller metadata.
2521
+ *
2522
+ * Keys and values are matched case-insensitively. Up to 10 supplied pairs
2523
+ * must match. Use `nextCursor` from the result to fetch another page.
2524
+ */
2525
+ async search(params) {
2526
+ return this.httpClient.request(SEARCH_PATH, params);
2527
+ }
2528
+ async getAssertions(traceId) {
2529
+ return this.httpClient.get(
2530
+ traceAssertionsPath(traceId)
2531
+ );
2532
+ }
2533
+ async saveAssertions(params) {
2534
+ return this.saveAssertionsAll({
2535
+ updates: [{ traceId: params.traceId, assertions: params.assertions }],
2536
+ source: params.source
2537
+ });
2538
+ }
2539
+ async saveAssertionsAll(params) {
2540
+ if (params.updates.length === 0) {
2541
+ return [];
2542
+ }
2543
+ const response = await this.httpClient.request(ASSERTIONS_PATH, {
2544
+ updates: params.updates,
2545
+ source: params.source ?? "agent"
2546
+ });
2547
+ return response.assertions;
2548
+ }
2549
+ async archiveAssertions(params) {
2550
+ const response = await this.httpClient.request(
2551
+ traceAssertionsPath(params.traceId, "/archive"),
2552
+ { assertionIds: params.assertionIds }
2553
+ );
2554
+ return response.archived;
2555
+ }
2556
+ };
2557
+
2542
2558
  // src/tracing.ts
2543
2559
  var BitfabOpenAITracingProcessor = class {
2544
2560
  /**
@@ -2550,6 +2566,8 @@ var BitfabOpenAITracingProcessor = class {
2550
2566
  this.activeTraces = {};
2551
2567
  this.activeSpanMappings = {};
2552
2568
  this.canonicalTraceIds = {};
2569
+ this.startedSpans = /* @__PURE__ */ new Map();
2570
+ this.endedTraces = /* @__PURE__ */ new Set();
2553
2571
  this.ownsHttpClient = config._httpClient === void 0;
2554
2572
  this.httpClient = config._httpClient ?? new HttpClient({
2555
2573
  apiKey: config.apiKey,
@@ -2588,6 +2606,10 @@ var BitfabOpenAITracingProcessor = class {
2588
2606
  }
2589
2607
  const canonicalTraceId = activeContext?.traceId ?? this.getCanonicalTraceId(trace.traceId);
2590
2608
  this.canonicalTraceIds[trace.traceId] = canonicalTraceId;
2609
+ this.httpClient.traceCompletion.hold(
2610
+ activeContext?.traceId ?? trace.traceId,
2611
+ `openai:${trace.traceId}`
2612
+ );
2591
2613
  this.sendTrace(trace, {
2592
2614
  id: canonicalTraceId,
2593
2615
  sourceTraceId: activeContext?.traceId
@@ -2605,16 +2627,33 @@ var BitfabOpenAITracingProcessor = class {
2605
2627
  id: mapping?.traceId ?? this.getCanonicalTraceId(trace.traceId),
2606
2628
  sourceTraceId: mapping?.traceId
2607
2629
  });
2608
- delete this.activeSpanMappings[trace.traceId];
2609
- delete this.canonicalTraceIds[trace.traceId];
2610
- delete this.activeTraces[trace.traceId];
2630
+ this.endedTraces.add(trace.traceId);
2631
+ this.httpClient.traceCompletion.end(
2632
+ mapping?.traceId ?? trace.traceId,
2633
+ `openai:${trace.traceId}`
2634
+ );
2635
+ this.cleanupTrace(trace.traceId);
2636
+ }
2637
+ cleanupTrace(traceId) {
2638
+ if (!this.endedTraces.has(traceId) || [...this.startedSpans.values()].includes(traceId)) {
2639
+ return;
2640
+ }
2641
+ this.endedTraces.delete(traceId);
2642
+ delete this.activeSpanMappings[traceId];
2643
+ delete this.canonicalTraceIds[traceId];
2644
+ delete this.activeTraces[traceId];
2611
2645
  }
2612
2646
  /**
2613
2647
  * Called when a span is started. Span payloads are authoritative completed
2614
2648
  * snapshots, so start notifications do not cross the transport boundary.
2615
2649
  */
2616
2650
  // biome-ignore lint/suspicious/noExplicitAny: OpenAI Agents SDK uses any for span data
2617
- async onSpanStart(_span) {
2651
+ async onSpanStart(span) {
2652
+ if (span.spanId !== void 0 && span.traceId !== null && span.traceId !== void 0) {
2653
+ this.startedSpans.set(span.spanId, span.traceId);
2654
+ const traceId = this.activeSpanMappings[span.traceId]?.traceId ?? span.traceId;
2655
+ this.httpClient.traceCompletion.start(traceId, span.spanId);
2656
+ }
2618
2657
  }
2619
2658
  /**
2620
2659
  * Called when a span is ended.
@@ -2623,7 +2662,17 @@ var BitfabOpenAITracingProcessor = class {
2623
2662
  */
2624
2663
  // biome-ignore lint/suspicious/noExplicitAny: OpenAI Agents SDK uses any for span data
2625
2664
  async onSpanEnd(span) {
2626
- this.sendSpan(span);
2665
+ const originalTraceId = span.traceId ?? "";
2666
+ const traceId = this.activeSpanMappings[originalTraceId]?.traceId ?? originalTraceId;
2667
+ try {
2668
+ this.sendSpan(span);
2669
+ } finally {
2670
+ if (span.spanId !== void 0) {
2671
+ this.httpClient.traceCompletion.end(traceId, span.spanId);
2672
+ this.startedSpans.delete(span.spanId);
2673
+ }
2674
+ this.cleanupTrace(originalTraceId);
2675
+ }
2627
2676
  }
2628
2677
  /**
2629
2678
  * Called when a trace is being flushed.
@@ -4328,6 +4377,7 @@ var Bitfab = class {
4328
4377
  let newStack;
4329
4378
  let executeWithContext;
4330
4379
  let registeredTraceId;
4380
+ let startedSpan;
4331
4381
  try {
4332
4382
  const currentStack = getSpanStack();
4333
4383
  const parentContext = currentStack[currentStack.length - 1];
@@ -4379,6 +4429,8 @@ var Bitfab = class {
4379
4429
  });
4380
4430
  registeredTraceId = traceId;
4381
4431
  }
4432
+ self.httpClient.traceCompletion.start(traceId, spanId);
4433
+ startedSpan = { traceId, spanId };
4382
4434
  const functionName = fn.name !== "" ? fn.name : void 0;
4383
4435
  const rootTraceFunctionKey = activeTraceStates.get(traceId)?.traceFunctionKey ?? traceFunctionKey;
4384
4436
  const baseSpanParams = {
@@ -4453,6 +4505,8 @@ var Bitfab = class {
4453
4505
  retireTraceMetadata(traceId);
4454
4506
  }
4455
4507
  } catch {
4508
+ } finally {
4509
+ self.httpClient.traceCompletion.end(traceId, spanId);
4456
4510
  }
4457
4511
  };
4458
4512
  const recordSpan = (result) => {
@@ -4469,6 +4523,14 @@ var Bitfab = class {
4469
4523
  void sendSpan({ result });
4470
4524
  }
4471
4525
  };
4526
+ const resolveMockOrAbort = async (resolve) => {
4527
+ try {
4528
+ return await resolve();
4529
+ } catch (error) {
4530
+ self.httpClient.traceCompletion.abort(traceId, spanId);
4531
+ throw error;
4532
+ }
4533
+ };
4472
4534
  executeWithContext = () => {
4473
4535
  let result;
4474
4536
  try {
@@ -4525,7 +4587,7 @@ var Bitfab = class {
4525
4587
  );
4526
4588
  }
4527
4589
  return (async () => {
4528
- const output = await pending;
4590
+ const output = await resolveMockOrAbort(() => pending);
4529
4591
  void sendSpan({
4530
4592
  result: output,
4531
4593
  mocked: true,
@@ -4595,7 +4657,7 @@ var Bitfab = class {
4595
4657
  );
4596
4658
  }
4597
4659
  return runWithSpanStack(newStack, async () => {
4598
- const resolved2 = await resolution;
4660
+ const resolved2 = await resolveMockOrAbort(() => resolution);
4599
4661
  if (resolved2.matched) {
4600
4662
  void sendSpan({
4601
4663
  result: resolved2.output,
@@ -4611,7 +4673,9 @@ var Bitfab = class {
4611
4673
  );
4612
4674
  }
4613
4675
  if (shouldMockWithBaseStrategy) {
4614
- const output = await resolveRecordedOutput();
4676
+ const output = await resolveMockOrAbort(
4677
+ () => resolveRecordedOutput()
4678
+ );
4615
4679
  void sendSpan({
4616
4680
  result: output,
4617
4681
  mocked: true,
@@ -4641,6 +4705,12 @@ var Bitfab = class {
4641
4705
  }
4642
4706
  }
4643
4707
  } catch (setupError) {
4708
+ if (startedSpan) {
4709
+ self.httpClient.traceCompletion.abort(
4710
+ startedSpan.traceId,
4711
+ startedSpan.spanId
4712
+ );
4713
+ }
4644
4714
  if (registeredTraceId) {
4645
4715
  activeTraceStates.delete(registeredTraceId);
4646
4716
  retireTraceMetadata(registeredTraceId);
@@ -5107,7 +5177,7 @@ var Bitfab = class {
5107
5177
  await runWithSeedContext({ traceId }, async () => target(...args));
5108
5178
  } finally {
5109
5179
  try {
5110
- const { flushTraces: flushTraces2 } = await import("./http-A5BXPX5R.js");
5180
+ const { flushTraces: flushTraces2 } = await import("./http-RW2JO6TU.js");
5111
5181
  await flushTraces2(3e4);
5112
5182
  } finally {
5113
5183
  unrecorded = activeTraceStates.delete(traceId);
@@ -5166,7 +5236,7 @@ var Bitfab = class {
5166
5236
  `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.`
5167
5237
  );
5168
5238
  }
5169
- const { replay: doReplay } = await import("./replay-FOVT4PNE.js");
5239
+ const { replay: doReplay } = await import("./replay-MHYULXCH.js");
5170
5240
  return doReplay(
5171
5241
  this.httpClient,
5172
5242
  this.serviceUrl,
@@ -5450,7 +5520,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
5450
5520
  sessionId: seedCase.sessionId
5451
5521
  })
5452
5522
  );
5453
- const { flushTraces: flushTraces2 } = await import("./http-A5BXPX5R.js");
5523
+ const { flushTraces: flushTraces2 } = await import("./http-RW2JO6TU.js");
5454
5524
  await flushTraces2(3e4);
5455
5525
  return { pipeline, traceFunctionKey, traceIds };
5456
5526
  }
@@ -5467,7 +5537,6 @@ function resolveTraceFunctionKey(registration) {
5467
5537
 
5468
5538
  export {
5469
5539
  AssertionCategoriesClient,
5470
- TracesClient,
5471
5540
  BitfabClaudeAgentHandler,
5472
5541
  DatasetsClient,
5473
5542
  SUPPORTED_PROVIDERS,
@@ -5476,6 +5545,7 @@ export {
5476
5545
  BitfabLangGraphCallbackHandler,
5477
5546
  BitfabLangGraphIntegration,
5478
5547
  BitfabOpenAIAgentHandler,
5548
+ TracesClient,
5479
5549
  BitfabOpenAITracingProcessor,
5480
5550
  BitfabVercelAiHandler,
5481
5551
  getCurrentSpan,
@@ -5488,4 +5558,4 @@ export {
5488
5558
  reseedFromRegistry,
5489
5559
  seedFromRegistry
5490
5560
  };
5491
- //# sourceMappingURL=chunk-PELZFWPC.js.map
5561
+ //# sourceMappingURL=chunk-NATC7L2W.js.map