bitfab 0.58.5 → 0.59.0

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 (31) hide show
  1. package/dist/{chunk-TAEWAXPA.js → chunk-FHEEAPG2.js} +2 -2
  2. package/dist/{chunk-7SPNHC33.js → chunk-KFZ5OIN5.js} +2 -2
  3. package/dist/{chunk-7SPNHC33.js.map → chunk-KFZ5OIN5.js.map} +1 -1
  4. package/dist/{chunk-QIBFNIIF.js → chunk-R5MUOBRK.js} +2 -2
  5. package/dist/{chunk-QIBFNIIF.js.map → chunk-R5MUOBRK.js.map} +1 -1
  6. package/dist/{chunk-UYAQRSCB.js → chunk-RYSCYPHQ.js} +118 -21
  7. package/dist/chunk-RYSCYPHQ.js.map +1 -0
  8. package/dist/{chunk-OTQA6MCF.js → chunk-Y6FVWJKU.js} +3 -3
  9. package/dist/{http-XDKEIZNV.js → http-7WLON2BH.js} +2 -2
  10. package/dist/{http-F6QV3YLY.js → http-D7P4JL6C.js} +2 -2
  11. package/dist/index.cjs +117 -16
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +32 -10
  14. package/dist/index.d.ts +32 -10
  15. package/dist/index.js +11 -3
  16. package/dist/node.cjs +117 -16
  17. package/dist/node.cjs.map +1 -1
  18. package/dist/node.d.cts +1 -1
  19. package/dist/node.d.ts +1 -1
  20. package/dist/node.js +11 -3
  21. package/dist/node.js.map +1 -1
  22. package/dist/{replay-WLJFWS6T.js → replay-5TZNJ2DL.js} +3 -3
  23. package/dist/replayCli.js +2 -2
  24. package/dist/seedCli.js +2 -2
  25. package/package.json +1 -1
  26. package/dist/chunk-UYAQRSCB.js.map +0 -1
  27. /package/dist/{chunk-TAEWAXPA.js.map → chunk-FHEEAPG2.js.map} +0 -0
  28. /package/dist/{chunk-OTQA6MCF.js.map → chunk-Y6FVWJKU.js.map} +0 -0
  29. /package/dist/{http-F6QV3YLY.js.map → http-7WLON2BH.js.map} +0 -0
  30. /package/dist/{http-XDKEIZNV.js.map → http-D7P4JL6C.js.map} +0 -0
  31. /package/dist/{replay-WLJFWS6T.js.map → replay-5TZNJ2DL.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BitfabError
3
- } from "./chunk-QIBFNIIF.js";
3
+ } from "./chunk-R5MUOBRK.js";
4
4
 
5
5
  // src/codeChange.ts
6
6
  var NUL = String.fromCharCode(0);
@@ -234,7 +234,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
234
234
  sessionId: seedCase.sessionId
235
235
  })
236
236
  );
237
- const { flushTraces: flushTraces2 } = await import("./http-XDKEIZNV.js");
237
+ const { flushTraces: flushTraces2 } = await import("./http-7WLON2BH.js");
238
238
  await flushTraces2(3e4);
239
239
  return { pipeline, traceFunctionKey, traceIds };
240
240
  }
@@ -782,4 +782,4 @@ export {
782
782
  runRegistryMain,
783
783
  runIfEntrypoint
784
784
  };
785
- //# sourceMappingURL=chunk-OTQA6MCF.js.map
785
+ //# sourceMappingURL=chunk-Y6FVWJKU.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-QIBFNIIF.js";
9
+ } from "./chunk-R5MUOBRK.js";
10
10
  export {
11
11
  BitfabError,
12
12
  HttpClient,
@@ -16,4 +16,4 @@ export {
16
16
  parseRetryAfterMs,
17
17
  serializePayloadBody
18
18
  };
19
- //# sourceMappingURL=http-XDKEIZNV.js.map
19
+ //# sourceMappingURL=http-7WLON2BH.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-7SPNHC33.js";
9
+ } from "./chunk-KFZ5OIN5.js";
10
10
  import "./chunk-BAOIRE5T.js";
11
11
  export {
12
12
  BitfabError,
@@ -17,4 +17,4 @@ export {
17
17
  parseRetryAfterMs,
18
18
  serializePayloadBody
19
19
  };
20
- //# sourceMappingURL=http-F6QV3YLY.js.map
20
+ //# sourceMappingURL=http-D7P4JL6C.js.map
package/dist/index.cjs CHANGED
@@ -51,7 +51,7 @@ var __version__, __packageName__;
51
51
  var init_version_generated = __esm({
52
52
  "src/version.generated.ts"() {
53
53
  "use strict";
54
- __version__ = "0.58.5";
54
+ __version__ = "0.59.0";
55
55
  __packageName__ = "bitfab";
56
56
  }
57
57
  });
@@ -4399,6 +4399,8 @@ var init_replay = __esm({
4399
4399
  var index_exports = {};
4400
4400
  __export(index_exports, {
4401
4401
  AssertionCategoriesClient: () => AssertionCategoriesClient,
4402
+ AssertionGenerationError: () => AssertionGenerationError,
4403
+ AssertionGenerationTimeoutError: () => AssertionGenerationTimeoutError,
4402
4404
  BITFAB_PROGRESS_PREFIX: () => BITFAB_PROGRESS_PREFIX,
4403
4405
  Bitfab: () => Bitfab,
4404
4406
  BitfabClaudeAgentHandler: () => BitfabClaudeAgentHandler,
@@ -4414,6 +4416,8 @@ __export(index_exports, {
4414
4416
  DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
4415
4417
  DatasetsClient: () => DatasetsClient,
4416
4418
  DbBranchReplayError: () => DbBranchReplayError,
4419
+ GraderRerunError: () => GraderRerunError,
4420
+ GraderRerunTimeoutError: () => GraderRerunTimeoutError,
4417
4421
  GradersClient: () => GradersClient,
4418
4422
  HttpClient: () => HttpClient,
4419
4423
  LabelsClient: () => LabelsClient,
@@ -5841,11 +5845,39 @@ init_constants();
5841
5845
 
5842
5846
  // src/datasets.ts
5843
5847
  var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
5844
- var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
5848
+ var RERUN_POLL_INTERVAL_MS = 1e3;
5845
5849
  var TERMINAL_RERUN_STATUSES = /* @__PURE__ */ new Set([
5846
5850
  "completed",
5847
5851
  "errored"
5848
5852
  ]);
5853
+ var GraderRerunError = class extends Error {
5854
+ constructor(message, run) {
5855
+ super(message);
5856
+ this.run = run;
5857
+ this.name = "GraderRerunError";
5858
+ }
5859
+ };
5860
+ var GraderRerunTimeoutError = class extends GraderRerunError {
5861
+ constructor(datasetId, run, timeoutMs) {
5862
+ super(
5863
+ `Grader re-run ${run.id} on dataset ${datasetId} was still ${run.status} after ${timeoutMs}ms. It keeps running on Bitfab; read it later with getGraderRerun.`,
5864
+ run
5865
+ );
5866
+ this.name = "GraderRerunTimeoutError";
5867
+ }
5868
+ };
5869
+ function finishedRerun(datasetId, run, joinedExisting) {
5870
+ if (!TERMINAL_RERUN_STATUSES.has(run.status)) {
5871
+ return null;
5872
+ }
5873
+ if (run.status === "errored") {
5874
+ throw new GraderRerunError(
5875
+ `Grader re-run ${run.id} on dataset ${datasetId} errored: ${run.error ?? "no reason recorded"}`,
5876
+ run
5877
+ );
5878
+ }
5879
+ return { run, joinedExisting };
5880
+ }
5849
5881
  function sleep(ms) {
5850
5882
  return new Promise((resolve) => setTimeout(resolve, ms));
5851
5883
  }
@@ -5945,28 +5977,25 @@ var DatasetsClient = class {
5945
5977
  { graderIds }
5946
5978
  );
5947
5979
  }
5948
- /**
5949
- * Re-run graders over every trace in the dataset. Defaults to every assigned
5950
- * grader; an unassigned id is rejected. Waits for the run to finish (up to
5951
- * `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
5952
- * run state seen either way. A request matching an in-flight run joins it.
5953
- */
5954
5980
  async rerunGraders(datasetId, options = {}) {
5955
5981
  const started = await this.httpClient.request(
5956
5982
  datasetPath(datasetId, "/rerunGraders"),
5957
5983
  options.graderIds === void 0 ? {} : { graderIds: options.graderIds }
5958
5984
  );
5959
- if (options.wait === false) {
5960
- return started;
5961
- }
5962
- const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS);
5963
- const interval = options.pollIntervalMs ?? DEFAULT_RERUN_POLL_INTERVAL_MS;
5985
+ const timeoutMs = options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS;
5986
+ const deadline = Date.now() + timeoutMs;
5964
5987
  let run = started.run;
5965
- while (!TERMINAL_RERUN_STATUSES.has(run.status) && Date.now() < deadline) {
5966
- await sleep(interval);
5988
+ while (true) {
5989
+ const finished = finishedRerun(datasetId, run, started.joinedExisting);
5990
+ if (finished !== null) {
5991
+ return finished;
5992
+ }
5993
+ if (Date.now() >= deadline) {
5994
+ throw new GraderRerunTimeoutError(datasetId, run, timeoutMs);
5995
+ }
5996
+ await sleep(RERUN_POLL_INTERVAL_MS);
5967
5997
  run = await this.getGraderRerun(datasetId, run.id) ?? run;
5968
5998
  }
5969
- return { run, joinedExisting: started.joinedExisting };
5970
5999
  }
5971
6000
  /**
5972
6001
  * The dataset's active grader re-run, or the run named by `runId`. Returns
@@ -7822,6 +7851,46 @@ init_traceMetadata();
7822
7851
  // src/traces.ts
7823
7852
  var ASSERTIONS_PATH = "/api/sdk/traces/assertions";
7824
7853
  var SEARCH_PATH = "/api/sdk/traces/search";
7854
+ var DEFAULT_GENERATION_TIMEOUT_MS = 6e5;
7855
+ var GENERATION_POLL_INTERVAL_MS = 2e3;
7856
+ var AssertionGenerationError = class extends Error {
7857
+ constructor(message, traceId) {
7858
+ super(message);
7859
+ this.traceId = traceId;
7860
+ this.name = "AssertionGenerationError";
7861
+ }
7862
+ };
7863
+ var AssertionGenerationTimeoutError = class extends AssertionGenerationError {
7864
+ constructor(traceId, timeoutMs) {
7865
+ super(
7866
+ `Assertion generation for trace ${traceId} did not finish within ${timeoutMs}ms. Generation keeps running on Bitfab. Call getAssertions and read its generation field to check its status.`,
7867
+ traceId
7868
+ );
7869
+ this.name = "AssertionGenerationTimeoutError";
7870
+ }
7871
+ };
7872
+ function sleep2(ms) {
7873
+ return new Promise((resolve) => setTimeout(resolve, ms));
7874
+ }
7875
+ function isGenerationFinished(traceId, generation) {
7876
+ if (generation === null || generation.status === "running") {
7877
+ return false;
7878
+ }
7879
+ if (generation.status === "failed") {
7880
+ throw new AssertionGenerationError(
7881
+ `Assertion generation for trace ${traceId} failed: ${generation.error ?? "no reason recorded"}. Pass regenerate: true to try again.`,
7882
+ traceId
7883
+ );
7884
+ }
7885
+ return true;
7886
+ }
7887
+ function draftsInGenerationOrder(assertions, assertionIds) {
7888
+ const byId = new Map(assertions.map((assertion) => [assertion.id, assertion]));
7889
+ return assertionIds.flatMap((id) => {
7890
+ const assertion = byId.get(id);
7891
+ return assertion === void 0 ? [] : [assertion];
7892
+ });
7893
+ }
7825
7894
  function traceAssertionsPath(traceId, suffix = "") {
7826
7895
  return `/api/sdk/traces/${encodeURIComponent(traceId)}/assertions${suffix}`;
7827
7896
  }
@@ -7853,6 +7922,34 @@ var TracesClient = class {
7853
7922
  });
7854
7923
  return response.assertions;
7855
7924
  }
7925
+ async generateAssertions(traceId, options = {}) {
7926
+ const started = await this.httpClient.request(
7927
+ traceAssertionsPath(traceId, "/generate"),
7928
+ {
7929
+ ...options.guidance === void 0 ? {} : { guidance: options.guidance },
7930
+ ...options.categoryIds === void 0 ? {} : { categoryIds: options.categoryIds },
7931
+ ...options.regenerate === void 0 ? {} : { regenerate: options.regenerate }
7932
+ }
7933
+ );
7934
+ if (isGenerationFinished(traceId, started.generation)) {
7935
+ return started.assertions;
7936
+ }
7937
+ const timeoutMs = options.timeoutMs ?? DEFAULT_GENERATION_TIMEOUT_MS;
7938
+ const deadline = Date.now() + timeoutMs;
7939
+ while (true) {
7940
+ if (Date.now() >= deadline) {
7941
+ throw new AssertionGenerationTimeoutError(traceId, timeoutMs);
7942
+ }
7943
+ await sleep2(GENERATION_POLL_INTERVAL_MS);
7944
+ const read2 = await this.getAssertions(traceId);
7945
+ if (isGenerationFinished(traceId, read2.generation)) {
7946
+ return draftsInGenerationOrder(
7947
+ read2.assertions,
7948
+ read2.generation.assertionIds
7949
+ );
7950
+ }
7951
+ }
7952
+ }
7856
7953
  async archiveAssertions(params) {
7857
7954
  const response = await this.httpClient.request(
7858
7955
  traceAssertionsPath(params.traceId, "/archive"),
@@ -11071,6 +11168,8 @@ function resolveTraceFunctionKey(registration) {
11071
11168
  // Annotate the CommonJS export names for ESM import in node:
11072
11169
  0 && (module.exports = {
11073
11170
  AssertionCategoriesClient,
11171
+ AssertionGenerationError,
11172
+ AssertionGenerationTimeoutError,
11074
11173
  BITFAB_PROGRESS_PREFIX,
11075
11174
  Bitfab,
11076
11175
  BitfabClaudeAgentHandler,
@@ -11086,6 +11185,8 @@ function resolveTraceFunctionKey(registration) {
11086
11185
  DEFAULT_SERVICE_URL,
11087
11186
  DatasetsClient,
11088
11187
  DbBranchReplayError,
11188
+ GraderRerunError,
11189
+ GraderRerunTimeoutError,
11089
11190
  GradersClient,
11090
11191
  HttpClient,
11091
11192
  LabelsClient,