@bitfab/sdk 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
@@ -27,7 +27,7 @@ import {
27
27
  getCurrentTrace,
28
28
  reseedFromRegistry,
29
29
  seedFromRegistry
30
- } from "./chunk-WJP4S2NP.js";
30
+ } from "./chunk-QJGDYXNC.js";
31
31
  import "./chunk-YWXQM6J3.js";
32
32
  import {
33
33
  BITFAB_PROGRESS_PREFIX,
@@ -36,7 +36,7 @@ import {
36
36
  ReplayError,
37
37
  reportReplayProgress,
38
38
  serializeReplayResult
39
- } from "./chunk-NPLI52PV.js";
39
+ } from "./chunk-G3KS5PSV.js";
40
40
  import {
41
41
  BitfabError,
42
42
  DEFAULT_SERVICE_URL,
@@ -44,7 +44,7 @@ import {
44
44
  MixedTracingError,
45
45
  __version__,
46
46
  flushTraces
47
- } from "./chunk-RZDYDKTP.js";
47
+ } from "./chunk-54JYZXMF.js";
48
48
  import "./chunk-MT36GJMW.js";
49
49
  export {
50
50
  AssertionCategoriesClient,
package/dist/node.cjs CHANGED
@@ -88,7 +88,7 @@ var __version__, __packageName__;
88
88
  var init_version_generated = __esm({
89
89
  "src/version.generated.ts"() {
90
90
  "use strict";
91
- __version__ = "0.64.6";
91
+ __version__ = "0.64.7";
92
92
  __packageName__ = "@bitfab/sdk";
93
93
  }
94
94
  });
@@ -2902,7 +2902,7 @@ var init_http = __esm({
2902
2902
  * Start a replay session by fetching historical traces.
2903
2903
  * Blocking call - creates an experiment and returns lightweight item references.
2904
2904
  */
2905
- async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetIds, graderIds, dbBranchSettings, attempts, includeOriginalMetadata, onlyWithAssertions, skipAssertionJudging, experimentalSelectiveReplay, notes, metadata, dryRun) {
2905
+ async startReplay(traceFunctionKey, limit, traceIds, name, codeChangeDescription, codeChangeFiles, includeDbBranchLease, experimentGroupId, datasetIds, graderIds, dbBranchSettings, attempts, includeOriginalMetadata, onlyWithAssertions, skipAssertionJudging, experimentalSelectiveReplay, notes, metadata, dryRun, invocation) {
2906
2906
  const payload = { traceFunctionKey };
2907
2907
  if (experimentalSelectiveReplay !== void 0) {
2908
2908
  payload.experimentalSelectiveReplay = experimentalSelectiveReplay;
@@ -2963,6 +2963,9 @@ var init_http = __esm({
2963
2963
  if (dryRun) {
2964
2964
  payload.dryRun = true;
2965
2965
  }
2966
+ if (invocation !== void 0) {
2967
+ payload.invocation = invocation;
2968
+ }
2966
2969
  const git = await resolvedGitState();
2967
2970
  if (git && !isEmptyGitState(git)) {
2968
2971
  payload.git = git;
@@ -3758,6 +3761,113 @@ var init_replayInterrupt = __esm({
3758
3761
  }
3759
3762
  });
3760
3763
 
3764
+ // src/replayInvocation.ts
3765
+ function replayEnvironment() {
3766
+ if (readEnv(REPLAY_EXECUTION_TARGET_ENV) === HOSTED_EXECUTION_TARGET) {
3767
+ return "cloud_replay";
3768
+ }
3769
+ if (CI_TRUE_VALUES.has((readEnv(CI_ENV) ?? "").toLowerCase())) {
3770
+ return "ci";
3771
+ }
3772
+ if (CI_PRESENCE_ENV_VARS.some((name) => (readEnv(name) ?? "") !== "")) {
3773
+ return "ci";
3774
+ }
3775
+ return "local";
3776
+ }
3777
+ function flagScalar(value) {
3778
+ if (typeof value === "string") {
3779
+ return value.slice(0, MAX_FLAG_STRING_LENGTH);
3780
+ }
3781
+ if (typeof value === "number") {
3782
+ return Number.isFinite(value) ? value : void 0;
3783
+ }
3784
+ if (typeof value === "boolean" || value === null) {
3785
+ return value;
3786
+ }
3787
+ return void 0;
3788
+ }
3789
+ function flagValue(value) {
3790
+ if (Array.isArray(value)) {
3791
+ const items = value.slice(0, MAX_FLAG_LIST_LENGTH).map(flagScalar);
3792
+ return items.every((item) => item !== void 0) ? items : true;
3793
+ }
3794
+ const scalar = flagScalar(value);
3795
+ return scalar === void 0 ? true : scalar;
3796
+ }
3797
+ function optionFlagName(option) {
3798
+ return OPTION_FLAG_NAMES[option] ?? option.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
3799
+ }
3800
+ function metadataKeys(value) {
3801
+ const keys = Array.isArray(value) ? value.map((pair) => String(pair).split("=")[0]) : typeof value === "object" && value !== null ? Object.keys(value) : void 0;
3802
+ return keys === void 0 ? true : [...new Set(keys)].sort();
3803
+ }
3804
+ function invocationFlags(entries) {
3805
+ const flags = {};
3806
+ const seen = /* @__PURE__ */ new Set();
3807
+ for (const [name, value] of entries) {
3808
+ if (seen.size >= MAX_FLAGS) {
3809
+ break;
3810
+ }
3811
+ if (value === void 0 || seen.has(name) || name.length === 0 || name.length > MAX_FLAG_NAME_LENGTH || SECRET_FLAG_NAME.test(name)) {
3812
+ continue;
3813
+ }
3814
+ flags[name] = flagValue(
3815
+ name === METADATA_FLAG ? metadataKeys(value) : value
3816
+ );
3817
+ seen.add(name);
3818
+ }
3819
+ return flags;
3820
+ }
3821
+ function buildReplayInvocation(entries = []) {
3822
+ return {
3823
+ flags: invocationFlags(entries),
3824
+ sdk: { language: "typescript", version: __version__ },
3825
+ environment: replayEnvironment()
3826
+ };
3827
+ }
3828
+ function safeReplayInvocation(build) {
3829
+ try {
3830
+ return build();
3831
+ } catch {
3832
+ return void 0;
3833
+ }
3834
+ }
3835
+ function cliFlags(options) {
3836
+ return options?.[CLI_FLAGS];
3837
+ }
3838
+ 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;
3839
+ var init_replayInvocation = __esm({
3840
+ "src/replayInvocation.ts"() {
3841
+ "use strict";
3842
+ init_constants();
3843
+ init_readEnv();
3844
+ REPLAY_EXECUTION_TARGET_ENV = "BITFAB_REPLAY_EXECUTION_TARGET";
3845
+ HOSTED_EXECUTION_TARGET = "hosted";
3846
+ CI_ENV = "CI";
3847
+ CI_TRUE_VALUES = /* @__PURE__ */ new Set(["true", "1"]);
3848
+ CI_PRESENCE_ENV_VARS = [
3849
+ "GITHUB_ACTIONS",
3850
+ "GITLAB_CI",
3851
+ "CIRCLECI",
3852
+ "BUILDKITE",
3853
+ "JENKINS_URL",
3854
+ "TF_BUILD"
3855
+ ];
3856
+ MAX_FLAGS = 100;
3857
+ MAX_FLAG_NAME_LENGTH = 100;
3858
+ MAX_FLAG_STRING_LENGTH = 1e3;
3859
+ MAX_FLAG_LIST_LENGTH = 100;
3860
+ SECRET_FLAG_NAME = /key|token|secret|password/i;
3861
+ CLI_FLAGS = /* @__PURE__ */ Symbol("bitfab.replayCliFlags");
3862
+ METADATA_FLAG = "metadata";
3863
+ OPTION_FLAG_NAMES = {
3864
+ maxConcurrency: "concurrency",
3865
+ datasetId: "dataset-ids",
3866
+ datasetIds: "dataset-ids"
3867
+ };
3868
+ }
3869
+ });
3870
+
3761
3871
  // src/selectiveReplay.ts
3762
3872
  function replayNodeKey(node) {
3763
3873
  return JSON.stringify([node.traceFunctionKey, node.spanName]);
@@ -4187,6 +4297,16 @@ function resolveDbBranchSettings(dbBranch) {
4187
4297
  };
4188
4298
  return Object.keys(settings).length === 0 ? void 0 : settings;
4189
4299
  }
4300
+ function explicitReplayOptions(options) {
4301
+ var _a;
4302
+ const explicit = {};
4303
+ for (const name of REPLAY_OPTION_NAMES) {
4304
+ if (options?.[name] !== void 0) {
4305
+ explicit[_a = optionFlagName(name)] ?? (explicit[_a] = options[name]);
4306
+ }
4307
+ }
4308
+ return explicit;
4309
+ }
4190
4310
  function reportReplayProgress(progress) {
4191
4311
  const stderr = typeof process !== "undefined" ? process.stderr : void 0;
4192
4312
  if (!stderr) {
@@ -4698,7 +4818,12 @@ async function replay(httpClient, serviceUrl, traceFunctionKey, fn, options, reg
4698
4818
  options?.experimentalSelectiveReplay,
4699
4819
  options?.notes,
4700
4820
  options?.metadata,
4701
- options?.dryRun === true
4821
+ options?.dryRun === true,
4822
+ safeReplayInvocation(
4823
+ () => buildReplayInvocation(
4824
+ Object.entries(cliFlags(options) ?? explicitReplayOptions(options))
4825
+ )
4826
+ )
4702
4827
  );
4703
4828
  if (started.items.length === 0) {
4704
4829
  try {
@@ -5090,7 +5215,7 @@ async function writeReplayResultFile(result) {
5090
5215
  }
5091
5216
  }
5092
5217
  }
5093
- var REPLAY_PERSISTENCE_TIMEOUT_MS, MAX_REPLAY_ATTEMPTS, RESUME_CONFLICTING_OPTIONS, CARRIED_OVER_ERROR, BITFAB_PROGRESS_PREFIX, ReplayError, DbBranchReplayError, JUDGE_ASSERTIONS_DEPRECATION_WARNING;
5218
+ 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;
5094
5219
  var init_replay = __esm({
5095
5220
  "src/replay.ts"() {
5096
5221
  "use strict";
@@ -5103,6 +5228,7 @@ var init_replay = __esm({
5103
5228
  init_replayContext();
5104
5229
  init_replayHeartbeat();
5105
5230
  init_replayInterrupt();
5231
+ init_replayInvocation();
5106
5232
  init_selectiveReplayRuntime();
5107
5233
  init_serialize();
5108
5234
  init_warnOnce();
@@ -5120,6 +5246,37 @@ var init_replay = __esm({
5120
5246
  "experimentalSelectiveReplay"
5121
5247
  ];
5122
5248
  CARRIED_OVER_ERROR = "This item errored in an earlier run of this experiment, before it was resumed.";
5249
+ REPLAY_OPTION_NAMES = [
5250
+ "experimentalSelectiveReplay",
5251
+ "limit",
5252
+ "attempts",
5253
+ "traceIds",
5254
+ "name",
5255
+ "notes",
5256
+ "metadata",
5257
+ "maxConcurrency",
5258
+ "codeChangeDescription",
5259
+ "codeChangeFiles",
5260
+ "mock",
5261
+ "mockOverride",
5262
+ "dbBranch",
5263
+ "experimentGroupId",
5264
+ "datasetId",
5265
+ "datasetIds",
5266
+ "graderIds",
5267
+ "onlyWithAssertions",
5268
+ "skipAssertionJudging",
5269
+ "judgeAssertions",
5270
+ "adaptInputs",
5271
+ "dryRun",
5272
+ "onItemFinish",
5273
+ "onProgress",
5274
+ "onItemStart",
5275
+ "onExperimentStart",
5276
+ "onInterrupt",
5277
+ "resume",
5278
+ "force"
5279
+ ];
5123
5280
  BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
5124
5281
  ReplayError = class extends BitfabError {
5125
5282
  constructor(message, items, experimentId, experimentUrl, cause) {
@@ -11977,6 +12134,7 @@ init_replay();
11977
12134
  init_errors();
11978
12135
  init_replay();
11979
12136
  init_replayInterrupt();
12137
+ init_replayInvocation();
11980
12138
  init_warnOnce();
11981
12139
  function defineReplayRegistry(registry) {
11982
12140
  validateReplayRegistry(registry);