bitfab 0.68.4 → 0.68.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 (68) hide show
  1. package/dist/{autoTrace-D3-OZcmR.cjs → autoTrace-DUmR1KJ8.cjs} +417 -62
  2. package/dist/autoTrace-DUmR1KJ8.cjs.map +1 -0
  3. package/dist/{autoTrace-ghnojSj9.js → autoTrace-DVnpnuMb.js} +322 -57
  4. package/dist/autoTrace-DVnpnuMb.js.map +1 -0
  5. package/dist/autoTrace.cjs +3 -1
  6. package/dist/autoTrace.d.cts +29 -1
  7. package/dist/autoTrace.d.ts +29 -1
  8. package/dist/autoTrace.js +1 -1
  9. package/dist/{babelPlugin-0uOq-j1Q.cjs → babelPlugin-C0Im6AZ2.cjs} +37 -14
  10. package/dist/babelPlugin-C0Im6AZ2.cjs.map +1 -0
  11. package/dist/{babelPlugin-Muq0uuuu.js → babelPlugin-hS2Hb2vt.js} +37 -14
  12. package/dist/babelPlugin-hS2Hb2vt.js.map +1 -0
  13. package/dist/baml.cjs +1 -1
  14. package/dist/baml.js +1 -1
  15. package/dist/{bamlPeer-BUoZgNxZ.cjs → bamlPeer-5Ohpq8q9.cjs} +3 -17
  16. package/dist/bamlPeer-5Ohpq8q9.cjs.map +1 -0
  17. package/dist/{bamlPeer-CIVwS68E.js → bamlPeer-Dyeb3e5o.js} +3 -11
  18. package/dist/bamlPeer-Dyeb3e5o.js.map +1 -0
  19. package/dist/{http-BGY4ULH5.js → http-CDqaLdge.js} +3 -3
  20. package/dist/{http-BGY4ULH5.js.map → http-CDqaLdge.js.map} +1 -1
  21. package/dist/{http-C-HrwUb8.cjs → http-DFqFW_hG.cjs} +4 -4
  22. package/dist/{http-C-HrwUb8.cjs.map → http-DFqFW_hG.cjs.map} +1 -1
  23. package/dist/{index-BcGxu85i.d.cts → index-DMJ6qrtL.d.cts} +109 -2
  24. package/dist/{index-BcGxu85i.d.ts → index-DMJ6qrtL.d.ts} +109 -2
  25. package/dist/index.cjs +2 -2
  26. package/dist/index.d.cts +2 -2
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.js +2 -2
  29. package/dist/node.cjs +3 -3
  30. package/dist/node.d.cts +2 -2
  31. package/dist/node.d.ts +2 -2
  32. package/dist/node.js +3 -3
  33. package/dist/optionalPeer-CUH756lt.cjs +17 -0
  34. package/dist/optionalPeer-CUH756lt.cjs.map +1 -0
  35. package/dist/optionalPeer-CczrzrXx.js +12 -0
  36. package/dist/optionalPeer-CczrzrXx.js.map +1 -0
  37. package/dist/{registryCommand-Dk4Y1ZgW.js → registryCommand-D7bfo0Au.js} +179 -8
  38. package/dist/registryCommand-D7bfo0Au.js.map +1 -0
  39. package/dist/replayCli.js +1 -1
  40. package/dist/seedCli.js +1 -1
  41. package/dist/{src-BG2_8Fpf.cjs → src-CxELko3f.cjs} +52 -80
  42. package/dist/src-CxELko3f.cjs.map +1 -0
  43. package/dist/{src-Cmfs_7Ib.js → src-DvVk1aLi.js} +41 -69
  44. package/dist/src-DvVk1aLi.js.map +1 -0
  45. package/dist/transform/babel.cjs +1 -1
  46. package/dist/transform/babel.js +1 -1
  47. package/dist/transform/loaderRuntime.cjs +2 -2
  48. package/dist/transform/loaderRuntime.js +2 -2
  49. package/dist/transform/nodeLoader.js +36 -13
  50. package/dist/transform/nodeLoader.js.map +1 -1
  51. package/dist/transform/swc.cjs +1 -1
  52. package/dist/transform/swc.js +1 -1
  53. package/dist/transform/unplugin.cjs +2 -2
  54. package/dist/transform/unplugin.js +2 -2
  55. package/dist/{transform-CAJyLLe2.js → transform-BL1fJW-C.js} +2 -2
  56. package/dist/{transform-CAJyLLe2.js.map → transform-BL1fJW-C.js.map} +1 -1
  57. package/dist/{transform-ClCOpCZ2.cjs → transform-C4H7TKW-.cjs} +2 -2
  58. package/dist/{transform-ClCOpCZ2.cjs.map → transform-C4H7TKW-.cjs.map} +1 -1
  59. package/package.json +1 -1
  60. package/dist/autoTrace-D3-OZcmR.cjs.map +0 -1
  61. package/dist/autoTrace-ghnojSj9.js.map +0 -1
  62. package/dist/babelPlugin-0uOq-j1Q.cjs.map +0 -1
  63. package/dist/babelPlugin-Muq0uuuu.js.map +0 -1
  64. package/dist/bamlPeer-BUoZgNxZ.cjs.map +0 -1
  65. package/dist/bamlPeer-CIVwS68E.js.map +0 -1
  66. package/dist/registryCommand-Dk4Y1ZgW.js.map +0 -1
  67. package/dist/src-BG2_8Fpf.cjs.map +0 -1
  68. package/dist/src-Cmfs_7Ib.js.map +0 -1
@@ -1,7 +1,8 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
- import { C as readEnv$1, S as MixedTracingError, _ as getReplayContext, b as gitRunner, c as recordCallerTraceMetadata, f as ROOT_TRACE_FUNCTION_KEY_FIELD, g as MAX_COMPRESSIBLE_SPAN_CARRIER_BYTES, h as makeSpanOrigin, i as flushTraces, l as retireTraceMetadata, m as isFrameworkInstrumentation, n as SPAN_TYPES, o as unrefTimer, p as SimulationPlan, r as experimentIdWireFields, s as callerTraceMetadata, t as HttpClient, v as replayContextReady, w as __version__, x as BitfabError, y as runWithReplayContext } from "./http-BGY4ULH5.js";
3
- import { E as isAsyncStorageInitDone, S as runWithCaptureSuppressed, T as createAsyncLocalStorage, _ as watchOpenRouterUsage, b as writeOnce, c as currentAutoTraceEntries, d as runAsAutoTraceRootFunction, f as runWithAutoTraceEntry, g as recordWatchedOpenRouterCompletion, h as recordAutoTracedOpenRouter, i as __bitfabAutoTraceActive, m as runWithAutoTraceRootContext, p as runWithAutoTraceNodeConfiguration, s as clearAutoTraceNodeConfiguration, u as invokeThroughAutoTraceEntries, w as asyncStorageReady, x as isCaptureSuppressed, y as warnOnce } from "./autoTrace-ghnojSj9.js";
4
- import { r as importOptionalPeer, t as loadBamlModule } from "./bamlPeer-CIVwS68E.js";
2
+ import { C as readEnv$1, S as MixedTracingError, _ as getReplayContext, b as gitRunner, c as recordCallerTraceMetadata, f as ROOT_TRACE_FUNCTION_KEY_FIELD, g as MAX_COMPRESSIBLE_SPAN_CARRIER_BYTES, h as makeSpanOrigin, i as flushTraces, l as retireTraceMetadata, m as isFrameworkInstrumentation, n as SPAN_TYPES, o as unrefTimer, p as SimulationPlan, r as experimentIdWireFields, s as callerTraceMetadata, t as HttpClient, v as replayContextReady, w as __version__, x as BitfabError, y as runWithReplayContext } from "./http-CDqaLdge.js";
3
+ import { A as forgetLangChainRun, B as createAsyncLocalStorage, C as recordWatchedClientCall, D as openAiAgentsParentSpanId, E as mapOpenAiAgentsTrace, F as writeOnce, I as isCaptureSuppressed, L as runWithCaptureSuppressed, M as markLangChainRunRecorded, O as openAiAgentsSpanChain, P as warnOnce, S as recordAutoTracedClientCall, T as endOpenAiAgentsSpan, V as isAsyncStorageInitDone, _ as ANTHROPIC, b as clientCallProvider, f as invokeThroughAutoTraceEntries, g as runWithAutoTraceRootContext, h as runWithAutoTraceNodeConfiguration, j as installLangChainRunScopes, k as unmapOpenAiAgentsTrace, l as clearAutoTraceNodeConfiguration, m as runWithAutoTraceEntry, o as __bitfabAutoTraceActive, p as runAsAutoTraceRootFunction, u as currentAutoTraceEntries, v as OPENAI_RESPONSES, w as watchClientCall, x as frameworkRecordsClientCall, y as OPENROUTER, z as asyncStorageReady } from "./autoTrace-DVnpnuMb.js";
4
+ import { t as importOptionalPeer } from "./optionalPeer-CczrzrXx.js";
5
+ import { t as loadBamlModule } from "./bamlPeer-Dyeb3e5o.js";
5
6
  import superjson from "superjson";
6
7
  //#region src/categories.ts
7
8
  const CATEGORIES_PATH = "/api/sdk/categories";
@@ -1696,6 +1697,7 @@ var BitfabLangGraphCallbackHandler = class {
1696
1697
  this.getActiveSpanContext = config.getActiveSpanContext ?? null;
1697
1698
  this.shouldRecord = config.shouldRecord ?? (() => this.httpClient.hasApiKey());
1698
1699
  this.captureTools = config.captureTools ?? true;
1700
+ installLangChainRunScopes();
1699
1701
  }
1700
1702
  async close(timeoutMs) {
1701
1703
  return this.ownsHttpClient ? this.httpClient.close(timeoutMs) : true;
@@ -1907,6 +1909,7 @@ var BitfabLangGraphCallbackHandler = class {
1907
1909
  const converted = messages.map((batch) => batch.map(convertMessage));
1908
1910
  const spanInfo = this.startSpan(runId, parentRunId, String(name), "llm", converted, metadata, tags);
1909
1911
  spanInfo.model = model;
1912
+ if (this.shouldRecord()) markLangChainRunRecorded(runId);
1910
1913
  } catch {}
1911
1914
  }
1912
1915
  async handleLLMStart(llm, prompts, runId, parentRunId, _extraParams, tags, metadata, runName) {
@@ -1917,10 +1920,12 @@ var BitfabLangGraphCallbackHandler = class {
1917
1920
  const name = runName ?? model ?? idArr?.[idArr.length - 1] ?? "llm";
1918
1921
  const spanInfo = this.startSpan(runId, parentRunId, String(name), "llm", prompts, metadata, tags);
1919
1922
  spanInfo.model = model;
1923
+ if (this.shouldRecord()) markLangChainRunRecorded(runId);
1920
1924
  } catch {}
1921
1925
  }
1922
1926
  async handleLLMEnd(output, runId) {
1923
1927
  try {
1928
+ forgetLangChainRun(runId);
1924
1929
  let llmOutput;
1925
1930
  const generations = output.generations;
1926
1931
  if (generations?.length && generations[generations.length - 1]?.length) {
@@ -1938,6 +1943,7 @@ var BitfabLangGraphCallbackHandler = class {
1938
1943
  }
1939
1944
  async handleLLMError(error, runId) {
1940
1945
  try {
1946
+ forgetLangChainRun(runId);
1941
1947
  this.completeSpan(runId, void 0, error instanceof Error ? error.message : String(error));
1942
1948
  } catch {}
1943
1949
  }
@@ -2570,64 +2576,6 @@ var BitfabOpenAIAgentHandler = class {
2570
2576
  }
2571
2577
  };
2572
2578
  //#endregion
2573
- //#region src/openaiAgentsSpanContext.ts
2574
- const OPENAI_AGENTS_CONTEXT_STORAGE = Symbol.for("openai.agents.core.asyncLocalStorage");
2575
- const MAX_OPENAI_AGENTS_SPAN_CHAIN = 64;
2576
- const spanGlobal = globalThis;
2577
- const state = spanGlobal.__bitfabOpenAiAgentsSpansV1 ?? {
2578
- bitfabTraceIds: /* @__PURE__ */ new Map(),
2579
- endedSpanIds: /* @__PURE__ */ new Map()
2580
- };
2581
- spanGlobal.__bitfabOpenAiAgentsSpansV1 = state;
2582
- function mapOpenAiAgentsTrace(agentsTraceId, bitfabTraceId) {
2583
- state.bitfabTraceIds.set(agentsTraceId, bitfabTraceId);
2584
- }
2585
- function unmapOpenAiAgentsTrace(agentsTraceId) {
2586
- state.bitfabTraceIds.delete(agentsTraceId);
2587
- state.endedSpanIds.delete(agentsTraceId);
2588
- }
2589
- function endOpenAiAgentsSpan(agentsTraceId, spanId) {
2590
- if (!state.bitfabTraceIds.has(agentsTraceId)) return;
2591
- const ended = state.endedSpanIds.get(agentsTraceId) ?? /* @__PURE__ */ new Set();
2592
- ended.add(spanId);
2593
- state.endedSpanIds.set(agentsTraceId, ended);
2594
- }
2595
- function isOpenAiAgentsContextStorage(value) {
2596
- return value !== null && typeof value === "object" && typeof value.getStore === "function";
2597
- }
2598
- function currentOpenAiAgentsSpan() {
2599
- const storage = spanGlobal[OPENAI_AGENTS_CONTEXT_STORAGE];
2600
- if (!isOpenAiAgentsContextStorage(storage)) return;
2601
- try {
2602
- const store = storage.getStore();
2603
- return store?.active === true ? store.span ?? void 0 : void 0;
2604
- } catch {
2605
- return;
2606
- }
2607
- }
2608
- function currentOpenAiAgentsSpans() {
2609
- const spans = [];
2610
- let span = currentOpenAiAgentsSpan();
2611
- while (span !== void 0 && spans.length < MAX_OPENAI_AGENTS_SPAN_CHAIN) {
2612
- spans.push(span);
2613
- span = span.previousSpan ?? void 0;
2614
- }
2615
- return spans;
2616
- }
2617
- function openAiAgentsSpanChain() {
2618
- if (state.bitfabTraceIds.size === 0) return [];
2619
- return currentOpenAiAgentsSpans().map((span) => span.spanId).filter((spanId) => typeof spanId === "string");
2620
- }
2621
- function openAiAgentsParentSpanId(bitfabTraceId, enclosingSpanIds) {
2622
- if (state.bitfabTraceIds.size === 0) return;
2623
- for (const span of currentOpenAiAgentsSpans()) {
2624
- if (typeof span.spanId !== "string" || typeof span.traceId !== "string") return;
2625
- if (state.bitfabTraceIds.get(span.traceId) !== bitfabTraceId) return;
2626
- if (enclosingSpanIds?.includes(span.spanId)) return;
2627
- if (!state.endedSpanIds.get(span.traceId)?.has(span.spanId)) return span.spanId;
2628
- }
2629
- }
2630
- //#endregion
2631
2579
  //#region src/organizationMembers.ts
2632
2580
  const MEMBERS_PATH = "/api/sdk/organizationMembers";
2633
2581
  var OrganizationMembersClient = class {
@@ -5220,7 +5168,7 @@ function extractContextFromCollector(collector) {
5220
5168
  }
5221
5169
  const BOUND_FUNCTION_NAME_PREFIX = /^bound /;
5222
5170
  function discoveredSpanType(definition, nodeConfiguration) {
5223
- const recordsModelCall = definition.baml === true || definition.jev === true || definition.openrouter === true;
5171
+ const recordsModelCall = definition.baml === true || definition.jev === true || definition.clientCall !== void 0;
5224
5172
  const ownType = recordsModelCall ? "llm" : "function";
5225
5173
  if (nodeConfiguration === void 0) return ownType;
5226
5174
  if (recordsModelCall && nodeConfiguration.defaultType === true) return ownType;
@@ -5541,6 +5489,7 @@ var Bitfab = class {
5541
5489
  const self = this;
5542
5490
  self.simulationPlan.refresh();
5543
5491
  loadCollectorClass();
5492
+ installLangChainRunScopes();
5544
5493
  const runRootFunction = (receiver, args) => runAsAutoTraceRootFunction(rootFunctionName, () => fn.apply(receiver, args));
5545
5494
  const maxDepth = autoTraceLimit(options.maxDepth, DEFAULT_AUTO_TRACE_MAX_DEPTH);
5546
5495
  const maxCapturedSubtreeSpans = autoTraceLimit(options.maxCapturedSubtreeSpans, DEFAULT_AUTO_TRACE_MAX_CAPTURED_SUBTREE_SPANS);
@@ -5629,7 +5578,8 @@ var Bitfab = class {
5629
5578
  ...nodeConfiguration?.finalize !== void 0 && { finalize: nodeConfiguration.finalize }
5630
5579
  };
5631
5580
  const isAsync = definition.async === true;
5632
- return openChild(entry, childOptions, inputs, isAsync, definition.baml === true ? () => invokeAutoTracedBaml(invokeFn, isAsync) : definition.jev === true ? () => recordAutoTracedJev(invokeFn, getCurrentSpan()) : definition.openrouter === true ? () => recordAutoTracedOpenRouter(invokeFn, inputs[0], getCurrentSpan()) : invokeFn);
5581
+ const clientCall = clientCallProvider(definition.clientCall);
5582
+ return openChild(entry, childOptions, inputs, isAsync, definition.baml === true ? () => invokeAutoTracedBaml(invokeFn, isAsync) : definition.jev === true ? () => recordAutoTracedJev(invokeFn, getCurrentSpan()) : clientCall !== void 0 ? () => recordAutoTracedClientCall(clientCall, invokeFn, inputs[0], getCurrentSpan()) : invokeFn);
5633
5583
  },
5634
5584
  invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link, spanDetails) {
5635
5585
  if (excluded.has(nestedName) || excluded.has(nestedFunctionName) || !recordsSpan(entry, nestedName, true)) return invokeFn();
@@ -5941,14 +5891,30 @@ var Bitfab = class {
5941
5891
  return wrappedFn;
5942
5892
  }
5943
5893
  wrapOpenRouter(method, options) {
5894
+ return this.wrapClientCall(OPENROUTER, "wrapOpenRouter requires a named function (e.g., openai.chat.completions.create.bind(openai.chat.completions)).", method, options);
5895
+ }
5896
+ wrapAnthropic(method, options) {
5897
+ return this.wrapClientCall(ANTHROPIC, "wrapAnthropic requires a named function (e.g., anthropic.messages.create.bind(anthropic.messages)).", method, options);
5898
+ }
5899
+ wrapOpenAIResponses(method, options) {
5900
+ return this.wrapClientCall(OPENAI_RESPONSES, "wrapOpenAIResponses requires a named function (e.g., openai.responses.create.bind(openai.responses)).", method, options);
5901
+ }
5902
+ wrapClientCall(provider, anonymousError, method, options) {
5944
5903
  const methodName = method.name.replace(BOUND_FUNCTION_NAME_PREFIX, "");
5945
- if (!methodName) throw new BitfabError("wrapOpenRouter requires a named function (e.g., openai.chat.completions.create.bind(openai.chat.completions)).");
5904
+ if (!methodName) throw new BitfabError(anonymousError);
5946
5905
  const wrappedFn = async (...args) => {
5947
5906
  const span = getCurrentSpan();
5948
5907
  const startedAt = Date.now();
5949
- const { watch, result } = watchOpenRouterUsage(() => method(...args));
5908
+ if (frameworkRecordsClientCall()) {
5909
+ const response = await method(...args);
5910
+ try {
5911
+ options?.onResponse?.(response);
5912
+ } catch {}
5913
+ return response;
5914
+ }
5915
+ const { watch, result } = watchClientCall(() => method(...args));
5950
5916
  const response = await result;
5951
- recordWatchedOpenRouterCompletion(span, watch, args[0], response, Date.now() - startedAt);
5917
+ recordWatchedClientCall(provider, span, watch, args[0], response, Date.now() - startedAt);
5952
5918
  try {
5953
5919
  options?.onResponse?.(response);
5954
5920
  } catch {}
@@ -6598,7 +6564,7 @@ var Bitfab = class {
6598
6564
  await runWithSeedContext({ traceId }, async () => target(...args));
6599
6565
  } finally {
6600
6566
  try {
6601
- const { flushTraces } = await import("./http-BGY4ULH5.js").then((n) => n.a);
6567
+ const { flushTraces } = await import("./http-CDqaLdge.js").then((n) => n.a);
6602
6568
  await flushTraces(3e4);
6603
6569
  } finally {
6604
6570
  unrecorded = activeTraceStates.delete(traceId);
@@ -6693,6 +6659,12 @@ var BitfabFunction = class {
6693
6659
  wrapOpenRouter(method, options) {
6694
6660
  return this.client.wrapOpenRouter(method, options);
6695
6661
  }
6662
+ wrapAnthropic(method, options) {
6663
+ return this.client.wrapAnthropic(method, options);
6664
+ }
6665
+ wrapOpenAIResponses(method, options) {
6666
+ return this.client.wrapOpenAIResponses(method, options);
6667
+ }
6696
6668
  };
6697
6669
  //#endregion
6698
6670
  //#region src/finalizers.ts
@@ -6795,7 +6767,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
6795
6767
  metadata: seedCase.metadata,
6796
6768
  sessionId: seedCase.sessionId
6797
6769
  }));
6798
- const { flushTraces } = await import("./http-BGY4ULH5.js").then((n) => n.a);
6770
+ const { flushTraces } = await import("./http-CDqaLdge.js").then((n) => n.a);
6799
6771
  await flushTraces(3e4);
6800
6772
  return {
6801
6773
  pipeline,
@@ -6812,4 +6784,4 @@ function resolveTraceFunctionKey(registration) {
6812
6784
  //#endregion
6813
6785
  export { ExperimentsClient as A, BitfabOpenAIAgentHandler as C, GradersClient as D, BitfabLangGraphCallbackHandler as E, BitfabClaudeAgentHandler as F, DEFAULT_SERVICE_URL as I, AssertionCategoriesClient as L, DatasetsClient as M, GraderRerunError as N, LabelsClient as O, GraderRerunTimeoutError as P, CategoriesClient as R, OrganizationMembersClient as S, BitfabLangGraphIntegration as T, BITFAB_PROGRESS_PREFIX as _, Bitfab as a, reportReplayProgress as b, getCurrentSpan as c, BitfabOpenAITracingProcessor as d, AssertionGenerationError as f, BitfabRivetIntegration as g, SpansClient as h, finalizers as i, SUPPORTED_PROVIDERS as j, VerdictsClient as k, getCurrentTrace as l, TracesClient as m, reseedFromRegistry as n, BitfabFunction as o, AssertionGenerationTimeoutError as p, seedFromRegistry as r, getCurrentReplayBranch as s, defineReplayRegistry as t, BitfabVercelAiHandler as u, DbBranchReplayError as v, NO_MOCK_OVERRIDE as w, serializeReplayResult as x, ReplayError as y };
6814
6786
 
6815
- //# sourceMappingURL=src-Cmfs_7Ib.js.map
6787
+ //# sourceMappingURL=src-DvVk1aLi.js.map