bitfab 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.
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-3JIPWENI.js";
9
+ } from "./chunk-YZGGAUG6.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-ALSBGWPS.js.map
19
+ //# sourceMappingURL=http-G5CODRDH.js.map
@@ -6,7 +6,7 @@ import {
6
6
  flushTraces,
7
7
  parseRetryAfterMs,
8
8
  serializePayloadBody
9
- } from "./chunk-OXE6M7CZ.js";
9
+ } from "./chunk-DYURJJSV.js";
10
10
  import "./chunk-H6LZRFMN.js";
11
11
  export {
12
12
  BitfabError,
@@ -17,4 +17,4 @@ export {
17
17
  parseRetryAfterMs,
18
18
  serializePayloadBody
19
19
  };
20
- //# sourceMappingURL=http-RMF7T3LG.js.map
20
+ //# sourceMappingURL=http-MRZNL7RE.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.39.0";
54
+ __version__ = "0.40.0";
55
55
  __packageName__ = "bitfab";
56
56
  }
57
57
  });
@@ -1741,6 +1741,10 @@ var init_http = __esm({
1741
1741
  const response = await this.get(endpoint);
1742
1742
  return response.span;
1743
1743
  }
1744
+ /**
1745
+ * GET a JSON endpoint on the service with the client's API key. Throws a
1746
+ * `BitfabError` carrying the status text for any non-2xx response.
1747
+ */
1744
1748
  async get(endpoint) {
1745
1749
  const url = `${this.serviceUrl}${endpoint}`;
1746
1750
  const controller = new AbortController();
@@ -1754,7 +1758,10 @@ var init_http = __esm({
1754
1758
  if (!response.ok) {
1755
1759
  const errorText = await response.text();
1756
1760
  throw new BitfabError(
1757
- `HTTP ${response.status}: ${errorText.slice(0, 500)}`
1761
+ `HTTP ${response.status}: ${errorText.slice(0, 500)}`,
1762
+ void 0,
1763
+ response.status,
1764
+ parseRetryAfterMs(readHeader(response, "retry-after"))
1758
1765
  );
1759
1766
  }
1760
1767
  return await response.json();
@@ -3206,6 +3213,7 @@ __export(index_exports, {
3206
3213
  BitfabOpenAITracingProcessor: () => BitfabOpenAITracingProcessor,
3207
3214
  BitfabVercelAiHandler: () => BitfabVercelAiHandler,
3208
3215
  DEFAULT_SERVICE_URL: () => DEFAULT_SERVICE_URL,
3216
+ DatasetsClient: () => DatasetsClient,
3209
3217
  DbBranchReplayError: () => DbBranchReplayError,
3210
3218
  HttpClient: () => HttpClient,
3211
3219
  NO_MOCK_OVERRIDE: () => NO_MOCK_OVERRIDE,
@@ -4285,6 +4293,131 @@ async function runFunctionWithBaml(bamlSource, inputs, providers, envVars) {
4285
4293
  // src/client.ts
4286
4294
  init_constants();
4287
4295
 
4296
+ // src/datasets.ts
4297
+ var DEFAULT_RERUN_TIMEOUT_MS = 9e4;
4298
+ var DEFAULT_RERUN_POLL_INTERVAL_MS = 1e3;
4299
+ var TERMINAL_RERUN_STATUSES = /* @__PURE__ */ new Set([
4300
+ "completed",
4301
+ "errored"
4302
+ ]);
4303
+ function sleep(ms) {
4304
+ return new Promise((resolve) => setTimeout(resolve, ms));
4305
+ }
4306
+ function datasetPath(datasetId, suffix = "") {
4307
+ return `/api/sdk/datasets/${encodeURIComponent(datasetId)}${suffix}`;
4308
+ }
4309
+ var DatasetsClient = class {
4310
+ constructor(httpClient) {
4311
+ this.httpClient = httpClient;
4312
+ }
4313
+ /**
4314
+ * Create a dataset, or update the one already named this way under the same
4315
+ * trace function. `created` reports which happened. An omitted description
4316
+ * leaves an existing one untouched.
4317
+ */
4318
+ async save(params) {
4319
+ return this.httpClient.request("/api/sdk/datasets", {
4320
+ traceFunctionKey: params.traceFunctionKey,
4321
+ name: params.name,
4322
+ ...params.description === void 0 ? {} : { description: params.description }
4323
+ });
4324
+ }
4325
+ /**
4326
+ * List datasets, scoped to one trace function when `traceFunctionKey` is
4327
+ * given and organization-wide otherwise.
4328
+ */
4329
+ async list(params = {}) {
4330
+ const query = params.traceFunctionKey === void 0 ? "" : `?traceFunctionKey=${encodeURIComponent(params.traceFunctionKey)}`;
4331
+ const response = await this.httpClient.get(
4332
+ `/api/sdk/datasets${query}`
4333
+ );
4334
+ return response.datasets;
4335
+ }
4336
+ /** Fetch one dataset by id. Rejects with a 404 `BitfabError` when it is not in this organization. */
4337
+ async get(datasetId) {
4338
+ const response = await this.httpClient.get(
4339
+ datasetPath(datasetId)
4340
+ );
4341
+ return response.dataset;
4342
+ }
4343
+ /** The ids of every trace in the dataset, the same membership a replay with `datasetId` selects. */
4344
+ async listTraces(datasetId) {
4345
+ return this.httpClient.get(
4346
+ datasetPath(datasetId, "/traces")
4347
+ );
4348
+ }
4349
+ /**
4350
+ * Add traces to the dataset (1 to 100 ids per call). Traces outside the
4351
+ * organization or under another trace function are reported in
4352
+ * `skippedTraceIds` rather than failing the call.
4353
+ */
4354
+ async addTraces(datasetId, traceIds) {
4355
+ return this.httpClient.request(
4356
+ datasetPath(datasetId, "/traces"),
4357
+ { traceIds }
4358
+ );
4359
+ }
4360
+ /** Remove traces from the dataset. The traces themselves are never deleted. */
4361
+ async removeTraces(datasetId, traceIds) {
4362
+ return this.httpClient.request(
4363
+ datasetPath(datasetId, "/removeTraces"),
4364
+ { traceIds }
4365
+ );
4366
+ }
4367
+ /**
4368
+ * Assign graders to the dataset (1 to 100 ids per call). Graders outside the
4369
+ * organization or under another trace function are reported in
4370
+ * `skippedGraderIds` rather than failing the call.
4371
+ */
4372
+ async addGraders(datasetId, graderIds) {
4373
+ return this.httpClient.request(
4374
+ datasetPath(datasetId, "/graders"),
4375
+ { graderIds }
4376
+ );
4377
+ }
4378
+ /** Unassign graders from the dataset. */
4379
+ async removeGraders(datasetId, graderIds) {
4380
+ return this.httpClient.request(
4381
+ datasetPath(datasetId, "/removeGraders"),
4382
+ { graderIds }
4383
+ );
4384
+ }
4385
+ /**
4386
+ * Re-run graders over every trace in the dataset. Defaults to every assigned
4387
+ * grader; an unassigned id is rejected. Waits for the run to finish (up to
4388
+ * `timeoutMs`, default 90s) unless `wait` is `false`, and returns the last
4389
+ * run state seen either way. A request matching an in-flight run joins it.
4390
+ */
4391
+ async rerunGraders(datasetId, options = {}) {
4392
+ const started = await this.httpClient.request(
4393
+ datasetPath(datasetId, "/rerunGraders"),
4394
+ options.graderIds === void 0 ? {} : { graderIds: options.graderIds }
4395
+ );
4396
+ if (options.wait === false) {
4397
+ return started;
4398
+ }
4399
+ const deadline = Date.now() + (options.timeoutMs ?? DEFAULT_RERUN_TIMEOUT_MS);
4400
+ const interval = options.pollIntervalMs ?? DEFAULT_RERUN_POLL_INTERVAL_MS;
4401
+ let run = started.run;
4402
+ while (!TERMINAL_RERUN_STATUSES.has(run.status) && Date.now() < deadline) {
4403
+ await sleep(interval);
4404
+ run = await this.getGraderRerun(datasetId, run.id) ?? run;
4405
+ }
4406
+ return { run, joinedExisting: started.joinedExisting };
4407
+ }
4408
+ /**
4409
+ * The dataset's active grader re-run, or the run named by `runId`. Returns
4410
+ * `null` when nothing is active or the run does not belong to this dataset.
4411
+ */
4412
+ async getGraderRerun(datasetId, runId) {
4413
+ const query = runId === void 0 ? "" : `?runId=${encodeURIComponent(runId)}`;
4414
+ const response = await this.httpClient.get(
4415
+ datasetPath(datasetId, `/rerunGraders${query}`)
4416
+ );
4417
+ return response.run;
4418
+ }
4419
+ };
4420
+
4288
4421
  // src/dbSnapshot.ts
4289
4422
  init_errors();
4290
4423
  var SUPPORTED_PROVIDERS = ["neon"];
@@ -6020,6 +6153,7 @@ var Bitfab = class {
6020
6153
  serviceUrl: this.serviceUrl,
6021
6154
  timeout: this.timeout
6022
6155
  });
6156
+ this.datasets = new DatasetsClient(this.httpClient);
6023
6157
  }
6024
6158
  /**
6025
6159
  * Decorate a class method as an automatically expanded trace root.
@@ -7833,6 +7967,7 @@ function resolveTraceFunctionKey(registration) {
7833
7967
  BitfabOpenAITracingProcessor,
7834
7968
  BitfabVercelAiHandler,
7835
7969
  DEFAULT_SERVICE_URL,
7970
+ DatasetsClient,
7836
7971
  DbBranchReplayError,
7837
7972
  HttpClient,
7838
7973
  NO_MOCK_OVERRIDE,