agent-inspect 1.0.2 → 1.0.3

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.
@@ -2537,6 +2537,9 @@ async function inspectRun(name, fn, options) {
2537
2537
  if (typeof fn !== "function") {
2538
2538
  throw new TypeError("inspectRun requires `fn` to be a function");
2539
2539
  }
2540
+ if (options?.enabled === false) {
2541
+ return Promise.resolve(fn());
2542
+ }
2540
2543
  const runName = normalizeRunName(name);
2541
2544
  const runId = createRunId();
2542
2545
  const traceDir = resolveTraceDir({ dir: options?.traceDir });
@@ -2616,6 +2619,25 @@ async function inspectRun(name, fn, options) {
2616
2619
  });
2617
2620
  }
2618
2621
 
2622
+ // packages/core/src/maybe-inspect-run.ts
2623
+ var ENABLED_ENV_VALUES = /* @__PURE__ */ new Set(["1", "true", "yes", "on", "enabled"]);
2624
+ function isAgentInspectEnabled(value) {
2625
+ if (value === void 0) return false;
2626
+ const normalized = value.trim().toLowerCase();
2627
+ if (normalized === "") return false;
2628
+ return ENABLED_ENV_VALUES.has(normalized);
2629
+ }
2630
+ async function maybeInspectRun(name, fn, options) {
2631
+ if (typeof fn !== "function") {
2632
+ throw new TypeError("maybeInspectRun requires `fn` to be a function");
2633
+ }
2634
+ const enabled = options?.enabled !== void 0 ? options.enabled : isAgentInspectEnabled(process.env.AGENT_INSPECT);
2635
+ if (!enabled) {
2636
+ return Promise.resolve(fn());
2637
+ }
2638
+ return inspectRun(name, fn, options);
2639
+ }
2640
+
2619
2641
  // packages/core/src/step.ts
2620
2642
  function normalizeStepName(name) {
2621
2643
  if (typeof name !== "string" || name.trim() === "") {
@@ -3632,6 +3654,7 @@ exports.getTraceFilePath = getTraceFilePath;
3632
3654
  exports.hasActiveContext = hasActiveContext;
3633
3655
  exports.initializeTraceFile = initializeTraceFile;
3634
3656
  exports.inspectRun = inspectRun;
3657
+ exports.isAgentInspectEnabled = isAgentInspectEnabled;
3635
3658
  exports.isAgentInspectTrace = isAgentInspectTrace;
3636
3659
  exports.isSilentContext = isSilentContext;
3637
3660
  exports.isStepStatus = isStepStatus;
@@ -3642,6 +3665,7 @@ exports.loadLogIngestConfig = loadLogIngestConfig;
3642
3665
  exports.manualTraceEventsToComparableRun = manualTraceEventsToComparableRun;
3643
3666
  exports.manualTraceEventsToRunTree = manualTraceEventsToRunTree;
3644
3667
  exports.matchMapping = matchMapping;
3668
+ exports.maybeInspectRun = maybeInspectRun;
3645
3669
  exports.mergeExportDefaults = mergeExportDefaults;
3646
3670
  exports.mergeLogIngestConfig = mergeLogIngestConfig;
3647
3671
  exports.observe = observe;