bitfab 0.52.4 → 0.52.5

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 (33) hide show
  1. package/README.md +2 -0
  2. package/dist/{chunk-IG3CPSRQ.js → chunk-3D7FNJ5R.js} +2 -2
  3. package/dist/{chunk-IG3CPSRQ.js.map → chunk-3D7FNJ5R.js.map} +1 -1
  4. package/dist/{chunk-HKTODDFP.js → chunk-3QXNM62Y.js} +3 -3
  5. package/dist/chunk-3QXNM62Y.js.map +1 -0
  6. package/dist/{chunk-U2D7ACC4.js → chunk-6DRFQJ75.js} +110 -13
  7. package/dist/chunk-6DRFQJ75.js.map +1 -0
  8. package/dist/{chunk-34B7PVAM.js → chunk-CAE7HE4C.js} +3 -2
  9. package/dist/{chunk-34B7PVAM.js.map → chunk-CAE7HE4C.js.map} +1 -1
  10. package/dist/{chunk-AUROMI67.js → chunk-EMRHO6YW.js} +241 -21
  11. package/dist/chunk-EMRHO6YW.js.map +1 -0
  12. package/dist/{http-RFNQ7LSU.js → http-Q6UEKZRF.js} +2 -2
  13. package/dist/{http-F3AXLOJT.js → http-UQT6QVBC.js} +2 -2
  14. package/dist/index.cjs +380 -57
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +10 -2
  17. package/dist/index.d.ts +10 -2
  18. package/dist/index.js +3 -3
  19. package/dist/node.cjs +380 -57
  20. package/dist/node.cjs.map +1 -1
  21. package/dist/node.d.cts +1 -1
  22. package/dist/node.d.ts +1 -1
  23. package/dist/node.js +3 -3
  24. package/dist/{replay-ZOTYMBMD.js → replay-UVSZFZW7.js} +3 -3
  25. package/dist/replayCli.js +2 -2
  26. package/dist/seedCli.js +2 -2
  27. package/package.json +1 -1
  28. package/dist/chunk-AUROMI67.js.map +0 -1
  29. package/dist/chunk-HKTODDFP.js.map +0 -1
  30. package/dist/chunk-U2D7ACC4.js.map +0 -1
  31. /package/dist/{http-F3AXLOJT.js.map → http-Q6UEKZRF.js.map} +0 -0
  32. /package/dist/{http-RFNQ7LSU.js.map → http-UQT6QVBC.js.map} +0 -0
  33. /package/dist/{replay-ZOTYMBMD.js.map → replay-UVSZFZW7.js.map} +0 -0
@@ -10,12 +10,13 @@ import {
10
10
  NO_MOCK_OVERRIDE,
11
11
  deserializeInputs,
12
12
  deserializeValue,
13
+ gitRunner,
13
14
  randomUuid,
14
15
  resolveMockValue,
15
16
  serializeValue,
16
17
  toJsonSafe,
17
18
  toJsonSafeReport
18
- } from "./chunk-U2D7ACC4.js";
19
+ } from "./chunk-6DRFQJ75.js";
19
20
  import {
20
21
  BitfabError,
21
22
  DEFAULT_SERVICE_URL,
@@ -23,10 +24,11 @@ import {
23
24
  MixedTracingError,
24
25
  callerTraceMetadata,
25
26
  getReplayContext,
27
+ readEnv,
26
28
  recordCallerTraceMetadata,
27
29
  retireTraceMetadata,
28
30
  warnOnce
29
- } from "./chunk-34B7PVAM.js";
31
+ } from "./chunk-CAE7HE4C.js";
30
32
  import {
31
33
  __privateAdd,
32
34
  __privateGet,
@@ -1017,24 +1019,237 @@ function mixedTracingError(enteredApi, entered, enclosing, traceFunctionKey) {
1017
1019
  `opt-in and opt-out tracing can't be mixed in one call stack: ${enteredApi} (${entered})${subject} was entered inside a ${SURFACE_API[enclosing]} call (${enclosing}). ${MIXED_SURFACE_REMEDY[entered]}`
1018
1020
  );
1019
1021
  }
1020
- function assertSurfacesCompatible(requested, resolved, parentSurface, traceFunctionKey) {
1022
+ function assertSurfacesCompatible(requested, resolved2, parentSurface, traceFunctionKey) {
1021
1023
  if (requested === "inherit" || requested === "neutral") {
1022
1024
  return;
1023
1025
  }
1024
- if (resolved === void 0 || parentSurface === void 0) {
1026
+ if (resolved2 === void 0 || parentSurface === void 0) {
1025
1027
  return;
1026
1028
  }
1027
- if (parentSurface === resolved) {
1029
+ if (parentSurface === resolved2) {
1028
1030
  return;
1029
1031
  }
1030
1032
  throw mixedTracingError(
1031
- SURFACE_API[resolved],
1032
- resolved,
1033
+ SURFACE_API[resolved2],
1034
+ resolved2,
1033
1035
  parentSurface,
1034
1036
  traceFunctionKey
1035
1037
  );
1036
1038
  }
1037
1039
 
1040
+ // src/commitRef.ts
1041
+ var EXPLICIT_SHA_ENV = "BITFAB_COMMIT_SHA";
1042
+ var DISABLE_ENV = "BITFAB_DISABLE_COMMIT_REF";
1043
+ var GIT_TIMEOUT_MS = 2e3;
1044
+ var GIT_MAX_BUFFER = 1024 * 1024;
1045
+ var VERCEL_PROVIDER_HOSTS = {
1046
+ github: "github.com",
1047
+ gitlab: "gitlab.com",
1048
+ bitbucket: "bitbucket.org"
1049
+ };
1050
+ function read(env, name) {
1051
+ if (name === null) {
1052
+ return null;
1053
+ }
1054
+ const value = env(name)?.trim();
1055
+ return value ? value : null;
1056
+ }
1057
+ function remoteFrom(...names) {
1058
+ return (env) => {
1059
+ const parts = names.map((name) => read(env, name));
1060
+ if (parts.some((part) => part === null)) {
1061
+ return null;
1062
+ }
1063
+ return normalizeRemote(parts.join("/"));
1064
+ };
1065
+ }
1066
+ function vercelRemote(env) {
1067
+ const provider = read(env, "VERCEL_GIT_PROVIDER")?.toLowerCase() ?? "";
1068
+ const host = VERCEL_PROVIDER_HOSTS[provider];
1069
+ const owner = read(env, "VERCEL_GIT_REPO_OWNER");
1070
+ const slug = read(env, "VERCEL_GIT_REPO_SLUG");
1071
+ if (!host || !owner || !slug) {
1072
+ return null;
1073
+ }
1074
+ return `${host}/${owner}/${slug}`;
1075
+ }
1076
+ function noRemote() {
1077
+ return null;
1078
+ }
1079
+ var PLATFORM_ENVS = [
1080
+ ["VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF", vercelRemote],
1081
+ [
1082
+ "GITHUB_SHA",
1083
+ "GITHUB_REF_NAME",
1084
+ remoteFrom("GITHUB_SERVER_URL", "GITHUB_REPOSITORY")
1085
+ ],
1086
+ ["RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH", noRemote],
1087
+ ["RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH", noRemote],
1088
+ ["SOURCE_VERSION", null, noRemote],
1089
+ ["CF_PAGES_COMMIT_SHA", "CF_PAGES_BRANCH", noRemote],
1090
+ ["CI_COMMIT_SHA", "CI_COMMIT_REF_NAME", remoteFrom("CI_REPOSITORY_URL")],
1091
+ [
1092
+ "BUILD_SOURCEVERSION",
1093
+ "BUILD_SOURCEBRANCHNAME",
1094
+ remoteFrom("BUILD_REPOSITORY_URI")
1095
+ ],
1096
+ ["CIRCLE_SHA1", "CIRCLE_BRANCH", remoteFrom("CIRCLE_REPOSITORY_URL")]
1097
+ ];
1098
+ var COMMIT_REF_ENV_NAMES = [
1099
+ EXPLICIT_SHA_ENV,
1100
+ DISABLE_ENV,
1101
+ ...PLATFORM_ENVS.flatMap(
1102
+ ([sha, branch]) => branch === null ? [sha] : [sha, branch]
1103
+ ),
1104
+ "GITHUB_SERVER_URL",
1105
+ "GITHUB_REPOSITORY",
1106
+ "CI_REPOSITORY_URL",
1107
+ "BUILD_REPOSITORY_URI",
1108
+ "CIRCLE_REPOSITORY_URL",
1109
+ "VERCEL_GIT_PROVIDER",
1110
+ "VERCEL_GIT_REPO_OWNER",
1111
+ "VERCEL_GIT_REPO_SLUG"
1112
+ ];
1113
+ function normalizeRemote(raw) {
1114
+ const value = raw?.trim();
1115
+ if (!value) {
1116
+ return null;
1117
+ }
1118
+ let host = "";
1119
+ let path = value;
1120
+ if (value.includes("://")) {
1121
+ try {
1122
+ const parsed = new URL(value);
1123
+ host = parsed.hostname;
1124
+ path = parsed.pathname;
1125
+ } catch {
1126
+ return null;
1127
+ }
1128
+ } else {
1129
+ const separator = value.indexOf(":");
1130
+ if (separator !== -1) {
1131
+ const head = value.slice(0, separator);
1132
+ host = head.slice(head.lastIndexOf("@") + 1);
1133
+ path = value.slice(separator + 1);
1134
+ }
1135
+ }
1136
+ path = path.replace(/^\/+|\/+$/g, "");
1137
+ if (path.endsWith(".git")) {
1138
+ path = path.slice(0, -".git".length).replace(/\/+$/, "");
1139
+ }
1140
+ if (!host) {
1141
+ return path || null;
1142
+ }
1143
+ return path ? `${host}/${path}` : host;
1144
+ }
1145
+ function resolveCommitRefFromEnv(env) {
1146
+ const explicit = read(env, EXPLICIT_SHA_ENV);
1147
+ const platform = PLATFORM_ENVS.find(([sha]) => read(env, sha) !== null);
1148
+ if (!platform) {
1149
+ if (explicit === null) {
1150
+ return null;
1151
+ }
1152
+ return {
1153
+ sha: explicit,
1154
+ branch: null,
1155
+ dirty: null,
1156
+ remote: null,
1157
+ rootSha: null
1158
+ };
1159
+ }
1160
+ const [shaEnv, branchEnv, readRemote] = platform;
1161
+ return {
1162
+ sha: explicit ?? read(env, shaEnv),
1163
+ branch: read(env, branchEnv),
1164
+ dirty: null,
1165
+ remote: readRemote(env),
1166
+ rootSha: null
1167
+ };
1168
+ }
1169
+ async function resolveCommitRefFromGit(cwd) {
1170
+ const git = await gitRunner({
1171
+ timeoutMs: GIT_TIMEOUT_MS,
1172
+ maxBuffer: GIT_MAX_BUFFER,
1173
+ keepProcessAlive: false
1174
+ });
1175
+ if (!git) {
1176
+ return null;
1177
+ }
1178
+ const run = async (args) => (await git(cwd, args))?.trim() ?? null;
1179
+ const sha = await run(["rev-parse", "HEAD"]);
1180
+ if (!sha) {
1181
+ return null;
1182
+ }
1183
+ const [branch, status, remote, roots] = await Promise.all([
1184
+ run(["symbolic-ref", "--short", "-q", "HEAD"]),
1185
+ run(["status", "--porcelain"]),
1186
+ run(["remote", "get-url", "origin"]),
1187
+ run(["rev-list", "--max-parents=0", "HEAD"])
1188
+ ]);
1189
+ return {
1190
+ sha,
1191
+ branch: branch || null,
1192
+ dirty: status === null ? null : status.length > 0,
1193
+ remote: normalizeRemote(remote),
1194
+ rootSha: roots ? roots.split(/\s+/).sort()[0] ?? null : null
1195
+ };
1196
+ }
1197
+ function commitRefWire(ref2) {
1198
+ return {
1199
+ sha: ref2.sha,
1200
+ branch: ref2.branch,
1201
+ dirty: ref2.dirty,
1202
+ remote: ref2.remote,
1203
+ root_sha: ref2.rootSha
1204
+ };
1205
+ }
1206
+ var resolved = false;
1207
+ var ref = null;
1208
+ var gitStarted = false;
1209
+ var settled = Promise.resolve();
1210
+ function startCommitRefResolution() {
1211
+ if (resolved || gitStarted) {
1212
+ return;
1213
+ }
1214
+ if (read(readEnv, DISABLE_ENV) !== null) {
1215
+ resolved = true;
1216
+ return;
1217
+ }
1218
+ const fromEnv = resolveCommitRefFromEnv(readEnv);
1219
+ if (fromEnv) {
1220
+ ref = fromEnv;
1221
+ resolved = true;
1222
+ return;
1223
+ }
1224
+ gitStarted = true;
1225
+ if (typeof process === "undefined") {
1226
+ resolved = true;
1227
+ return;
1228
+ }
1229
+ let cwd;
1230
+ try {
1231
+ cwd = process.cwd?.() ?? ".";
1232
+ } catch {
1233
+ resolved = true;
1234
+ return;
1235
+ }
1236
+ settled = resolveCommitRefFromGit(cwd).then(
1237
+ (fromGit) => {
1238
+ if (!resolved) {
1239
+ ref = fromGit;
1240
+ resolved = true;
1241
+ }
1242
+ },
1243
+ () => {
1244
+ resolved = true;
1245
+ }
1246
+ );
1247
+ }
1248
+ function currentCommitRef() {
1249
+ startCommitRefResolution();
1250
+ return ref;
1251
+ }
1252
+
1038
1253
  // src/datasets.ts
1039
1254
  var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
1040
1255
  var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
@@ -1512,11 +1727,11 @@ var BitfabLangGraphCallbackHandler = class {
1512
1727
  this.invocations.set(invocation.rootRunId, invocation);
1513
1728
  }
1514
1729
  if (!willHide) {
1515
- let resolved = parentSpan;
1516
- while (resolved?.hidden === true) {
1517
- resolved = resolved.parentId ? this.runToSpan.get(resolved.parentId) : void 0;
1730
+ let resolved2 = parentSpan;
1731
+ while (resolved2?.hidden === true) {
1732
+ resolved2 = resolved2.parentId ? this.runToSpan.get(resolved2.parentId) : void 0;
1518
1733
  }
1519
- effectiveParentId = resolved ? resolved.spanId : invocation.activeContext?.spanId ?? null;
1734
+ effectiveParentId = resolved2 ? resolved2.spanId : invocation.activeContext?.spanId ?? null;
1520
1735
  } else {
1521
1736
  effectiveParentId = parentRunId ?? null;
1522
1737
  }
@@ -2948,7 +3163,7 @@ function getCurrentTrace() {
2948
3163
  }
2949
3164
  };
2950
3165
  }
2951
- function readEnv(name) {
3166
+ function readEnv2(name) {
2952
3167
  if (typeof process !== "undefined" && process.env) {
2953
3168
  return process.env[name];
2954
3169
  }
@@ -2995,6 +3210,7 @@ var Bitfab = class {
2995
3210
  validateDbSnapshotConfig(config.dbSnapshot);
2996
3211
  }
2997
3212
  this.dbSnapshot = config.dbSnapshot;
3213
+ startCommitRefResolution();
2998
3214
  this.httpClient = new HttpClient({
2999
3215
  apiKey: () => this.resolveApiKey(),
3000
3216
  serviceUrl: this.serviceUrl,
@@ -3330,7 +3546,7 @@ var Bitfab = class {
3330
3546
  return this.resolvedApiKey;
3331
3547
  }
3332
3548
  const fromConfig = typeof this.apiKeyConfig === "function" ? this.apiKeyConfig() : this.apiKeyConfig;
3333
- const candidate = fromConfig && fromConfig.trim() !== "" ? fromConfig : readEnv("BITFAB_API_KEY");
3549
+ const candidate = fromConfig && fromConfig.trim() !== "" ? fromConfig : readEnv2("BITFAB_API_KEY");
3334
3550
  const key = candidate && candidate.trim() !== "" ? candidate : void 0;
3335
3551
  if (key) {
3336
3552
  this.resolvedApiKey = key;
@@ -4088,15 +4304,15 @@ var Bitfab = class {
4088
4304
  );
4089
4305
  }
4090
4306
  return runWithSpanStack(newStack, async () => {
4091
- const resolved = await resolution;
4092
- if (resolved.matched) {
4307
+ const resolved2 = await resolution;
4308
+ if (resolved2.matched) {
4093
4309
  void sendSpan({
4094
- result: resolved.output,
4310
+ result: resolved2.output,
4095
4311
  mocked: true,
4096
4312
  mockTarget: "output",
4097
4313
  mockSource: "override"
4098
4314
  });
4099
- return resolved.output;
4315
+ return resolved2.output;
4100
4316
  }
4101
4317
  if (shouldMockWithBaseStrategy && !mockSpan) {
4102
4318
  throw new BitfabError(
@@ -4332,6 +4548,10 @@ var Bitfab = class {
4332
4548
  if (params.dbSnapshotRef) {
4333
4549
  rawTrace.db_snapshot_ref = params.dbSnapshotRef;
4334
4550
  }
4551
+ const commitRef = currentCommitRef();
4552
+ if (commitRef) {
4553
+ rawTrace.commit_ref = commitRefWire(commitRef);
4554
+ }
4335
4555
  if (params.ingestionType) {
4336
4556
  rawTrace.ingestion_type = params.ingestionType;
4337
4557
  }
@@ -4577,7 +4797,7 @@ var Bitfab = class {
4577
4797
  await runWithSeedContext({ traceId }, async () => target(...args));
4578
4798
  } finally {
4579
4799
  try {
4580
- const { flushTraces: flushTraces2 } = await import("./http-RFNQ7LSU.js");
4800
+ const { flushTraces: flushTraces2 } = await import("./http-Q6UEKZRF.js");
4581
4801
  await flushTraces2(3e4);
4582
4802
  } finally {
4583
4803
  unrecorded = activeTraceStates.delete(traceId);
@@ -4636,7 +4856,7 @@ var Bitfab = class {
4636
4856
  `Function is wrapped with trace function key '${wrappedKey}' but replay was called with '${traceFunctionKey}'. Pass matching keys, or pass the unwrapped function to replay it under the explicit key.`
4637
4857
  );
4638
4858
  }
4639
- const { replay: doReplay } = await import("./replay-ZOTYMBMD.js");
4859
+ const { replay: doReplay } = await import("./replay-UVSZFZW7.js");
4640
4860
  return doReplay(
4641
4861
  this.httpClient,
4642
4862
  this.serviceUrl,
@@ -4920,7 +5140,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
4920
5140
  sessionId: seedCase.sessionId
4921
5141
  })
4922
5142
  );
4923
- const { flushTraces: flushTraces2 } = await import("./http-RFNQ7LSU.js");
5143
+ const { flushTraces: flushTraces2 } = await import("./http-Q6UEKZRF.js");
4924
5144
  await flushTraces2(3e4);
4925
5145
  return { pipeline, traceFunctionKey, traceIds };
4926
5146
  }
@@ -4957,4 +5177,4 @@ export {
4957
5177
  reseedFromRegistry,
4958
5178
  seedFromRegistry
4959
5179
  };
4960
- //# sourceMappingURL=chunk-AUROMI67.js.map
5180
+ //# sourceMappingURL=chunk-EMRHO6YW.js.map