@bitfab/sdk 0.39.0 → 0.40.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.
@@ -14,14 +14,14 @@ import {
14
14
  serializeValue,
15
15
  toJsonSafe,
16
16
  toJsonSafeReport
17
- } from "./chunk-FW7PZ3EP.js";
17
+ } from "./chunk-EXT5FK54.js";
18
18
  import {
19
19
  BitfabError,
20
20
  DEFAULT_SERVICE_URL,
21
21
  HttpClient,
22
22
  getReplayContext,
23
23
  warnOnce
24
- } from "./chunk-2JQSYJJR.js";
24
+ } from "./chunk-A22EYRSY.js";
25
25
  import {
26
26
  __privateAdd,
27
27
  __privateGet,
@@ -949,6 +949,131 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
949
949
  };
950
950
  }
951
951
 
952
+ // src/datasets.ts
953
+ var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
954
+ var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
955
+ var TERMINAL_RERUN_STATUSES = /* @__PURE__ */ new Set([
956
+ "completed",
957
+ "errored"
958
+ ]);
959
+ function sleep(ms) {
960
+ return new Promise((resolve) => setTimeout(resolve, ms));
961
+ }
962
+ function datasetPath(datasetId, suffix = "") {
963
+ return `/api/sdk/datasets/${encodeURIComponent(datasetId)}${suffix}`;
964
+ }
965
+ var DatasetsClient = class {
966
+ constructor(httpClient) {
967
+ this.httpClient = httpClient;
968
+ }
969
+ /**
970
+ * Create a dataset, or update the one already named this way under the same
971
+ * trace function. `created` reports which happened. An omitted description
972
+ * leaves an existing one untouched.
973
+ */
974
+ async save(params) {
975
+ return this.httpClient.request("/api/sdk/datasets", {
976
+ traceFunctionKey: params.traceFunctionKey,
977
+ name: params.name,
978
+ ...params.description === void 0 ? {} : { description: params.description }
979
+ });
980
+ }
981
+ /**
982
+ * List datasets, scoped to one trace function when `traceFunctionKey` is
983
+ * given and organization-wide otherwise.
984
+ */
985
+ async list(params = {}) {
986
+ const query = params.traceFunctionKey === void 0 ? "" : `?traceFunctionKey=${encodeURIComponent(params.traceFunctionKey)}`;
987
+ const response = await this.httpClient.get(
988
+ `/api/sdk/datasets${query}`
989
+ );
990
+ return response.datasets;
991
+ }
992
+ /** Fetch one dataset by id. Rejects with a 404 `BitfabError` when it is not in this organization. */
993
+ async get(datasetId) {
994
+ const response = await this.httpClient.get(
995
+ datasetPath(datasetId)
996
+ );
997
+ return response.dataset;
998
+ }
999
+ /** The ids of every trace in the dataset, the same membership a replay with `datasetId` selects. */
1000
+ async listTraces(datasetId) {
1001
+ return this.httpClient.get(
1002
+ datasetPath(datasetId, "/traces")
1003
+ );
1004
+ }
1005
+ /**
1006
+ * Add traces to the dataset (1 to 100 ids per call). Traces outside the
1007
+ * organization or under another trace function are reported in
1008
+ * `skippedTraceIds` rather than failing the call.
1009
+ */
1010
+ async addTraces(datasetId, traceIds) {
1011
+ return this.httpClient.request(
1012
+ datasetPath(datasetId, "/traces"),
1013
+ { traceIds }
1014
+ );
1015
+ }
1016
+ /** Remove traces from the dataset. The traces themselves are never deleted. */
1017
+ async removeTraces(datasetId, traceIds) {
1018
+ return this.httpClient.request(
1019
+ datasetPath(datasetId, "/removeTraces"),
1020
+ { traceIds }
1021
+ );
1022
+ }
1023
+ /**
1024
+ * Assign graders to the dataset (1 to 100 ids per call). Graders outside the
1025
+ * organization or under another trace function are reported in
1026
+ * `skippedGraderIds` rather than failing the call.
1027
+ */
1028
+ async addGraders(datasetId, graderIds) {
1029
+ return this.httpClient.request(
1030
+ datasetPath(datasetId, "/graders"),
1031
+ { graderIds }
1032
+ );
1033
+ }
1034
+ /** Unassign graders from the dataset. */
1035
+ async removeGraders(datasetId, graderIds) {
1036
+ return this.httpClient.request(
1037
+ datasetPath(datasetId, "/removeGraders"),
1038
+ { graderIds }
1039
+ );
1040
+ }
1041
+ /**
1042
+ * Re-run graders over every trace in the dataset. Defaults to every assigned
1043
+ * grader; an unassigned id is rejected. Waits for the run to finish (up to
1044
+ * `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
1045
+ * run state seen either way. A request matching an in-flight run joins it.
1046
+ */
1047
+ async rerunGraders(datasetId, options = {}) {
1048
+ const started = await this.httpClient.request(
1049
+ datasetPath(datasetId, "/rerunGraders"),
1050
+ options.graderIds === void 0 ? {} : { graderIds: options.graderIds }
1051
+ );
1052
+ if (options.wait === false) {
1053
+ return started;
1054
+ }
1055
+ const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS);
1056
+ const interval = options.pollIntervalMs ?? DEFAULT_RERUN_POLL_INTERVAL_MS;
1057
+ let run = started.run;
1058
+ while (!TERMINAL_RERUN_STATUSES.has(run.status) && Date.now() < deadline) {
1059
+ await sleep(interval);
1060
+ run = await this.getGraderRerun(datasetId, run.id) ?? run;
1061
+ }
1062
+ return { run, joinedExisting: started.joinedExisting };
1063
+ }
1064
+ /**
1065
+ * The dataset's active grader re-run, or the run named by `runId`. Returns
1066
+ * `null` when nothing is active or the run does not belong to this dataset.
1067
+ */
1068
+ async getGraderRerun(datasetId, runId) {
1069
+ const query = runId === void 0 ? "" : `?runId=${encodeURIComponent(runId)}`;
1070
+ const response = await this.httpClient.get(
1071
+ datasetPath(datasetId, `/rerunGraders${query}`)
1072
+ );
1073
+ return response.run;
1074
+ }
1075
+ };
1076
+
952
1077
  // src/dbSnapshot.ts
953
1078
  var SUPPORTED_PROVIDERS = ["neon"];
954
1079
  function validateDbSnapshotConfig(config) {
@@ -2660,6 +2785,7 @@ var Bitfab = class {
2660
2785
  serviceUrl: this.serviceUrl,
2661
2786
  timeout: this.timeout
2662
2787
  });
2788
+ this.datasets = new DatasetsClient(this.httpClient);
2663
2789
  }
2664
2790
  /**
2665
2791
  * Decorate a class method as an automatically expanded trace root.
@@ -4182,7 +4308,7 @@ var Bitfab = class {
4182
4308
  `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.`
4183
4309
  );
4184
4310
  }
4185
- const { replay: doReplay } = await import("./replay-MZYX4IFV.js");
4311
+ const { replay: doReplay } = await import("./replay-352POXG3.js");
4186
4312
  return doReplay(
4187
4313
  this.httpClient,
4188
4314
  this.serviceUrl,
@@ -4435,7 +4561,7 @@ async function seedFromRegistry(registry, pipeline, cases) {
4435
4561
  sessionId: seedCase.sessionId
4436
4562
  })
4437
4563
  );
4438
- const { flushTraces: flushTraces2 } = await import("./http-PRCLI43J.js");
4564
+ const { flushTraces: flushTraces2 } = await import("./http-2OFIGQOK.js");
4439
4565
  await flushTraces2(3e4);
4440
4566
  return { pipeline, traceFunctionKey, traceIds };
4441
4567
  }
@@ -4452,6 +4578,7 @@ function resolveTraceFunctionKey(registration) {
4452
4578
 
4453
4579
  export {
4454
4580
  BitfabClaudeAgentHandler,
4581
+ DatasetsClient,
4455
4582
  SUPPORTED_PROVIDERS,
4456
4583
  BitfabLangGraphCallbackHandler,
4457
4584
  BitfabLangGraphIntegration,
@@ -4467,4 +4594,4 @@ export {
4467
4594
  defineReplayRegistry,
4468
4595
  seedFromRegistry
4469
4596
  };
4470
- //# sourceMappingURL=chunk-SHJ3ABUG.js.map
4597
+ //# sourceMappingURL=chunk-5NT4YDCQ.js.map