@bitfab/sdk 0.64.16 → 0.64.18

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 (36) hide show
  1. package/cloudReplay.py +286 -24
  2. package/dist/{chunk-PAWBCEI7.js → chunk-4JZ6UMDW.js} +2 -2
  3. package/dist/{chunk-PAWBCEI7.js.map → chunk-4JZ6UMDW.js.map} +1 -1
  4. package/dist/{chunk-LOIVELPI.js → chunk-6AUI3X66.js} +204 -89
  5. package/dist/chunk-6AUI3X66.js.map +1 -0
  6. package/dist/{chunk-I4TFQZCW.js → chunk-7NPHFRQD.js} +16 -2
  7. package/dist/{chunk-I4TFQZCW.js.map → chunk-7NPHFRQD.js.map} +1 -1
  8. package/dist/{chunk-NNZAQSTW.js → chunk-ACKEEC7I.js} +2 -2
  9. package/dist/chunk-NGKTKRCV.js +1905 -0
  10. package/dist/chunk-NGKTKRCV.js.map +1 -0
  11. package/dist/{chunk-AXFKZYIY.js → chunk-ZBA4QJWF.js} +11 -6
  12. package/dist/chunk-ZBA4QJWF.js.map +1 -0
  13. package/dist/{http-QQ6VVHUZ.js → http-2BXJLZ5N.js} +2 -2
  14. package/dist/{http-LV7OUBKA.js → http-6VZBSALH.js} +2 -2
  15. package/dist/index.cjs +6 -1
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +3 -3
  20. package/dist/node.cjs +6 -1
  21. package/dist/node.cjs.map +1 -1
  22. package/dist/node.js +3 -3
  23. package/dist/{replay-JNKXZPY7.js → replay-OO2DFUAQ.js} +3 -3
  24. package/dist/replay-Z46UJQVQ.js +28 -0
  25. package/dist/replay-Z46UJQVQ.js.map +1 -0
  26. package/dist/replayCli.js +3 -2
  27. package/dist/replayCli.js.map +1 -1
  28. package/dist/seedCli.js +3 -2
  29. package/dist/seedCli.js.map +1 -1
  30. package/package.json +1 -1
  31. package/dist/chunk-AXFKZYIY.js.map +0 -1
  32. package/dist/chunk-LOIVELPI.js.map +0 -1
  33. /package/dist/{chunk-NNZAQSTW.js.map → chunk-ACKEEC7I.js.map} +0 -0
  34. /package/dist/{http-LV7OUBKA.js.map → http-2BXJLZ5N.js.map} +0 -0
  35. /package/dist/{http-QQ6VVHUZ.js.map → http-6VZBSALH.js.map} +0 -0
  36. /package/dist/{replay-JNKXZPY7.js.map → replay-OO2DFUAQ.js.map} +0 -0
@@ -1,104 +1,208 @@
1
+ import {
2
+ ReplayError,
3
+ canonicalCliFlag,
4
+ describeReplayInterrupt,
5
+ reportReplayProgress,
6
+ serializeReplayResult,
7
+ warnJudgeAssertionsDeprecated,
8
+ withCliFlags
9
+ } from "./chunk-NGKTKRCV.js";
1
10
  import {
2
11
  BitfabError,
3
- warnOnce,
4
- writeOnce
5
- } from "./chunk-I4TFQZCW.js";
6
-
7
- // src/codeChange.ts
8
- var NUL = String.fromCharCode(0);
12
+ asyncStorageReady,
13
+ createAsyncLocalStorage,
14
+ warnOnce
15
+ } from "./chunk-7NPHFRQD.js";
9
16
 
10
- // src/serialize.ts
11
- import superjson from "superjson";
17
+ // src/autoTrace.ts
18
+ var autoTraceGlobal = globalThis;
19
+ var autoTraceState = autoTraceGlobal.__bitfabAutoTraceStateV4 ?? {
20
+ storage: null,
21
+ browserScope: void 0,
22
+ capturePolicies: /* @__PURE__ */ new WeakMap(),
23
+ activeRoots: 0
24
+ };
25
+ autoTraceGlobal.__bitfabAutoTraceStateV4 = autoTraceState;
12
26
 
13
- // src/replayInterrupt.ts
14
- function describeReplayInterrupt(experimentId, markedInterrupted) {
15
- if (markedInterrupted) {
16
- return `[replay] Experiment ${experimentId} interrupted.`;
27
+ // src/commitRef.ts
28
+ var EXPLICIT_SHA_ENV = "BITFAB_COMMIT_SHA";
29
+ var DISABLE_ENV = "BITFAB_DISABLE_COMMIT_REF";
30
+ var GIT_MAX_BUFFER = 1024 * 1024;
31
+ var VERCEL_PROVIDER_HOSTS = {
32
+ github: "github.com",
33
+ gitlab: "gitlab.com",
34
+ bitbucket: "bitbucket.org"
35
+ };
36
+ function read(env, name) {
37
+ if (name === null) {
38
+ return null;
17
39
  }
18
- return `[replay] Experiment ${experimentId} stopped, but Bitfab could not mark it interrupted. It will be marked interrupted within 15 minutes. A resume in the next two minutes may be refused as still running.`;
40
+ const value = env(name)?.trim();
41
+ return value ? value : null;
19
42
  }
20
-
21
- // src/replayInvocation.ts
22
- var CLI_FLAGS = /* @__PURE__ */ Symbol("bitfab.replayCliFlags");
23
- var CLI_FLAG_ALIASES = {
24
- "max-concurrency": "concurrency",
25
- "dataset-id": "dataset-ids"
26
- };
27
- function canonicalCliFlag(name) {
28
- return CLI_FLAG_ALIASES[name] ?? name;
43
+ function remoteFrom(...names) {
44
+ return (env) => {
45
+ const parts = names.map((name) => read(env, name));
46
+ if (parts.some((part) => part === null)) {
47
+ return null;
48
+ }
49
+ return normalizeRemote(parts.join("/"));
50
+ };
29
51
  }
30
- function withCliFlags(options, flags) {
31
- Object.defineProperty(options, CLI_FLAGS, {
32
- value: flags,
33
- enumerable: false
34
- });
35
- return options;
52
+ function vercelRemote(env) {
53
+ const provider = read(env, "VERCEL_GIT_PROVIDER")?.toLowerCase() ?? "";
54
+ const host = VERCEL_PROVIDER_HOSTS[provider];
55
+ const owner = read(env, "VERCEL_GIT_REPO_OWNER");
56
+ const slug = read(env, "VERCEL_GIT_REPO_SLUG");
57
+ if (!host || !owner || !slug) {
58
+ return null;
59
+ }
60
+ return `${host}/${owner}/${slug}`;
61
+ }
62
+ function noRemote() {
63
+ return null;
64
+ }
65
+ var PLATFORM_ENVS = [
66
+ ["VERCEL_GIT_COMMIT_SHA", "VERCEL_GIT_COMMIT_REF", vercelRemote],
67
+ [
68
+ "GITHUB_SHA",
69
+ "GITHUB_REF_NAME",
70
+ remoteFrom("GITHUB_SERVER_URL", "GITHUB_REPOSITORY")
71
+ ],
72
+ ["RAILWAY_GIT_COMMIT_SHA", "RAILWAY_GIT_BRANCH", noRemote],
73
+ ["RENDER_GIT_COMMIT", "RENDER_GIT_BRANCH", noRemote],
74
+ ["SOURCE_VERSION", null, noRemote],
75
+ ["CF_PAGES_COMMIT_SHA", "CF_PAGES_BRANCH", noRemote],
76
+ ["CI_COMMIT_SHA", "CI_COMMIT_REF_NAME", remoteFrom("CI_REPOSITORY_URL")],
77
+ [
78
+ "BUILD_SOURCEVERSION",
79
+ "BUILD_SOURCEBRANCHNAME",
80
+ remoteFrom("BUILD_REPOSITORY_URI")
81
+ ],
82
+ ["CIRCLE_SHA1", "CIRCLE_BRANCH", remoteFrom("CIRCLE_REPOSITORY_URL")]
83
+ ];
84
+ var COMMIT_REF_ENV_NAMES = [
85
+ EXPLICIT_SHA_ENV,
86
+ DISABLE_ENV,
87
+ ...PLATFORM_ENVS.flatMap(
88
+ ([sha, branch]) => branch === null ? [sha] : [sha, branch]
89
+ ),
90
+ "GITHUB_SERVER_URL",
91
+ "GITHUB_REPOSITORY",
92
+ "CI_REPOSITORY_URL",
93
+ "BUILD_REPOSITORY_URI",
94
+ "CIRCLE_REPOSITORY_URL",
95
+ "VERCEL_GIT_PROVIDER",
96
+ "VERCEL_GIT_REPO_OWNER",
97
+ "VERCEL_GIT_REPO_SLUG"
98
+ ];
99
+ function normalizeRemote(raw) {
100
+ const value = raw?.trim();
101
+ if (!value) {
102
+ return null;
103
+ }
104
+ let host = "";
105
+ let path = value;
106
+ if (value.includes("://")) {
107
+ try {
108
+ const parsed = new URL(value);
109
+ host = parsed.hostname;
110
+ path = parsed.pathname;
111
+ } catch {
112
+ return null;
113
+ }
114
+ } else {
115
+ const separator = value.indexOf(":");
116
+ if (separator !== -1) {
117
+ const head = value.slice(0, separator);
118
+ host = head.slice(head.lastIndexOf("@") + 1);
119
+ path = value.slice(separator + 1);
120
+ }
121
+ }
122
+ path = path.replace(/^\/+|\/+$/g, "");
123
+ if (path.endsWith(".git")) {
124
+ path = path.slice(0, -".git".length).replace(/\/+$/, "");
125
+ }
126
+ if (!host) {
127
+ return path || null;
128
+ }
129
+ return path ? `${host}/${path}` : host;
36
130
  }
131
+ var settled = Promise.resolve();
37
132
 
38
- // src/replay.ts
39
- var BITFAB_PROGRESS_PREFIX = "@@bitfab:progress ";
40
- function reportReplayProgress(progress) {
41
- const stderr = typeof process !== "undefined" ? process.stderr : void 0;
42
- if (!stderr) {
133
+ // src/openaiAgentsSpanContext.ts
134
+ var spanGlobal = globalThis;
135
+ var state = spanGlobal.__bitfabOpenAiAgentsSpansV1 ?? {
136
+ bitfabTraceIds: /* @__PURE__ */ new Map(),
137
+ endedSpanIds: /* @__PURE__ */ new Map()
138
+ };
139
+ spanGlobal.__bitfabOpenAiAgentsSpansV1 = state;
140
+
141
+ // src/rivetContext.ts
142
+ var storage = null;
143
+ var STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.rivetContextStorage");
144
+ function initializeStorage() {
145
+ if (storage) {
43
146
  return;
44
147
  }
45
- try {
46
- stderr.write(
47
- `${BITFAB_PROGRESS_PREFIX}${JSON.stringify(progress, replayJsonReplacer)}
48
- `
49
- );
50
- } catch {
148
+ const shared = globalThis;
149
+ const existing = shared[STORAGE_SYMBOL];
150
+ if (existing) {
151
+ storage = existing;
152
+ return;
153
+ }
154
+ const created = createAsyncLocalStorage();
155
+ if (created) {
156
+ shared[STORAGE_SYMBOL] = created;
157
+ storage = created;
51
158
  }
52
159
  }
53
- var ReplayError = class extends BitfabError {
54
- constructor(message, items, experimentId, experimentUrl, cause) {
55
- super(message, experimentUrl);
56
- this.items = items;
57
- this.experimentId = experimentId;
58
- this.experimentUrl = experimentUrl;
59
- this.cause = cause;
60
- this.name = "ReplayError";
61
- this.testRunId = experimentId;
62
- this.testRunUrl = experimentUrl;
160
+ var rivetContextReady = asyncStorageReady.then(() => {
161
+ initializeStorage();
162
+ });
163
+
164
+ // src/seedContext.ts
165
+ var seedContextStorage = null;
166
+ var SEED_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.seedContextStorage");
167
+ var seedContextReady = asyncStorageReady.then(() => {
168
+ const shared = globalThis;
169
+ const existing = shared[SEED_CONTEXT_STORAGE_SYMBOL];
170
+ if (existing) {
171
+ seedContextStorage = existing;
172
+ return;
63
173
  }
64
- };
65
- var DbBranchReplayError = class extends BitfabError {
66
- constructor(code, message, originalTraceId, cause) {
67
- super(message);
68
- this.code = code;
69
- this.originalTraceId = originalTraceId;
70
- this.cause = cause;
71
- this.name = "DbBranchReplayError";
174
+ const created = createAsyncLocalStorage();
175
+ if (created) {
176
+ shared[SEED_CONTEXT_STORAGE_SYMBOL] = created;
177
+ seedContextStorage = created;
72
178
  }
73
- };
74
- function replayJsonReplacer(_key, value) {
75
- if (value instanceof Error) {
76
- const serialized = {
77
- name: value.name,
78
- message: value.message,
79
- stack: value.stack
80
- };
81
- if (value instanceof DbBranchReplayError) {
82
- serialized.code = value.code;
83
- serialized.originalTraceId = value.originalTraceId;
84
- if (value.cause !== void 0) {
85
- serialized.cause = value.cause;
86
- }
87
- }
88
- return serialized;
179
+ });
180
+
181
+ // src/client.ts
182
+ var asyncLocalStorage = null;
183
+ var SPAN_CONTEXT_STORAGE_SYMBOL = /* @__PURE__ */ Symbol.for("bitfab.spanContextStorage");
184
+ var initializeAsyncContext = () => {
185
+ if (asyncLocalStorage) {
186
+ return;
89
187
  }
90
- return value;
91
- }
92
- function serializeReplayResult(result) {
93
- return JSON.stringify(result, replayJsonReplacer, 2);
94
- }
95
- var JUDGE_ASSERTIONS_DEPRECATION_WARNING = "Bitfab: judgeAssertions is deprecated. Assertion judging is on by default; pass skipAssertionJudging: true (--skip-assertion-judging) to turn it off.";
96
- function warnJudgeAssertionsDeprecated(write = console.warn) {
97
- writeOnce(
98
- "judgeAssertions-deprecated",
99
- JUDGE_ASSERTIONS_DEPRECATION_WARNING,
100
- write
101
- );
188
+ const shared = globalThis;
189
+ const existing = shared[SPAN_CONTEXT_STORAGE_SYMBOL];
190
+ if (existing) {
191
+ asyncLocalStorage = existing;
192
+ return;
193
+ }
194
+ const created = createAsyncLocalStorage();
195
+ if (created) {
196
+ shared[SPAN_CONTEXT_STORAGE_SYMBOL] = created;
197
+ asyncLocalStorage = created;
198
+ }
199
+ };
200
+ var asyncLocalStorageReady = asyncStorageReady.then(() => {
201
+ initializeAsyncContext();
202
+ });
203
+ function _resolvedApiKey(client) {
204
+ const keyed = client;
205
+ return keyed.findApiKey(true) ?? null;
102
206
  }
103
207
 
104
208
  // src/replayRegistry.ts
@@ -349,8 +453,8 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
349
453
  sessionId: seedCase.sessionId
350
454
  })
351
455
  );
352
- const { flushTraces: flushTraces2 } = await import("./http-QQ6VVHUZ.js");
353
- await flushTraces2(3e4);
456
+ const { flushTraces } = await import("./http-2BXJLZ5N.js");
457
+ await flushTraces(3e4);
354
458
  return { pipeline, traceFunctionKey, traceIds };
355
459
  }
356
460
  var SEED_USAGE = `Usage: bitfab-seed --registry <path> <pipeline> --from-trace <id>[,<id>...]
@@ -785,10 +889,21 @@ function reportReplayError(error, stderr) {
785
889
  );
786
890
  }
787
891
  }
892
+ var API_KEY_LINE_PREFIX = "@@bitfab:api-key ";
893
+ var PRINT_API_KEY_FLAG = "--print-api-key";
788
894
  async function runReplayCli(registry, argv = typeof process === "undefined" ? [] : process.argv.slice(2), io = {}, registryPath) {
789
895
  const stdout = io.stdout ?? console.log;
790
896
  const stderr = io.stderr ?? console.error;
791
- const args = parseReplayCliArgs(registry, argv);
897
+ const printApiKey = argv.includes(PRINT_API_KEY_FLAG);
898
+ const args = parseReplayCliArgs(
899
+ registry,
900
+ argv.filter((arg) => arg !== PRINT_API_KEY_FLAG)
901
+ );
902
+ if (printApiKey) {
903
+ const apiKey = _resolvedApiKey(registry[args.pipeline].client);
904
+ stdout(`${API_KEY_LINE_PREFIX}${JSON.stringify({ apiKey })}`);
905
+ return null;
906
+ }
792
907
  if (args.judgeAssertionsFlag) {
793
908
  warnJudgeAssertionsDeprecated(stderr);
794
909
  }
@@ -1047,4 +1162,4 @@ export {
1047
1162
  runRegistryMain,
1048
1163
  runIfEntrypoint
1049
1164
  };
1050
- //# sourceMappingURL=chunk-LOIVELPI.js.map
1165
+ //# sourceMappingURL=chunk-6AUI3X66.js.map