bitfab 0.68.4 → 0.68.6

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-C-HrwUb8.cjs → http-CARmid5D.cjs} +4 -4
  20. package/dist/{http-C-HrwUb8.cjs.map → http-CARmid5D.cjs.map} +1 -1
  21. package/dist/{http-BGY4ULH5.js → http-CYIjoMdj.js} +3 -3
  22. package/dist/{http-BGY4ULH5.js.map → http-CYIjoMdj.js.map} +1 -1
  23. package/dist/{index-BcGxu85i.d.cts → index-BuP59-AI.d.cts} +189 -4
  24. package/dist/{index-BcGxu85i.d.ts → index-BuP59-AI.d.ts} +189 -4
  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-C3H1v_hp.cjs} +62 -81
  42. package/dist/src-C3H1v_hp.cjs.map +1 -0
  43. package/dist/{src-Cmfs_7Ib.js → src-DgeGOhjN.js} +51 -70
  44. package/dist/src-DgeGOhjN.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-CYIjoMdj.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 {
@@ -4652,9 +4600,18 @@ var TracesClient = class {
4652
4600
  return (await this.httpClient.get(traceScenarioPath(traceId))).scenario;
4653
4601
  }
4654
4602
  async saveScenario({ traceId, ...edit }) {
4655
- return (await this.httpClient.request(traceScenarioPath(traceId), edit)).scenario;
4603
+ return (await this.httpClient.request(traceScenarioPath(traceId), withoutDataRecords(edit))).scenario;
4656
4604
  }
4657
4605
  };
4606
+ const RECORDS_KEYS_IN_DATA = ["records", "sources"];
4607
+ function withoutDataRecords(edit) {
4608
+ if (edit.data === void 0) return edit;
4609
+ const data = Object.fromEntries(Object.entries(edit.data).filter(([key]) => !RECORDS_KEYS_IN_DATA.includes(key)));
4610
+ return {
4611
+ ...edit,
4612
+ data
4613
+ };
4614
+ }
4658
4615
  //#endregion
4659
4616
  //#region src/tracing.ts
4660
4617
  var BitfabOpenAITracingProcessor = class {
@@ -5220,7 +5177,7 @@ function extractContextFromCollector(collector) {
5220
5177
  }
5221
5178
  const BOUND_FUNCTION_NAME_PREFIX = /^bound /;
5222
5179
  function discoveredSpanType(definition, nodeConfiguration) {
5223
- const recordsModelCall = definition.baml === true || definition.jev === true || definition.openrouter === true;
5180
+ const recordsModelCall = definition.baml === true || definition.jev === true || definition.clientCall !== void 0;
5224
5181
  const ownType = recordsModelCall ? "llm" : "function";
5225
5182
  if (nodeConfiguration === void 0) return ownType;
5226
5183
  if (recordsModelCall && nodeConfiguration.defaultType === true) return ownType;
@@ -5541,6 +5498,7 @@ var Bitfab = class {
5541
5498
  const self = this;
5542
5499
  self.simulationPlan.refresh();
5543
5500
  loadCollectorClass();
5501
+ installLangChainRunScopes();
5544
5502
  const runRootFunction = (receiver, args) => runAsAutoTraceRootFunction(rootFunctionName, () => fn.apply(receiver, args));
5545
5503
  const maxDepth = autoTraceLimit(options.maxDepth, DEFAULT_AUTO_TRACE_MAX_DEPTH);
5546
5504
  const maxCapturedSubtreeSpans = autoTraceLimit(options.maxCapturedSubtreeSpans, DEFAULT_AUTO_TRACE_MAX_CAPTURED_SUBTREE_SPANS);
@@ -5629,7 +5587,8 @@ var Bitfab = class {
5629
5587
  ...nodeConfiguration?.finalize !== void 0 && { finalize: nodeConfiguration.finalize }
5630
5588
  };
5631
5589
  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);
5590
+ const clientCall = clientCallProvider(definition.clientCall);
5591
+ 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
5592
  },
5634
5593
  invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link, spanDetails) {
5635
5594
  if (excluded.has(nestedName) || excluded.has(nestedFunctionName) || !recordsSpan(entry, nestedName, true)) return invokeFn();
@@ -5941,14 +5900,30 @@ var Bitfab = class {
5941
5900
  return wrappedFn;
5942
5901
  }
5943
5902
  wrapOpenRouter(method, options) {
5903
+ return this.wrapClientCall(OPENROUTER, "wrapOpenRouter requires a named function (e.g., openai.chat.completions.create.bind(openai.chat.completions)).", method, options);
5904
+ }
5905
+ wrapAnthropic(method, options) {
5906
+ return this.wrapClientCall(ANTHROPIC, "wrapAnthropic requires a named function (e.g., anthropic.messages.create.bind(anthropic.messages)).", method, options);
5907
+ }
5908
+ wrapOpenAIResponses(method, options) {
5909
+ return this.wrapClientCall(OPENAI_RESPONSES, "wrapOpenAIResponses requires a named function (e.g., openai.responses.create.bind(openai.responses)).", method, options);
5910
+ }
5911
+ wrapClientCall(provider, anonymousError, method, options) {
5944
5912
  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)).");
5913
+ if (!methodName) throw new BitfabError(anonymousError);
5946
5914
  const wrappedFn = async (...args) => {
5947
5915
  const span = getCurrentSpan();
5948
5916
  const startedAt = Date.now();
5949
- const { watch, result } = watchOpenRouterUsage(() => method(...args));
5917
+ if (frameworkRecordsClientCall()) {
5918
+ const response = await method(...args);
5919
+ try {
5920
+ options?.onResponse?.(response);
5921
+ } catch {}
5922
+ return response;
5923
+ }
5924
+ const { watch, result } = watchClientCall(() => method(...args));
5950
5925
  const response = await result;
5951
- recordWatchedOpenRouterCompletion(span, watch, args[0], response, Date.now() - startedAt);
5926
+ recordWatchedClientCall(provider, span, watch, args[0], response, Date.now() - startedAt);
5952
5927
  try {
5953
5928
  options?.onResponse?.(response);
5954
5929
  } catch {}
@@ -6598,7 +6573,7 @@ var Bitfab = class {
6598
6573
  await runWithSeedContext({ traceId }, async () => target(...args));
6599
6574
  } finally {
6600
6575
  try {
6601
- const { flushTraces } = await import("./http-BGY4ULH5.js").then((n) => n.a);
6576
+ const { flushTraces } = await import("./http-CYIjoMdj.js").then((n) => n.a);
6602
6577
  await flushTraces(3e4);
6603
6578
  } finally {
6604
6579
  unrecorded = activeTraceStates.delete(traceId);
@@ -6693,6 +6668,12 @@ var BitfabFunction = class {
6693
6668
  wrapOpenRouter(method, options) {
6694
6669
  return this.client.wrapOpenRouter(method, options);
6695
6670
  }
6671
+ wrapAnthropic(method, options) {
6672
+ return this.client.wrapAnthropic(method, options);
6673
+ }
6674
+ wrapOpenAIResponses(method, options) {
6675
+ return this.client.wrapOpenAIResponses(method, options);
6676
+ }
6696
6677
  };
6697
6678
  //#endregion
6698
6679
  //#region src/finalizers.ts
@@ -6795,7 +6776,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
6795
6776
  metadata: seedCase.metadata,
6796
6777
  sessionId: seedCase.sessionId
6797
6778
  }));
6798
- const { flushTraces } = await import("./http-BGY4ULH5.js").then((n) => n.a);
6779
+ const { flushTraces } = await import("./http-CYIjoMdj.js").then((n) => n.a);
6799
6780
  await flushTraces(3e4);
6800
6781
  return {
6801
6782
  pipeline,
@@ -6812,4 +6793,4 @@ function resolveTraceFunctionKey(registration) {
6812
6793
  //#endregion
6813
6794
  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
6795
 
6815
- //# sourceMappingURL=src-Cmfs_7Ib.js.map
6796
+ //# sourceMappingURL=src-DgeGOhjN.js.map