@bitfab/sdk 0.65.5 → 0.65.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.
@@ -29,7 +29,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  enumerable: true
30
30
  }) : target, mod));
31
31
  //#endregion
32
- const require_autoTrace = require("./autoTrace-KM9pYqk9.cjs");
32
+ const require_autoTrace = require("./autoTrace-CQw0qMBt.cjs");
33
33
  let _opentelemetry_api = require("@opentelemetry/api");
34
34
  let _opentelemetry_core = require("@opentelemetry/core");
35
35
  let _opentelemetry_resources = require("@opentelemetry/resources");
@@ -58,7 +58,7 @@ var CategoriesClient = class {
58
58
  const AssertionCategoriesClient = CategoriesClient;
59
59
  //#endregion
60
60
  //#region src/version.generated.ts
61
- const __version__ = "0.65.5";
61
+ const __version__ = "0.65.7";
62
62
  const __packageName__ = "@bitfab/sdk";
63
63
  //#endregion
64
64
  //#region src/constants.ts
@@ -832,6 +832,7 @@ var SimulationPlan = class {
832
832
  this.rootWaitOver = false;
833
833
  this.held = [];
834
834
  this.stopped = false;
835
+ this.readStarted = false;
835
836
  this.loaded = new Promise((resolve) => {
836
837
  this.resolveLoaded = resolve;
837
838
  });
@@ -842,8 +843,16 @@ var SimulationPlan = class {
842
843
  disabled() {
843
844
  return !this.enabled || simulationPlanEnvDisabled();
844
845
  }
846
+ idle() {
847
+ return !this.readStarted && this.source.canRead?.() === false;
848
+ }
845
849
  refresh() {
850
+ if (this.idle()) return;
851
+ this.read();
852
+ }
853
+ read() {
846
854
  if (this.stopped || this.disabled()) return;
855
+ this.readStarted = true;
847
856
  this.policyRefresh.run(() => this.source.getSimulationPlan(), (body) => {
848
857
  const parsed = parseSimulationPlan(body);
849
858
  if (parsed === null) this.scheduleRetry("sim-plan-unreadable", "the sim plan response was not understood");
@@ -888,7 +897,7 @@ var SimulationPlan = class {
888
897
  }
889
898
  waitForFirstRead() {
890
899
  this.refresh();
891
- if (this.rootWaitOver || this.disabled() || !this.holdingForFirstRead()) return;
900
+ if (this.rootWaitOver || this.disabled() || this.idle() || !this.holdingForFirstRead()) return;
892
901
  if (this.rootWait === void 0) {
893
902
  this.rootWait = new Promise((resolve) => {
894
903
  this.resolveRootWait = resolve;
@@ -904,11 +913,11 @@ var SimulationPlan = class {
904
913
  return !this.disabled() && this.contentOffByKey === void 0 && this.firstReadOver;
905
914
  }
906
915
  firstLoad() {
907
- if (this.contentOffByKey !== void 0 || this.stopped || this.disabled()) return;
916
+ if (this.contentOffByKey !== void 0 || this.stopped || this.disabled() || this.idle()) return;
908
917
  return this.loaded;
909
918
  }
910
919
  send(payload, traceFunctionKey, submit, drop) {
911
- this.refresh();
920
+ this.read();
912
921
  if (this.disabled() || traceFunctionKey === void 0 || spanNameOf(payload) === void 0 || recordedByFramework(payload)) {
913
922
  submit(payload);
914
923
  return;
@@ -926,7 +935,7 @@ var SimulationPlan = class {
926
935
  this.submitEntry(entry);
927
936
  }
928
937
  sendTrace(payload, submit) {
929
- this.refresh();
938
+ this.read();
930
939
  if (this.disabled() || !this.holdingForFirstRead() || !this.holdsSpanOfTrace(traceIdOf(payload))) {
931
940
  submit(payload);
932
941
  return;
@@ -6748,13 +6757,13 @@ function getCurrentSpan() {
6748
6757
  addContext(context) {
6749
6758
  try {
6750
6759
  if (typeof context !== "object" || context === null) return;
6751
- current.contexts.push(context);
6760
+ current.details.contexts.push(context);
6752
6761
  } catch {}
6753
6762
  },
6754
6763
  setPrompt(prompt) {
6755
6764
  try {
6756
6765
  if (typeof prompt !== "string") return;
6757
- current.prompt = prompt;
6766
+ current.details.prompt = prompt;
6758
6767
  } catch {}
6759
6768
  }
6760
6769
  };
@@ -6881,7 +6890,10 @@ var Bitfab = class {
6881
6890
  serviceUrl: this.serviceUrl,
6882
6891
  timeout: this.timeout
6883
6892
  });
6884
- this.simulationPlan = new SimulationPlan(this.httpClient, config.simulationPlan ?? true);
6893
+ this.simulationPlan = new SimulationPlan({
6894
+ getSimulationPlan: () => this.httpClient.getSimulationPlan(),
6895
+ canRead: () => this.canReadSimulationPlan()
6896
+ }, config.simulationPlan ?? true);
6885
6897
  this.httpClient.externalSpanTransform = (payload, submit, drop) => this.applySimulationPlan(payload, submit, drop);
6886
6898
  this.httpClient.externalTraceTransform = (payload, submit) => this.simulationPlan.sendTrace(payload, submit);
6887
6899
  this.httpClient.releaseHeldExternalSpans = (timeoutMs) => this.simulationPlan.release(timeoutMs);
@@ -7035,7 +7047,7 @@ var Bitfab = class {
7035
7047
  };
7036
7048
  const autoTraceContext = {
7037
7049
  traceFunctionKey,
7038
- invoke(definition, inputs, invokeFn, entry, nodeConfiguration) {
7050
+ invoke(definition, inputs, invokeFn, entry, spanDetails, nodeConfiguration) {
7039
7051
  const nameParts = definition.name.split(".");
7040
7052
  const simpleName = nameParts[nameParts.length - 1];
7041
7053
  const invokeWithoutNode = () => nodeConfiguration === void 0 ? invokeFn() : require_autoTrace.clearAutoTraceNodeConfiguration(invokeFn);
@@ -7055,6 +7067,7 @@ var Bitfab = class {
7055
7067
  functionId: definition.id,
7056
7068
  captureContent: true,
7057
7069
  autoTraceDefinition: definition,
7070
+ spanDetails,
7058
7071
  ...declaredNode && { declaredNode },
7059
7072
  ...nodeExperimentId !== void 0 && { experimentId: nodeExperimentId },
7060
7073
  ...mockOnReplay !== void 0 && { mockOnReplay },
@@ -7063,7 +7076,7 @@ var Bitfab = class {
7063
7076
  };
7064
7077
  return openChild(entry, childOptions, inputs, definition.async === true, invokeFn);
7065
7078
  },
7066
- invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link) {
7079
+ invokeNestedRoot(nestedName, nestedFunctionName, inputs, invokeFn, entry, link, spanDetails) {
7067
7080
  if (excluded.has(nestedName) || excluded.has(nestedFunctionName) || !recordsSpan(entry, nestedName, true)) return invokeFn();
7068
7081
  const childOptions = {
7069
7082
  name: nestedName,
@@ -7073,6 +7086,7 @@ var Bitfab = class {
7073
7086
  instrumentation: "trace",
7074
7087
  captureContent: true,
7075
7088
  declaredNode: true,
7089
+ spanDetails,
7076
7090
  ...link !== void 0 && { nestedTrace: link }
7077
7091
  };
7078
7092
  return openChild(entry, childOptions, inputs, false, invokeFn);
@@ -7091,13 +7105,15 @@ var Bitfab = class {
7091
7105
  }
7092
7106
  const link = getReplayContext() || inSeedScope() ? void 0 : { traceFunctionKey };
7093
7107
  const rootName = rootNameFor(this);
7094
- return require_autoTrace.invokeThroughAutoTraceEntries(enclosing, (entry, next) => entry.context.invokeNestedRoot(rootName, name, args, next, entry, link), () => {
7108
+ const spanDetails = { contexts: [] };
7109
+ return require_autoTrace.invokeThroughAutoTraceEntries(enclosing, (entry, next) => entry.context.invokeNestedRoot(rootName, name, args, next, entry, link, spanDetails), () => {
7095
7110
  if (link === void 0) return runRootFunction(this, args);
7096
7111
  const innermost = enclosing[enclosing.length - 1];
7097
7112
  const innermostStack = (require_autoTrace.currentAutoTraceEntries().find((entry) => entry.context === innermost.context) ?? innermost).spanStack;
7098
7113
  const copy = innermostStack[innermostStack.length - 1];
7099
7114
  const detachedRoot = buildTracedRoot({
7100
7115
  ...rootOptions,
7116
+ spanDetails,
7101
7117
  ...copy !== void 0 && { enclosingTrace: {
7102
7118
  traceId: copy.traceId,
7103
7119
  spanId: copy.spanId,
@@ -7149,6 +7165,9 @@ var Bitfab = class {
7149
7165
  if (!this.isCaptureConfigured() && !getReplayContext() && !inSeedScope()) return false;
7150
7166
  return this.resolveApiKey() !== void 0;
7151
7167
  }
7168
+ canReadSimulationPlan() {
7169
+ return ((this.captureConfiguredInCode ?? this.captureConfiguredFromEnv ?? readBooleanEnv(CAPTURE_ENABLED_ENV) ?? true) || getReplayContext() !== null || inSeedScope()) && this.findApiKey(true) !== void 0;
7170
+ }
7152
7171
  prepareFrameworkIntegration() {
7153
7172
  if (this.isCaptureConfigured() && this.strict) this.resolveApiKey();
7154
7173
  }
@@ -7263,7 +7282,7 @@ var Bitfab = class {
7263
7282
  if (!root) return;
7264
7283
  const rootId = `${root.traceId}:${root.spanId}`;
7265
7284
  if (recordedRoots.has(rootId)) return;
7266
- root.contexts.push(context);
7285
+ root.details.contexts.push(context);
7267
7286
  recordedRoots.add(rootId);
7268
7287
  }
7269
7288
  }, options);
@@ -7404,7 +7423,7 @@ var Bitfab = class {
7404
7423
  const newContext = {
7405
7424
  traceId,
7406
7425
  spanId,
7407
- contexts: [],
7426
+ details: options.spanDetails ?? { contexts: [] },
7408
7427
  spanName: options.name ?? options.nameFor?.(this) ?? qualifiedSpanName(this, functionNameAtOpen) ?? traceFunctionKey,
7409
7428
  rootTraceFunctionKey: rootTraceFunctionKeyOfTrace(traceId, traceFunctionKey),
7410
7429
  instrumentation: options.instrumentation ?? "span",
@@ -7468,8 +7487,8 @@ var Bitfab = class {
7468
7487
  if (!(activeTraceStates.get(traceId)?.dropped === true)) self.sendWrapperSpan({
7469
7488
  ...baseSpanParams,
7470
7489
  ...params,
7471
- contexts: newContext.contexts,
7472
- prompt: newContext.prompt,
7490
+ contexts: newContext.details.contexts,
7491
+ prompt: newContext.details.prompt,
7473
7492
  endedAt,
7474
7493
  ...experimentId !== void 0 && { experimentId },
7475
7494
  ...replayCtx?.inputSourceSpanId && { inputSourceSpanId: replayCtx.inputSourceSpanId }
@@ -8431,4 +8450,4 @@ Object.defineProperty(exports, "serializeReplayResult", {
8431
8450
  }
8432
8451
  });
8433
8452
 
8434
- //# sourceMappingURL=src-BRKm0P_S.cjs.map
8453
+ //# sourceMappingURL=src-DgkDt32g.cjs.map