@bitfab/sdk 0.75.0 → 0.76.0

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 (58) hide show
  1. package/dist/{autoTrace-kHOBg49M.js → autoTrace-BgN0zCQf.js} +565 -69
  2. package/dist/autoTrace-BgN0zCQf.js.map +1 -0
  3. package/dist/{autoTrace-DPWV1Xzr.cjs → autoTrace-pZKu5Nk2.cjs} +612 -68
  4. package/dist/autoTrace-pZKu5Nk2.cjs.map +1 -0
  5. package/dist/autoTrace.cjs +2 -1
  6. package/dist/autoTrace.d.cts +20 -24
  7. package/dist/autoTrace.d.ts +20 -24
  8. package/dist/autoTrace.js +1 -1
  9. package/dist/{babelPlugin-C0Im6AZ2.cjs → babelPlugin-BpEeVvk4.cjs} +73 -25
  10. package/dist/babelPlugin-BpEeVvk4.cjs.map +1 -0
  11. package/dist/{babelPlugin-hS2Hb2vt.js → babelPlugin-PgjdBuQe.js} +73 -25
  12. package/dist/babelPlugin-PgjdBuQe.js.map +1 -0
  13. package/dist/{http-BkL24D7v.cjs → http-CWOvmnGL.cjs} +3 -3
  14. package/dist/{http-BkL24D7v.cjs.map → http-CWOvmnGL.cjs.map} +1 -1
  15. package/dist/{http-Cotx6kLL.js → http-DeWpv44r.js} +3 -3
  16. package/dist/{http-Cotx6kLL.js.map → http-DeWpv44r.js.map} +1 -1
  17. package/dist/{index-V6ECPulQ.d.cts → index-Dx3MwCB4.d.cts} +263 -17
  18. package/dist/{index-V6ECPulQ.d.ts → index-Dx3MwCB4.d.ts} +263 -17
  19. package/dist/index.cjs +2 -2
  20. package/dist/index.d.cts +2 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +2 -2
  23. package/dist/node.cjs +3 -3
  24. package/dist/node.d.cts +2 -2
  25. package/dist/node.d.ts +2 -2
  26. package/dist/node.js +3 -3
  27. package/dist/{registryCommand-DdE8cNOX.js → registryCommand-D1VgfJjC.js} +341 -46
  28. package/dist/registryCommand-D1VgfJjC.js.map +1 -0
  29. package/dist/replayCli.js +1 -1
  30. package/dist/seedCli.js +1 -1
  31. package/dist/{src-CrV0INwT.js → src-CFD_cP43.js} +64 -34
  32. package/dist/src-CFD_cP43.js.map +1 -0
  33. package/dist/{src-BJ5a-chk.cjs → src-CxsswRYd.cjs} +70 -40
  34. package/dist/src-CxsswRYd.cjs.map +1 -0
  35. package/dist/transform/babel.cjs +1 -1
  36. package/dist/transform/babel.d.cts +2 -9
  37. package/dist/transform/babel.d.ts +2 -9
  38. package/dist/transform/babel.js +1 -1
  39. package/dist/transform/loaderRuntime.cjs +2 -2
  40. package/dist/transform/loaderRuntime.js +2 -2
  41. package/dist/transform/nodeLoader.js +72 -24
  42. package/dist/transform/nodeLoader.js.map +1 -1
  43. package/dist/transform/swc.cjs +1 -1
  44. package/dist/transform/swc.js +1 -1
  45. package/dist/transform/unplugin.cjs +2 -2
  46. package/dist/transform/unplugin.js +2 -2
  47. package/dist/{transform-BL1fJW-C.js → transform-BhazCKOg.js} +2 -2
  48. package/dist/{transform-BL1fJW-C.js.map → transform-BhazCKOg.js.map} +1 -1
  49. package/dist/{transform-C4H7TKW-.cjs → transform-Cdg7CSbP.cjs} +2 -2
  50. package/dist/{transform-C4H7TKW-.cjs.map → transform-Cdg7CSbP.cjs.map} +1 -1
  51. package/package.json +1 -1
  52. package/dist/autoTrace-DPWV1Xzr.cjs.map +0 -1
  53. package/dist/autoTrace-kHOBg49M.js.map +0 -1
  54. package/dist/babelPlugin-C0Im6AZ2.cjs.map +0 -1
  55. package/dist/babelPlugin-hS2Hb2vt.js.map +0 -1
  56. package/dist/registryCommand-DdE8cNOX.js.map +0 -1
  57. package/dist/src-BJ5a-chk.cjs.map +0 -1
  58. package/dist/src-CrV0INwT.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  const require_bamlPeer = require("./bamlPeer-5Ohpq8q9.cjs");
2
- const require_http = require("./http-BkL24D7v.cjs");
3
- const require_autoTrace = require("./autoTrace-DPWV1Xzr.cjs");
2
+ const require_http = require("./http-CWOvmnGL.cjs");
3
+ const require_autoTrace = require("./autoTrace-pZKu5Nk2.cjs");
4
4
  const require_optionalPeer = require("./optionalPeer-CUH756lt.cjs");
5
5
  let superjson = require("superjson");
6
6
  superjson = require_bamlPeer.__toESM(superjson, 1);
@@ -2670,15 +2670,6 @@ function normalizeMockOverrides(mockOverride) {
2670
2670
  } : override);
2671
2671
  }
2672
2672
  //#endregion
2673
- //#region src/streamFinalizationError.ts
2674
- var StreamFinalizationError = class extends Error {
2675
- constructor(message, output) {
2676
- super(message);
2677
- this.output = output;
2678
- this.name = "StreamFinalizationError";
2679
- }
2680
- };
2681
- //#endregion
2682
2673
  //#region src/openaiAgentSdk.ts
2683
2674
  var BitfabOpenAIAgentHandler = class {
2684
2675
  constructor(config) {
@@ -2695,7 +2686,7 @@ var BitfabOpenAIAgentHandler = class {
2695
2686
  if (isStreaming && res?.completed) try {
2696
2687
  await res.completed;
2697
2688
  } catch (error) {
2698
- throw new StreamFinalizationError(error instanceof Error ? error.message : String(error), res.finalOutput);
2689
+ throw new require_autoTrace.StreamFinalizationError(error instanceof Error ? error.message : String(error), res.finalOutput);
2699
2690
  }
2700
2691
  return res?.finalOutput;
2701
2692
  };
@@ -3063,7 +3054,7 @@ var BitfabPiIntegration = class {
3063
3054
  finalize: (result) => {
3064
3055
  const finalMessage = result;
3065
3056
  const text = messageText(finalMessage);
3066
- if (failed(finalMessage)) throw new StreamFinalizationError(finalMessage?.errorMessage ?? `Agent run ${finalMessage?.stopReason}`, text);
3057
+ if (failed(finalMessage)) throw new require_autoTrace.StreamFinalizationError(finalMessage?.errorMessage ?? `Agent run ${finalMessage?.stopReason}`, text);
3067
3058
  return text;
3068
3059
  }
3069
3060
  }, callReturningFinalMessage)(...args).then(() => void 0);
@@ -3082,7 +3073,7 @@ var BitfabPiIntegration = class {
3082
3073
  const recordFinalMessage = async (result) => {
3083
3074
  const message = await result.result();
3084
3075
  llmSpan?.addContext(usageContext(message, model));
3085
- if (failed(message)) throw new StreamFinalizationError(message.errorMessage ?? `Model request ${message.stopReason}`, message);
3076
+ if (failed(message)) throw new require_autoTrace.StreamFinalizationError(message.errorMessage ?? `Model request ${message.stopReason}`, message);
3086
3077
  return message;
3087
3078
  };
3088
3079
  const traced = this.host.withSpan(this.traceFunctionKey, {
@@ -5557,7 +5548,7 @@ var BitfabVercelAiHandler = class {
5557
5548
  type: "llm",
5558
5549
  finalize: async () => {
5559
5550
  const output = await summary;
5560
- if (output.error !== void 0) throw new StreamFinalizationError(output.error, output);
5551
+ if (output.error !== void 0) throw new require_autoTrace.StreamFinalizationError(output.error, output);
5561
5552
  return output;
5562
5553
  },
5563
5554
  surface: "inherit",
@@ -5654,6 +5645,9 @@ function runWithSpanStack(stack, fn) {
5654
5645
  throw error;
5655
5646
  }
5656
5647
  }
5648
+ function finalizedLater(finalize, result) {
5649
+ return Promise.resolve().then(() => finalize(result));
5650
+ }
5657
5651
  function isAsyncIterable(value) {
5658
5652
  return value !== null && typeof value === "object" && typeof value[Symbol.asyncIterator] === "function";
5659
5653
  }
@@ -5799,6 +5793,15 @@ function extractContextFromCollector(collector) {
5799
5793
  }
5800
5794
  }
5801
5795
  const BOUND_FUNCTION_NAME_PREFIX = /^bound /;
5796
+ function unboundName(method) {
5797
+ const name = method.name.replace(BOUND_FUNCTION_NAME_PREFIX, "");
5798
+ return name === "" ? void 0 : name;
5799
+ }
5800
+ function requiredMethodName(method, error) {
5801
+ const name = unboundName(method);
5802
+ if (name === void 0) throw new require_http.BitfabError(error);
5803
+ return name;
5804
+ }
5802
5805
  function discoveredSpanType(definition, nodeConfiguration) {
5803
5806
  const recordsModelCall = definition.baml === true || definition.jev === true || definition.clientCall !== void 0;
5804
5807
  const ownType = recordsModelCall ? "llm" : "function";
@@ -6169,9 +6172,9 @@ var Bitfab = class {
6169
6172
  const innermost = stack[stack.length - 1];
6170
6173
  return innermost === void 0 ? traceFunctionKey : rootTraceFunctionKeyOfTrace(innermost.traceId, traceFunctionKey);
6171
6174
  };
6172
- const recordsSpan = (entry, spanName, declared) => {
6175
+ const recordsSpan = (entry, spanName, declared, llmCall = false) => {
6173
6176
  const contentOff = !declared && self.simulationPlan.contentOffNow(rootTraceFunctionKeyOfEntry(entry), spanName);
6174
- const countsTowardCapturedSubtree = !declared && !contentOff;
6177
+ const countsTowardCapturedSubtree = !declared && !contentOff && !llmCall;
6175
6178
  const refusedBy = entry.depth >= maxDepth ? "max_depth" : countsTowardCapturedSubtree && capturedSubtreeCount >= maxCapturedSubtreeSpans ? "max_captured_subtree_spans" : void 0;
6176
6179
  if (refusedBy !== void 0) {
6177
6180
  truncate(refusedBy);
@@ -6190,7 +6193,10 @@ var Bitfab = class {
6190
6193
  if (nodeConfiguration?.capture === false) return require_autoTrace.clearAutoTraceNodeConfiguration(invokeFn);
6191
6194
  const spanName = nodeConfiguration?.name ?? definition.name;
6192
6195
  const declaredNode = nodeConfiguration !== void 0;
6193
- if (!recordsSpan(entry, spanName, declaredNode)) return invokeWithoutNode();
6196
+ const clientCall = require_autoTrace.clientCallProvider(definition.clientCall);
6197
+ const llmCall = definition.baml === true || definition.jev === true || clientCall !== void 0;
6198
+ if (!recordsSpan(entry, spanName, declaredNode, llmCall)) return invokeWithoutNode();
6199
+ const streamRecording = clientCall !== void 0 && require_autoTrace.clientCallStreams(clientCall, definition.clientCallMethod ?? simpleName ?? "", inputs[0]) ? require_autoTrace.sharedClientCallStreamRecording(spanDetails, clientCall, inputs[0]) : void 0;
6194
6200
  const mockOnReplay = nodeConfiguration?.mockOnReplay ?? options.mockOnReplayDefault;
6195
6201
  const nodeExperimentId = nodeConfiguration === void 0 ? void 0 : resolveSpanExperimentId(nodeConfiguration);
6196
6202
  const childOptions = {
@@ -6207,11 +6213,14 @@ var Bitfab = class {
6207
6213
  ...nodeExperimentId !== void 0 && { experimentId: nodeExperimentId },
6208
6214
  ...mockOnReplay !== void 0 && { mockOnReplay },
6209
6215
  ...nodeConfiguration?.replayReusable !== void 0 && { replayReusable: nodeConfiguration.replayReusable },
6210
- ...nodeConfiguration?.finalize !== void 0 && { finalize: nodeConfiguration.finalize }
6216
+ ...nodeConfiguration?.finalize !== void 0 && { finalize: nodeConfiguration.finalize },
6217
+ ...streamRecording !== void 0 && {
6218
+ finalize: () => streamRecording.done,
6219
+ alwaysRunsOnReplay: true
6220
+ }
6211
6221
  };
6212
6222
  const isAsync = definition.async === true;
6213
- const clientCall = require_autoTrace.clientCallProvider(definition.clientCall);
6214
- return openChild(entry, childOptions, inputs, isAsync, definition.baml === true ? () => invokeAutoTracedBaml(invokeFn, isAsync) : definition.jev === true ? () => recordAutoTracedJev(invokeFn, getCurrentSpan()) : clientCall !== void 0 ? () => require_autoTrace.recordAutoTracedClientCall(clientCall, invokeFn, inputs[0], getCurrentSpan()) : invokeFn);
6223
+ return openChild(entry, childOptions, inputs, isAsync, definition.baml === true ? () => invokeAutoTracedBaml(invokeFn, isAsync) : definition.jev === true ? () => recordAutoTracedJev(invokeFn, getCurrentSpan()) : streamRecording !== void 0 ? () => streamRecording.start(getCurrentSpan(), invokeFn) : clientCall !== void 0 ? () => require_autoTrace.recordAutoTracedClientCall(clientCall, invokeFn, inputs[0], getCurrentSpan()) : invokeFn);
6215
6224
  },
6216
6225
  invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link, spanDetails) {
6217
6226
  if (excluded.has(nestedName) || excluded.has(nestedFunctionName) || !recordsSpan(entry, nestedName, true)) return invokeFn();
@@ -6521,8 +6530,7 @@ var Bitfab = class {
6521
6530
  return wrappedFn;
6522
6531
  }
6523
6532
  wrapJev(method, options) {
6524
- const methodName = method.name.replace(BOUND_FUNCTION_NAME_PREFIX, "");
6525
- if (!methodName) throw new require_http.BitfabError("wrapJev requires a named function (e.g., jev.systemOne.bind(jev)).");
6533
+ const name = requiredMethodName(method, "wrapJev requires a named function (e.g., jev.systemOne.bind(jev)).");
6526
6534
  const wrappedFn = async (...args) => {
6527
6535
  const span = getCurrentSpan();
6528
6536
  const startedAt = Date.now();
@@ -6536,22 +6544,32 @@ var Bitfab = class {
6536
6544
  };
6537
6545
  Object.defineProperty(wrappedFn, "name", {
6538
6546
  configurable: true,
6539
- value: methodName
6547
+ value: name
6540
6548
  });
6541
6549
  return wrappedFn;
6542
6550
  }
6543
6551
  wrapOpenRouter(method, options) {
6544
- return this.wrapClientCall(require_autoTrace.OPENROUTER, "wrapOpenRouter requires a named function (e.g., openai.chat.completions.create.bind(openai.chat.completions)).", method, options);
6552
+ return this.wrapClientCall(require_autoTrace.OPENROUTER, method, options, requiredMethodName(method, "wrapOpenRouter requires a named function (e.g., openai.chat.completions.create.bind(openai.chat.completions))."));
6545
6553
  }
6546
6554
  wrapAnthropic(method, options) {
6547
- return this.wrapClientCall(require_autoTrace.ANTHROPIC, "wrapAnthropic requires a named function (e.g., anthropic.messages.create.bind(anthropic.messages)).", method, options);
6555
+ return this.wrapClientCall(require_autoTrace.ANTHROPIC, method, options, requiredMethodName(method, "wrapAnthropic requires a named function (e.g., anthropic.messages.create.bind(anthropic.messages))."));
6548
6556
  }
6549
6557
  wrapOpenAIResponses(method, options) {
6550
- return this.wrapClientCall(require_autoTrace.OPENAI_RESPONSES, "wrapOpenAIResponses requires a named function (e.g., openai.responses.create.bind(openai.responses)).", method, options);
6558
+ return this.wrapClientCall(require_autoTrace.OPENAI_RESPONSES, method, options, requiredMethodName(method, "wrapOpenAIResponses requires a named function (e.g., openai.responses.create.bind(openai.responses))."));
6559
+ }
6560
+ wrapOpenAIChat(method, options) {
6561
+ return this.wrapClientCall(require_autoTrace.OPENAI_CHAT, method, options, requiredMethodName(method, "wrapOpenAIChat requires a named function (e.g., openai.chat.completions.create.bind(openai.chat.completions))."));
6562
+ }
6563
+ wrapOpenAIEmbeddings(method, options) {
6564
+ return this.wrapClientCall(require_autoTrace.OPENAI_EMBEDDINGS, method, options, requiredMethodName(method, "wrapOpenAIEmbeddings requires a named function (e.g., openai.embeddings.create.bind(openai.embeddings))."));
6565
+ }
6566
+ wrapOpenAITranscriptions(method, options) {
6567
+ return this.wrapClientCall(require_autoTrace.OPENAI_TRANSCRIPTIONS, method, options, requiredMethodName(method, "wrapOpenAITranscriptions requires a named function (e.g., openai.audio.transcriptions.create.bind(openai.audio.transcriptions))."));
6568
+ }
6569
+ wrapGemini(method, options) {
6570
+ return this.wrapClientCall(require_autoTrace.GEMINI, method, options, unboundName(method) ?? "generateContent");
6551
6571
  }
6552
- wrapClientCall(provider, anonymousError, method, options) {
6553
- const methodName = method.name.replace(BOUND_FUNCTION_NAME_PREFIX, "");
6554
- if (!methodName) throw new require_http.BitfabError(anonymousError);
6572
+ wrapClientCall(provider, method, options, name) {
6555
6573
  const wrappedFn = async (...args) => {
6556
6574
  const span = getCurrentSpan();
6557
6575
  const startedAt = Date.now();
@@ -6572,7 +6590,7 @@ var Bitfab = class {
6572
6590
  };
6573
6591
  Object.defineProperty(wrappedFn, "name", {
6574
6592
  configurable: true,
6575
- value: methodName
6593
+ value: name
6576
6594
  });
6577
6595
  return wrappedFn;
6578
6596
  }
@@ -6749,9 +6767,9 @@ var Bitfab = class {
6749
6767
  }
6750
6768
  };
6751
6769
  const recordSpan = (result) => {
6752
- if (options.finalize) self.httpClient.trackDeferred(Promise.resolve().then(() => options.finalize(result)).then((output) => sendSpan({ result: output })).catch((error) => sendSpan({
6753
- result: error instanceof StreamFinalizationError ? error.output : void 0,
6754
- error: error instanceof StreamFinalizationError ? error.message : error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
6770
+ if (options.finalize) self.httpClient.trackDeferred(finalizedLater(options.finalize, result).then((output) => sendSpan({ result: output })).catch((error) => sendSpan({
6771
+ result: error instanceof require_autoTrace.StreamFinalizationError ? error.output : void 0,
6772
+ error: error instanceof require_autoTrace.StreamFinalizationError ? error.message : error instanceof Error ? `finalize failed: ${error.message}` : `finalize failed: ${String(error)}`
6755
6773
  })));
6756
6774
  else sendSpan({ result });
6757
6775
  };
@@ -6800,7 +6818,7 @@ var Bitfab = class {
6800
6818
  reuseAllowed: options.replayReusable === true,
6801
6819
  canReuseOutput: options.finalize === void 0 && options.replayOutput === void 0 && !fn.constructor.name.includes("Generator")
6802
6820
  });
6803
- if (decision.mock) {
6821
+ if (decision.mock && options.alwaysRunsOnReplay !== true) {
6804
6822
  sendSpan({
6805
6823
  result: decision.output,
6806
6824
  mocked: true,
@@ -6851,8 +6869,8 @@ var Bitfab = class {
6851
6869
  return output;
6852
6870
  };
6853
6871
  const resolveBaseOutput = () => options.replayOutput !== void 0 ? options.replayOutput() : resolveRecordedOutput();
6854
- const shouldMockWithBaseStrategy = replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true;
6855
- if (replayCtxForMock.mockOverrides?.length) {
6872
+ const shouldMockWithBaseStrategy = options.alwaysRunsOnReplay !== true && (replayCtxForMock.mockStrategy === "all" || replayCtxForMock.mockStrategy === "marked" && options.mockOnReplay === true);
6873
+ if (replayCtxForMock.mockOverrides?.length && options.alwaysRunsOnReplay !== true) {
6856
6874
  const nodeMeta = {
6857
6875
  traceFunctionKey,
6858
6876
  spanName: baseSpanParams.spanName,
@@ -7214,7 +7232,7 @@ var Bitfab = class {
7214
7232
  await runWithSeedContext({ traceId }, async () => target(...args));
7215
7233
  } finally {
7216
7234
  try {
7217
- const { flushTraces } = await Promise.resolve().then(() => require("./http-BkL24D7v.cjs")).then((n) => n.http_exports);
7235
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-CWOvmnGL.cjs")).then((n) => n.http_exports);
7218
7236
  await flushTraces(3e4);
7219
7237
  } finally {
7220
7238
  unrecorded = activeTraceStates.delete(traceId);
@@ -7318,6 +7336,18 @@ var BitfabFunction = class {
7318
7336
  wrapOpenAIResponses(method, options) {
7319
7337
  return this.client.wrapOpenAIResponses(method, options);
7320
7338
  }
7339
+ wrapOpenAIChat(method, options) {
7340
+ return this.client.wrapOpenAIChat(method, options);
7341
+ }
7342
+ wrapOpenAIEmbeddings(method, options) {
7343
+ return this.client.wrapOpenAIEmbeddings(method, options);
7344
+ }
7345
+ wrapOpenAITranscriptions(method, options) {
7346
+ return this.client.wrapOpenAITranscriptions(method, options);
7347
+ }
7348
+ wrapGemini(method, options) {
7349
+ return this.client.wrapGemini(method, options);
7350
+ }
7321
7351
  };
7322
7352
  //#endregion
7323
7353
  //#region src/finalizers.ts
@@ -7420,7 +7450,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
7420
7450
  metadata: seedCase.metadata,
7421
7451
  sessionId: seedCase.sessionId
7422
7452
  }));
7423
- const { flushTraces } = await Promise.resolve().then(() => require("./http-BkL24D7v.cjs")).then((n) => n.http_exports);
7453
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-CWOvmnGL.cjs")).then((n) => n.http_exports);
7424
7454
  await flushTraces(3e4);
7425
7455
  return {
7426
7456
  pipeline,
@@ -7670,4 +7700,4 @@ Object.defineProperty(exports, "serializeReplayResult", {
7670
7700
  }
7671
7701
  });
7672
7702
 
7673
- //# sourceMappingURL=src-BJ5a-chk.cjs.map
7703
+ //# sourceMappingURL=src-CxsswRYd.cjs.map