bitfab 0.64.6 → 0.64.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.
package/dist/index.d.cts CHANGED
@@ -452,6 +452,18 @@ interface ReplayContext {
452
452
  dbSnapshotAccessed?: boolean;
453
453
  }
454
454
 
455
+ type FlagScalar = string | number | boolean | null;
456
+ type FlagValue = FlagScalar | FlagScalar[];
457
+ type ReplayEnvironment = "local" | "ci" | "cloud_replay";
458
+ interface ReplayInvocation {
459
+ flags: Record<string, FlagValue>;
460
+ sdk: {
461
+ language: "typescript";
462
+ version: string;
463
+ };
464
+ environment: ReplayEnvironment;
465
+ }
466
+
455
467
  interface SimulationPlanNode {
456
468
  traceFunctionKey: string;
457
469
  name: string;
@@ -697,7 +709,7 @@ declare class HttpClient {
697
709
  * Start a replay session by fetching historical traces.
698
710
  * Blocking call - creates an experiment and returns lightweight item references.
699
711
  */
700
- startReplay(traceFunctionKey: string, limit: number | undefined, traceIds?: string[], name?: string, codeChangeDescription?: string | null, codeChangeFiles?: CodeChangeFile[] | null, includeDbBranchLease?: boolean, experimentGroupId?: string, datasetIds?: string[], graderIds?: string[], dbBranchSettings?: DbBranchSettings, attempts?: number, includeOriginalMetadata?: boolean, onlyWithAssertions?: boolean, skipAssertionJudging?: boolean, experimentalSelectiveReplay?: SelectiveReplayOptions, notes?: string, metadata?: Record<string, string>, dryRun?: boolean): Promise<StartReplayResponse>;
712
+ startReplay(traceFunctionKey: string, limit: number | undefined, traceIds?: string[], name?: string, codeChangeDescription?: string | null, codeChangeFiles?: CodeChangeFile[] | null, includeDbBranchLease?: boolean, experimentGroupId?: string, datasetIds?: string[], graderIds?: string[], dbBranchSettings?: DbBranchSettings, attempts?: number, includeOriginalMetadata?: boolean, onlyWithAssertions?: boolean, skipAssertionJudging?: boolean, experimentalSelectiveReplay?: SelectiveReplayOptions, notes?: string, metadata?: Record<string, string>, dryRun?: boolean, invocation?: ReplayInvocation): Promise<StartReplayResponse>;
701
713
  resumeReplay(experimentId: string, traceFunctionKey: string, codeChangeFiles?: CodeChangeFile[] | null, force?: boolean): Promise<ResumeReplayResponse>;
702
714
  /**
703
715
  * Fetch an external span by ID.
@@ -3980,7 +3992,7 @@ interface CommitRef {
3980
3992
  /**
3981
3993
  * SDK version from package.json (injected at build time)
3982
3994
  */
3983
- declare const __version__ = "0.64.6";
3995
+ declare const __version__ = "0.64.7";
3984
3996
 
3985
3997
  /**
3986
3998
  * Constants for the Bitfab SDK.
package/dist/index.d.ts CHANGED
@@ -452,6 +452,18 @@ interface ReplayContext {
452
452
  dbSnapshotAccessed?: boolean;
453
453
  }
454
454
 
455
+ type FlagScalar = string | number | boolean | null;
456
+ type FlagValue = FlagScalar | FlagScalar[];
457
+ type ReplayEnvironment = "local" | "ci" | "cloud_replay";
458
+ interface ReplayInvocation {
459
+ flags: Record<string, FlagValue>;
460
+ sdk: {
461
+ language: "typescript";
462
+ version: string;
463
+ };
464
+ environment: ReplayEnvironment;
465
+ }
466
+
455
467
  interface SimulationPlanNode {
456
468
  traceFunctionKey: string;
457
469
  name: string;
@@ -697,7 +709,7 @@ declare class HttpClient {
697
709
  * Start a replay session by fetching historical traces.
698
710
  * Blocking call - creates an experiment and returns lightweight item references.
699
711
  */
700
- startReplay(traceFunctionKey: string, limit: number | undefined, traceIds?: string[], name?: string, codeChangeDescription?: string | null, codeChangeFiles?: CodeChangeFile[] | null, includeDbBranchLease?: boolean, experimentGroupId?: string, datasetIds?: string[], graderIds?: string[], dbBranchSettings?: DbBranchSettings, attempts?: number, includeOriginalMetadata?: boolean, onlyWithAssertions?: boolean, skipAssertionJudging?: boolean, experimentalSelectiveReplay?: SelectiveReplayOptions, notes?: string, metadata?: Record<string, string>, dryRun?: boolean): Promise<StartReplayResponse>;
712
+ startReplay(traceFunctionKey: string, limit: number | undefined, traceIds?: string[], name?: string, codeChangeDescription?: string | null, codeChangeFiles?: CodeChangeFile[] | null, includeDbBranchLease?: boolean, experimentGroupId?: string, datasetIds?: string[], graderIds?: string[], dbBranchSettings?: DbBranchSettings, attempts?: number, includeOriginalMetadata?: boolean, onlyWithAssertions?: boolean, skipAssertionJudging?: boolean, experimentalSelectiveReplay?: SelectiveReplayOptions, notes?: string, metadata?: Record<string, string>, dryRun?: boolean, invocation?: ReplayInvocation): Promise<StartReplayResponse>;
701
713
  resumeReplay(experimentId: string, traceFunctionKey: string, codeChangeFiles?: CodeChangeFile[] | null, force?: boolean): Promise<ResumeReplayResponse>;
702
714
  /**
703
715
  * Fetch an external span by ID.
@@ -3980,7 +3992,7 @@ interface CommitRef {
3980
3992
  /**
3981
3993
  * SDK version from package.json (injected at build time)
3982
3994
  */
3983
- declare const __version__ = "0.64.6";
3995
+ declare const __version__ = "0.64.7";
3984
3996
 
3985
3997
  /**
3986
3998
  * Constants for the Bitfab SDK.
package/dist/index.js CHANGED
@@ -36,7 +36,7 @@ import {
36
36
  getCurrentTrace,
37
37
  reseedFromRegistry,
38
38
  seedFromRegistry
39
- } from "./chunk-6NUSTEQ6.js";
39
+ } from "./chunk-DIOPUOV3.js";
40
40
  import "./chunk-YWXQM6J3.js";
41
41
  import {
42
42
  BITFAB_PROGRESS_PREFIX,
@@ -45,7 +45,7 @@ import {
45
45
  ReplayError,
46
46
  reportReplayProgress,
47
47
  serializeReplayResult
48
- } from "./chunk-B363XZTL.js";
48
+ } from "./chunk-SZVZU3F6.js";
49
49
  import {
50
50
  BitfabError,
51
51
  DEFAULT_SERVICE_URL,
@@ -53,7 +53,7 @@ import {
53
53
  MixedTracingError,
54
54
  __version__,
55
55
  flushTraces
56
- } from "./chunk-ROZEHSGO.js";
56
+ } from "./chunk-TAGNRN6F.js";
57
57
  import "./chunk-MT36GJMW.js";
58
58
  export {
59
59
  AssertionCategoriesClient,
package/dist/node.cjs CHANGED
@@ -97,7 +97,7 @@ var __version__, __packageName__;
97
97
  var init_version_generated = __esm({
98
98
  "src/version.generated.ts"() {
99
99
  "use strict";
100
- __version__ = "0.64.6";
100
+ __version__ = "0.64.7";
101
101
  __packageName__ = "bitfab";
102
102
  }
103
103
  });
@@ -2911,7 +2911,7 @@ var init_http = __esm({
2911
2911
  * Start a replay session by fetching historical traces.
2912
2912
  * Blocking call - creates an experiment and returns lightweight item references.
2913
2913
  */
2914
- async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetIds, graderIds, dbBranchSettings, attempts, includeOriginalMetadata, onlyWithAssertions, skipAssertionJudging, experimentalSelectiveReplay, notes, metadata, dryRun) {
2914
+ async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetIds, graderIds, dbBranchSettings, attempts, includeOriginalMetadata, onlyWithAssertions, skipAssertionJudging, experimentalSelectiveReplay, notes, metadata, dryRun, invocation) {
2915
2915
  const payload = { traceFunctionKey };
2916
2916
  if (experimentalSelectiveReplay !== void 0) {
2917
2917
  payload.experimentalSelectiveReplay = experimentalSelectiveReplay;
@@ -2972,6 +2972,9 @@ var init_http = __esm({
2972
2972
  if (dryRun) {
2973
2973
  payload.dryRun = true;
2974
2974
  }
2975
+ if (invocation !== void 0) {
2976
+ payload.invocation = invocation;
2977
+ }
2975
2978
  const git = await resolvedGitState();
2976
2979
  if (git && !isEmptyGitState(git)) {
2977
2980
  payload.git = git;
@@ -3767,6 +3770,113 @@ var init_replayInterrupt = __esm({
3767
3770
  }
3768
3771
  });
3769
3772
 
3773
+ // src/replayInvocation.ts
3774
+ function replayEnvironment() {
3775
+ if (readEnv(REPLAY_EXECUTION_TARGET_ENV) === HOSTED_EXECUTION_TARGET) {
3776
+ return "cloud_replay";
3777
+ }
3778
+ if (CI_TRUE_VALUES.has((readEnv(CI_ENV) ?? "").toLowerCase())) {
3779
+ return "ci";
3780
+ }
3781
+ if (CI_PRESENCE_ENV_VARS.some((name) => (readEnv(name) ?? "") !== "")) {
3782
+ return "ci";
3783
+ }
3784
+ return "local";
3785
+ }
3786
+ function flagScalar(value) {
3787
+ if (typeof value === "string") {
3788
+ return value.slice(0, MAX_FLAG_STRING_LENGTH);
3789
+ }
3790
+ if (typeof value === "number") {
3791
+ return Number.isFinite(value) ? value : void 0;
3792
+ }
3793
+ if (typeof value === "boolean" || value === null) {
3794
+ return value;
3795
+ }
3796
+ return void 0;
3797
+ }
3798
+ function flagValue(value) {
3799
+ if (Array.isArray(value)) {
3800
+ const items = value.slice(0, MAX_FLAG_LIST_LENGTH).map(flagScalar);
3801
+ return items.every((item) => item !== void 0) ? items : true;
3802
+ }
3803
+ const scalar = flagScalar(value);
3804
+ return scalar === void 0 ? true : scalar;
3805
+ }
3806
+ function optionFlagName(option) {
3807
+ return OPTION_FLAG_NAMES[option] ?? option.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
3808
+ }
3809
+ function metadataKeys(value) {
3810
+ const keys = Array.isArray(value) ? value.map((pair) => String(pair).split("=")[0]) : typeof value === "object" && value !== null ? Object.keys(value) : void 0;
3811
+ return keys === void 0 ? true : [...new Set(keys)].sort();
3812
+ }
3813
+ function invocationFlags(entries) {
3814
+ const flags = {};
3815
+ const seen = /* @__PURE__ */ new Set();
3816
+ for (const [name, value] of entries) {
3817
+ if (seen.size >= MAX_FLAGS) {
3818
+ break;
3819
+ }
3820
+ if (value === void 0 || seen.has(name) || name.length === 0 || name.length > MAX_FLAG_NAME_LENGTH || SECRET_FLAG_NAME.test(name)) {
3821
+ continue;
3822
+ }
3823
+ flags[name] = flagValue(
3824
+ name === METADATA_FLAG ? metadataKeys(value) : value
3825
+ );
3826
+ seen.add(name);
3827
+ }
3828
+ return flags;
3829
+ }
3830
+ function buildReplayInvocation(entries = []) {
3831
+ return {
3832
+ flags: invocationFlags(entries),
3833
+ sdk: { language: "typescript", version: __version__ },
3834
+ environment: replayEnvironment()
3835
+ };
3836
+ }
3837
+ function safeReplayInvocation(build) {
3838
+ try {
3839
+ return build();
3840
+ } catch {
3841
+ return void 0;
3842
+ }
3843
+ }
3844
+ function cliFlags(options) {
3845
+ return options?.[CLI_FLAGS];
3846
+ }
3847
+ var REPLAY_EXECUTION_TARGET_ENV, HOSTED_EXECUTION_TARGET, CI_ENV, CI_TRUE_VALUES, CI_PRESENCE_ENV_VARS, MAX_FLAGS, MAX_FLAG_NAME_LENGTH, MAX_FLAG_STRING_LENGTH, MAX_FLAG_LIST_LENGTH, SECRET_FLAG_NAME, CLI_FLAGS, METADATA_FLAG, OPTION_FLAG_NAMES;
3848
+ var init_replayInvocation = __esm({
3849
+ "src/replayInvocation.ts"() {
3850
+ "use strict";
3851
+ init_constants();
3852
+ init_readEnv();
3853
+ REPLAY_EXECUTION_TARGET_ENV = "BITFAB_REPLAY_EXECUTION_TARGET";
3854
+ HOSTED_EXECUTION_TARGET = "hosted";
3855
+ CI_ENV = "CI";
3856
+ CI_TRUE_VALUES = /* @__PURE__ */ new Set(["true", "1"]);
3857
+ CI_PRESENCE_ENV_VARS = [
3858
+ "GITHUB_ACTIONS",
3859
+ "GITLAB_CI",
3860
+ "CIRCLECI",
3861
+ "BUILDKITE",
3862
+ "JENKINS_URL",
3863
+ "TF_BUILD"
3864
+ ];
3865
+ MAX_FLAGS = 100;
3866
+ MAX_FLAG_NAME_LENGTH = 100;
3867
+ MAX_FLAG_STRING_LENGTH = 1e3;
3868
+ MAX_FLAG_LIST_LENGTH = 100;
3869
+ SECRET_FLAG_NAME = /key|token|secret|password/i;
3870
+ CLI_FLAGS = /* @__PURE__ */ Symbol("bitfab.replayCliFlags");
3871
+ METADATA_FLAG = "metadata";
3872
+ OPTION_FLAG_NAMES = {
3873
+ maxConcurrency: "concurrency",
3874
+ datasetId: "dataset-ids",
3875
+ datasetIds: "dataset-ids"
3876
+ };
3877
+ }
3878
+ });
3879
+
3770
3880
  // src/selectiveReplay.ts
3771
3881
  function replayNodeKey(node) {
3772
3882
  return JSON.stringify([node.traceFunctionKey, node.spanName]);
@@ -4196,6 +4306,16 @@ function resolveDbBranchSettings(dbBranch) {
4196
4306
  };
4197
4307
  return Object.keys(settings).length === 0 ? void 0 : settings;
4198
4308
  }
4309
+ function explicitReplayOptions(options) {
4310
+ var _a;
4311
+ const explicit = {};
4312
+ for (const name of REPLAY_OPTION_NAMES) {
4313
+ if (options?.[name] !== void 0) {
4314
+ explicit[_a = optionFlagName(name)] ?? (explicit[_a] = options[name]);
4315
+ }
4316
+ }
4317
+ return explicit;
4318
+ }
4199
4319
  function reportReplayProgress(progress) {
4200
4320
  const stderr = typeof process !== "undefined" ? process.stderr : void 0;
4201
4321
  if (!stderr) {
@@ -4707,7 +4827,12 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
4707
4827
  options?.experimentalSelectiveReplay,
4708
4828
  options?.notes,
4709
4829
  options?.metadata,
4710
- options?.dryRun === true
4830
+ options?.dryRun === true,
4831
+ safeReplayInvocation(
4832
+ () => buildReplayInvocation(
4833
+ Object.entries(cliFlags(options) ?? explicitReplayOptions(options))
4834
+ )
4835
+ )
4711
4836
  );
4712
4837
  if (started.items.length === 0) {
4713
4838
  try {
@@ -5099,7 +5224,7 @@ async function writeReplayResultFile(result) {
5099
5224
  }
5100
5225
  }
5101
5226
  }
5102
- var REPLAY_PERSISTENCE_TIMEOUT_MS, MAX_REPLAY_ATTEMPTS, RESUME_CONFLICTING_OPTIONS, CARRIED_OVER_ERROR, BITFAB_PROGRESS_PREFIX, ReplayError, DbBranchReplayError, JUDGE_ASSERTIONS_DEPRECATION_WARNING;
5227
+ var REPLAY_PERSISTENCE_TIMEOUT_MS, MAX_REPLAY_ATTEMPTS, RESUME_CONFLICTING_OPTIONS, CARRIED_OVER_ERROR, REPLAY_OPTION_NAMES, BITFAB_PROGRESS_PREFIX, ReplayError, DbBranchReplayError, JUDGE_ASSERTIONS_DEPRECATION_WARNING;
5103
5228
  var init_replay = __esm({
5104
5229
  "src/replay.ts"() {
5105
5230
  "use strict";
@@ -5112,6 +5237,7 @@ var init_replay = __esm({
5112
5237
  init_replayContext();
5113
5238
  init_replayHeartbeat();
5114
5239
  init_replayInterrupt();
5240
+ init_replayInvocation();
5115
5241
  init_selectiveReplayRuntime();
5116
5242
  init_serialize();
5117
5243
  init_warnOnce();
@@ -5129,6 +5255,37 @@ var init_replay = __esm({
5129
5255
  "experimentalSelectiveReplay"
5130
5256
  ];
5131
5257
  CARRIED_OVER_ERROR = "This item errored in an earlier run of this experiment, before it was resumed.";
5258
+ REPLAY_OPTION_NAMES = [
5259
+ "experimentalSelectiveReplay",
5260
+ "limit",
5261
+ "attempts",
5262
+ "traceIds",
5263
+ "name",
5264
+ "notes",
5265
+ "metadata",
5266
+ "maxConcurrency",
5267
+ "codeChangeDescription",
5268
+ "codeChangeFiles",
5269
+ "mock",
5270
+ "mockOverride",
5271
+ "dbBranch",
5272
+ "experimentGroupId",
5273
+ "datasetId",
5274
+ "datasetIds",
5275
+ "graderIds",
5276
+ "onlyWithAssertions",
5277
+ "skipAssertionJudging",
5278
+ "judgeAssertions",
5279
+ "adaptInputs",
5280
+ "dryRun",
5281
+ "onItemFinish",
5282
+ "onProgress",
5283
+ "onItemStart",
5284
+ "onExperimentStart",
5285
+ "onInterrupt",
5286
+ "resume",
5287
+ "force"
5288
+ ];
5132
5289
  BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
5133
5290
  ReplayError = class extends BitfabError {
5134
5291
  constructor(message, items, experimentId, experimentUrl, cause) {
@@ -11986,6 +12143,7 @@ init_replay();
11986
12143
  init_errors();
11987
12144
  init_replay();
11988
12145
  init_replayInterrupt();
12146
+ init_replayInvocation();
11989
12147
  init_warnOnce();
11990
12148
  function defineReplayRegistry(registry) {
11991
12149
  validateReplayRegistry(registry);