@bitfab/sdk 0.65.7 → 0.65.9

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.
@@ -1,6 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
- import { C as readEnv$1, S as MixedTracingError, _ as getReplayContext, b as gitRunner, c as recordCallerTraceMetadata, f as ROOT_TRACE_FUNCTION_KEY_FIELD, g as MAX_COMPRESSIBLE_SPAN_CARRIER_BYTES, h as makeSpanOrigin, i as flushTraces, l as retireTraceMetadata, m as isFrameworkInstrumentation, n as SPAN_TYPES, o as unrefTimer, p as SimulationPlan, r as experimentIdWireFields, s as callerTraceMetadata, t as HttpClient, v as replayContextReady, w as __version__, x as BitfabError, y as runWithReplayContext } from "./http-BaLzqv9W.js";
2
+ import { C as readEnv$1, S as MixedTracingError, _ as getReplayContext, b as gitRunner, c as recordCallerTraceMetadata, f as ROOT_TRACE_FUNCTION_KEY_FIELD, g as MAX_COMPRESSIBLE_SPAN_CARRIER_BYTES, h as makeSpanOrigin, i as flushTraces, l as retireTraceMetadata, m as isFrameworkInstrumentation, n as SPAN_TYPES, o as unrefTimer, p as SimulationPlan, r as experimentIdWireFields, s as callerTraceMetadata, t as HttpClient, v as replayContextReady, w as __version__, x as BitfabError, y as runWithReplayContext } from "./http-DUDL3FGE.js";
3
3
  import { a as clearAutoTraceNodeConfiguration, b as isAsyncStorageInitDone, c as runAsAutoTraceRootFunction, d as runWithAutoTraceRootContext, g as runWithCaptureSuppressed, h as isCaptureSuppressed, l as runWithAutoTraceEntry, m as writeOnce, n as __bitfabAutoTraceActive, o as currentAutoTraceEntries, p as warnOnce, s as invokeThroughAutoTraceEntries, u as runWithAutoTraceNodeConfiguration, v as asyncStorageReady, y as createAsyncLocalStorage } from "./autoTrace-O40k8f5M.js";
4
+ import { r as importOptionalPeer, t as loadBamlModule } from "./bamlPeer-CIVwS68E.js";
4
5
  import superjson from "superjson";
5
6
  //#region src/categories.ts
6
7
  const CATEGORIES_PATH = "/api/sdk/categories";
@@ -617,25 +618,11 @@ var BitfabClaudeAgentHandler = class {
617
618
  }
618
619
  };
619
620
  //#endregion
620
- //#region src/optionalPeer.ts
621
- function importOptionalPeer(specifierParts) {
622
- return import(
623
- /* webpackIgnore: true */
624
- /* @vite-ignore */
625
- specifierParts.join("/")
626
- );
627
- }
628
- //#endregion
629
621
  //#region src/baml.ts
630
- let cachedBaml = null;
631
622
  async function loadBaml() {
632
- if (cachedBaml) return cachedBaml;
633
- try {
634
- cachedBaml = await importOptionalPeer(["@boundaryml", "baml"]);
635
- return cachedBaml;
636
- } catch {
637
- throw new Error("@boundaryml/baml is required for Bitfab.call(). Install it with: npm install @boundaryml/baml");
638
- }
623
+ const baml = await loadBamlModule();
624
+ if (!baml) throw new Error("@boundaryml/baml is required for Bitfab.call(). Install it with: npm install @boundaryml/baml. If it is installed and your app is bundled (Next.js with Turbopack, for example), add `import \"@bitfab/sdk/baml\"` once in your server code.");
625
+ return baml;
639
626
  }
640
627
  function capitalize(str) {
641
628
  return str.charAt(0).toUpperCase() + str.slice(1);
@@ -2073,6 +2060,7 @@ var OrganizationMembersClient = class {
2073
2060
  const MAX_FILES = 60;
2074
2061
  const MAX_FILE_BYTES = 5e5;
2075
2062
  const MAX_TOTAL_BYTES = 2e6;
2063
+ const MAX_BRANCH_WALK = 1e3;
2076
2064
  const NUL = String.fromCharCode(0);
2077
2065
  async function resolveAutoCodeChange(label) {
2078
2066
  if (typeof process === "undefined") return null;
@@ -2114,8 +2102,17 @@ async function captureCodeChangeFromGit(cwd, label) {
2114
2102
  try {
2115
2103
  const root = (await git(cwd, ["rev-parse", "--show-toplevel"]))?.trim();
2116
2104
  if (!root) return null;
2117
- const resolved = await resolveBase(git, root);
2105
+ let resolved = await resolveBase(git, root);
2118
2106
  if (!resolved) return null;
2107
+ let entries = await listChanges(git, root, resolved.base);
2108
+ if (entries.length === 0 && resolved.base === "HEAD") {
2109
+ const branchPoint = await resolveBranchPoint(git, root);
2110
+ if (branchPoint) {
2111
+ resolved = branchPoint;
2112
+ entries = await listChanges(git, root, branchPoint.base);
2113
+ }
2114
+ }
2115
+ if (entries.length === 0) return null;
2119
2116
  const { base, against } = resolved;
2120
2117
  const blobBytes = async (ref, path) => {
2121
2118
  const out = await git(root, [
@@ -2135,29 +2132,6 @@ async function captureCodeChangeFromGit(cwd, label) {
2135
2132
  return 0;
2136
2133
  }
2137
2134
  };
2138
- const tracked = await git(root, [
2139
- "diff",
2140
- "--name-status",
2141
- "--find-renames",
2142
- "-z",
2143
- base,
2144
- "--",
2145
- ":!.bitfab"
2146
- ]);
2147
- const untracked = await git(root, [
2148
- "ls-files",
2149
- "--others",
2150
- "--exclude-standard",
2151
- "-z",
2152
- "--",
2153
- ":!.bitfab"
2154
- ]);
2155
- const entries = [...parseNameStatusZ(tracked ?? ""), ...(untracked ?? "").split(NUL).filter((p) => p.length > 0).map((path) => ({
2156
- status: "A",
2157
- beforePath: path,
2158
- path
2159
- }))];
2160
- if (entries.length === 0) return null;
2161
2135
  const files = [];
2162
2136
  let totalBytes = 0;
2163
2137
  for (const { status, beforePath, path } of entries) {
@@ -2193,6 +2167,129 @@ async function captureCodeChangeFromGit(cwd, label) {
2193
2167
  return null;
2194
2168
  }
2195
2169
  }
2170
+ async function listChanges(git, root, base) {
2171
+ const tracked = await git(root, [
2172
+ "diff",
2173
+ "--name-status",
2174
+ "--find-renames",
2175
+ "-z",
2176
+ base,
2177
+ "--",
2178
+ ":!.bitfab"
2179
+ ]);
2180
+ const untracked = await git(root, [
2181
+ "ls-files",
2182
+ "--others",
2183
+ "--exclude-standard",
2184
+ "-z",
2185
+ "--",
2186
+ ":!.bitfab"
2187
+ ]);
2188
+ return [...parseNameStatusZ(tracked ?? ""), ...(untracked ?? "").split(NUL).filter((p) => p.length > 0).map((path) => ({
2189
+ status: "A",
2190
+ beforePath: path,
2191
+ path
2192
+ }))];
2193
+ }
2194
+ async function defaultBranchCandidates(git, root) {
2195
+ const originHead = (await git(root, [
2196
+ "rev-parse",
2197
+ "--abbrev-ref",
2198
+ "origin/HEAD"
2199
+ ]))?.trim();
2200
+ const candidates = [
2201
+ originHead && originHead !== "origin/HEAD" ? originHead : null,
2202
+ "origin/main",
2203
+ "origin/master",
2204
+ "main",
2205
+ "master"
2206
+ ].filter((ref) => !!ref);
2207
+ return [...new Set(candidates)];
2208
+ }
2209
+ async function resolveDefaultBranch(git, root) {
2210
+ for (const ref of await defaultBranchCandidates(git, root)) if (await refExists(git, root, ref)) return ref;
2211
+ return null;
2212
+ }
2213
+ async function currentBranchRefs(git, root) {
2214
+ const branch = (await git(root, [
2215
+ "symbolic-ref",
2216
+ "--short",
2217
+ "-q",
2218
+ "HEAD"
2219
+ ]))?.trim();
2220
+ const refs = /* @__PURE__ */ new Set();
2221
+ if (branch) {
2222
+ refs.add(`refs/heads/${branch}`);
2223
+ const remotes = (await git(root, ["remote"]))?.split(/\s+/) ?? [];
2224
+ for (const remote of remotes.filter((r) => r.length > 0)) refs.add(`refs/remotes/${remote}/${branch}`);
2225
+ }
2226
+ return refs;
2227
+ }
2228
+ async function ownBranchRefs(git, root) {
2229
+ const upstream = (await git(root, [
2230
+ "rev-parse",
2231
+ "--symbolic-full-name",
2232
+ "@{upstream}"
2233
+ ]))?.trim();
2234
+ const own = await currentBranchRefs(git, root);
2235
+ if (upstream) own.add(upstream);
2236
+ return own;
2237
+ }
2238
+ async function isOnDefaultBranch(git, root, defaultBranch) {
2239
+ const fullName = (await git(root, [
2240
+ "rev-parse",
2241
+ "--symbolic-full-name",
2242
+ defaultBranch
2243
+ ]))?.trim();
2244
+ return !!fullName && (await currentBranchRefs(git, root)).has(fullName);
2245
+ }
2246
+ async function branchTips(git, root) {
2247
+ const own = await ownBranchRefs(git, root);
2248
+ const listing = await git(root, [
2249
+ "for-each-ref",
2250
+ "--format=%(objectname) %(refname)",
2251
+ "refs/heads",
2252
+ "refs/remotes"
2253
+ ]);
2254
+ const tips = /* @__PURE__ */ new Map();
2255
+ for (const line of (listing ?? "").split("\n")) {
2256
+ const [sha, ref] = line.trim().split(" ");
2257
+ if (!ref || own.has(ref) || ref.endsWith("/HEAD") || tips.has(sha)) continue;
2258
+ tips.set(sha, ref.replace(/^refs\/(heads|remotes)\//, ""));
2259
+ }
2260
+ return tips;
2261
+ }
2262
+ async function resolveBranchPoint(git, root) {
2263
+ const head = (await git(root, ["rev-parse", "HEAD"]))?.trim();
2264
+ if (!head) return null;
2265
+ const defaultBranch = await resolveDefaultBranch(git, root);
2266
+ if (defaultBranch && await isOnDefaultBranch(git, root, defaultBranch)) return null;
2267
+ const defaultBase = defaultBranch ? (await git(root, [
2268
+ "merge-base",
2269
+ "HEAD",
2270
+ defaultBranch
2271
+ ]))?.trim() : void 0;
2272
+ const walk = [
2273
+ "rev-list",
2274
+ "--first-parent",
2275
+ `--max-count=${MAX_BRANCH_WALK}`,
2276
+ "HEAD",
2277
+ ...defaultBase ? [`^${defaultBase}`] : []
2278
+ ];
2279
+ const tips = await branchTips(git, root);
2280
+ const history = (await git(root, walk) ?? "").split(/\s+/).filter(Boolean);
2281
+ for (const sha of history.slice(1)) {
2282
+ const name = tips.get(sha);
2283
+ if (name) return {
2284
+ base: sha,
2285
+ against: `vs ${name}`
2286
+ };
2287
+ }
2288
+ return defaultBase && defaultBase !== head ? {
2289
+ base: defaultBase,
2290
+ against: `vs ${defaultBranch}`
2291
+ } : null;
2292
+ }
2196
2293
  async function resolveBase(git, root) {
2197
2294
  const forced = process.env?.BITFAB_CODE_CHANGE_BASE;
2198
2295
  if (forced && await refExists(git, root, forced)) {
@@ -4495,13 +4592,10 @@ function wrapAsyncGenerator(source, spanStack, sendSpan) {
4495
4592
  let cachedCollectorClass;
4496
4593
  async function loadCollectorClass() {
4497
4594
  if (cachedCollectorClass !== void 0) return cachedCollectorClass;
4498
- try {
4499
- cachedCollectorClass = (await importOptionalPeer(["@boundaryml", "baml"])).Collector;
4500
- return cachedCollectorClass;
4501
- } catch {
4502
- cachedCollectorClass = null;
4503
- return null;
4504
- }
4595
+ const baml = await loadBamlModule();
4596
+ if (!baml) return null;
4597
+ cachedCollectorClass = baml.Collector;
4598
+ return cachedCollectorClass;
4505
4599
  }
4506
4600
  function extractPromptFromCollector(collector) {
4507
4601
  try {
@@ -5145,6 +5239,7 @@ var Bitfab = class {
5145
5239
  const wrappedFn = async (...args) => {
5146
5240
  const CollectorClass = await loadCollectorClass();
5147
5241
  if (!CollectorClass) {
5242
+ warnOnce("wrapBAML-collector-unavailable", `@boundaryml/baml could not be loaded, so "${methodName}" and every other wrapBAML call run untraced: no prompt, model, or token usage is recorded and onCollector is not called. If @boundaryml/baml is installed and your app is bundled (Next.js with Turbopack, for example), add \`import "@bitfab/sdk/baml"\` once in your server code.`);
5148
5243
  wrappedFn.collector = null;
5149
5244
  return await bamlClient[methodName](...args);
5150
5245
  }
@@ -5813,7 +5908,7 @@ var Bitfab = class {
5813
5908
  await runWithSeedContext({ traceId }, async () => target(...args));
5814
5909
  } finally {
5815
5910
  try {
5816
- const { flushTraces } = await import("./http-BaLzqv9W.js").then((n) => n.a);
5911
+ const { flushTraces } = await import("./http-DUDL3FGE.js").then((n) => n.a);
5817
5912
  await flushTraces(3e4);
5818
5913
  } finally {
5819
5914
  unrecorded = activeTraceStates.delete(traceId);
@@ -6001,7 +6096,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
6001
6096
  metadata: seedCase.metadata,
6002
6097
  sessionId: seedCase.sessionId
6003
6098
  }));
6004
- const { flushTraces } = await import("./http-BaLzqv9W.js").then((n) => n.a);
6099
+ const { flushTraces } = await import("./http-DUDL3FGE.js").then((n) => n.a);
6005
6100
  await flushTraces(3e4);
6006
6101
  return {
6007
6102
  pipeline,
@@ -6018,4 +6113,4 @@ function resolveTraceFunctionKey(registration) {
6018
6113
  //#endregion
6019
6114
  export { SUPPORTED_PROVIDERS as A, BitfabOpenAIAgentHandler as C, LabelsClient as D, BitfabLangGraphCallbackHandler as E, DEFAULT_SERVICE_URL as F, AssertionCategoriesClient as I, CategoriesClient as L, GraderRerunError as M, GraderRerunTimeoutError as N, GradersClient as O, BitfabClaudeAgentHandler as P, OrganizationMembersClient as S, BitfabLangGraphIntegration as T, BITFAB_PROGRESS_PREFIX as _, Bitfab as a, reportReplayProgress as b, getCurrentSpan as c, BitfabOpenAITracingProcessor as d, AssertionGenerationError as f, BitfabRivetIntegration as g, SpansClient as h, finalizers as i, DatasetsClient as j, ExperimentsClient as k, getCurrentTrace as l, TracesClient as m, reseedFromRegistry as n, BitfabFunction as o, AssertionGenerationTimeoutError as p, seedFromRegistry as r, getCurrentReplayBranch as s, defineReplayRegistry as t, BitfabVercelAiHandler as u, DbBranchReplayError as v, NO_MOCK_OVERRIDE as w, serializeReplayResult as x, ReplayError as y };
6020
6115
 
6021
- //# sourceMappingURL=src-BblbvWfU.js.map
6116
+ //# sourceMappingURL=src-DYCb-06l.js.map