bitfab 0.65.10 → 0.66.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.
@@ -1,5 +1,5 @@
1
1
  const require_bamlPeer = require("./bamlPeer-BUoZgNxZ.cjs");
2
- const require_http = require("./http-C9CDbT4U.cjs");
2
+ const require_http = require("./http-DIz8mEMq.cjs");
3
3
  const require_autoTrace = require("./autoTrace-CQw0qMBt.cjs");
4
4
  let superjson = require("superjson");
5
5
  superjson = require_bamlPeer.__toESM(superjson, 1);
@@ -1240,52 +1240,63 @@ var ExperimentsClient = class {
1240
1240
  }
1241
1241
  };
1242
1242
  //#endregion
1243
- //#region src/graders.ts
1244
- const GRADER_LABELS_PATH = "/api/sdk/graderLabels";
1245
- var GradersClient = class {
1246
- constructor(httpClient) {
1247
- this.httpClient = httpClient;
1248
- }
1249
- async getLabels(params) {
1250
- const hasTraceIds = params.traceIds !== void 0 && params.traceIds.length > 0;
1251
- const hasGraderId = params.graderId !== void 0;
1252
- if (!hasTraceIds && !hasGraderId) throw new require_http.BitfabError("Pass traceIds, graderId, or both: there is nothing to read otherwise.");
1253
- const query = new URLSearchParams();
1254
- if (params.traceIds !== void 0 && params.traceIds.length > 0) query.set("traceIds", params.traceIds.join(","));
1255
- if (params.graderId !== void 0) query.set("graderId", params.graderId);
1256
- if (params.limit !== void 0) query.set("limit", String(params.limit));
1257
- return (await this.httpClient.get(`${GRADER_LABELS_PATH}?${query.toString()}`)).labels;
1258
- }
1259
- async saveLabel(update) {
1260
- const [outcome] = await this.saveLabelAll([update]);
1261
- return outcome;
1243
+ //#region src/verdicts.ts
1244
+ const VERDICTS_PATH = "/api/sdk/traces/verdicts";
1245
+ const HUMAN_VERDICTS_PATH = "/api/sdk/traces/verdicts/human";
1246
+ function isSkipOrArchive(fields) {
1247
+ return fields.skip === true || fields.archive === true;
1248
+ }
1249
+ function toWireVerdict(update) {
1250
+ const fields = update;
1251
+ const legacyLabel = fields.label !== void 0;
1252
+ const legacyAbstain = fields.abstain !== void 0;
1253
+ if (!legacyLabel && !legacyAbstain) return update;
1254
+ if (fields.verdict !== void 0) throw new require_http.BitfabError("Pass verdict, or the deprecated label or abstain, not both.");
1255
+ if (legacyLabel && fields.abstain === true) throw new require_http.BitfabError("Pass the deprecated label or abstain, not both. Pass verdict: \"pass\" | \"fail\" | \"abstained\" instead.");
1256
+ const { label, abstain, ...rest } = fields;
1257
+ if (!legacyLabel && abstain !== true) {
1258
+ if (isSkipOrArchive(fields)) return rest;
1259
+ throw new require_http.BitfabError("abstain: false is not a verdict. Pass verdict: \"pass\" | \"fail\" | \"abstained\" instead.");
1260
+ }
1261
+ if (legacyLabel) {
1262
+ require_autoTrace.warnOnce("deprecated-label-field", "The label field is deprecated; pass verdict: \"pass\" | \"fail\" instead.");
1263
+ return {
1264
+ ...rest,
1265
+ verdict: label === true ? "pass" : "fail"
1266
+ };
1262
1267
  }
1263
- async saveLabelAll(updates) {
1264
- return (await this.httpClient.request(GRADER_LABELS_PATH, { labels: updates })).labels;
1268
+ require_autoTrace.warnOnce("deprecated-abstain-field", "The abstain field is deprecated; pass verdict: \"abstained\" or call verdicts.abstain instead.");
1269
+ return {
1270
+ ...rest,
1271
+ verdict: "abstained"
1272
+ };
1273
+ }
1274
+ function assertAbstainedCarriesNoExtras(updates) {
1275
+ for (const update of updates) {
1276
+ const fields = update;
1277
+ if (fields.verdict !== "abstained") continue;
1278
+ const extra = fields.confidence !== void 0 ? "confidence" : fields.evidence !== void 0 ? "evidence" : null;
1279
+ if (extra !== null) throw new require_http.BitfabError(`An "abstained" verdict carries no ${extra}, since nothing was found to judge.`);
1265
1280
  }
1266
- };
1267
- //#endregion
1268
- //#region src/labels.ts
1269
- const LABELS_PATH = "/api/sdk/traces/labels";
1270
- const HUMAN_LABELS_PATH = "/api/sdk/traces/labels/human";
1281
+ }
1271
1282
  function assertEveryVerdictNamesAnAssertion(updates) {
1272
1283
  const unscoped = updates.filter((update) => !("archive" in update && update.archive === true) && (typeof update.assertionId !== "string" || update.assertionId === ""));
1273
1284
  if (unscoped.length > 0) {
1274
1285
  const targets = unscoped.map((update) => update.traceId ?? update.originalTraceId);
1275
- throw new require_http.BitfabError(`Agent verdicts must name an assertion: ${targets.join(", ")}. Pass the assertionId of the assertion each verdict scores to labels.save, saveAll, skip, and abstain. Only archive may omit it, to clear an old whole-trace verdict.`);
1286
+ throw new require_http.BitfabError(`Agent verdicts must name an assertion: ${targets.join(", ")}. Pass the assertionId of the assertion each verdict scores to verdicts.save, saveAll, skip, and abstain. Only archive may omit it, to clear an old whole-trace verdict.`);
1276
1287
  }
1277
1288
  }
1278
1289
  function assertEveryHumanVerdictNamesAnAssertion(updates) {
1279
1290
  const unscoped = updates.filter((update) => typeof update.assertionId !== "string" || update.assertionId === "");
1280
1291
  if (unscoped.length > 0) {
1281
1292
  const targets = unscoped.map((update) => update.traceId);
1282
- throw new require_http.BitfabError(`Human verdicts must name an assertion: ${targets.join(", ")}. Pass the assertionId of the assertion each verdict scores to labels.saveHuman and saveHumanAll.`);
1293
+ throw new require_http.BitfabError(`Human verdicts must name an assertion: ${targets.join(", ")}. Pass the assertionId of the assertion each verdict scores to verdicts.saveHuman and saveHumanAll.`);
1283
1294
  }
1284
1295
  }
1285
- function labelEvidencePath(traceId, assertionId) {
1296
+ function verdictEvidencePath(traceId, assertionId) {
1286
1297
  return `/api/sdk/traces/${encodeURIComponent(traceId)}/assertions/${encodeURIComponent(assertionId)}/evidence`;
1287
1298
  }
1288
- var LabelsClient = class {
1299
+ var VerdictsClient = class {
1289
1300
  constructor(httpClient) {
1290
1301
  this.httpClient = httpClient;
1291
1302
  }
@@ -1295,10 +1306,12 @@ var LabelsClient = class {
1295
1306
  }
1296
1307
  async saveAll(updates, experimentId) {
1297
1308
  assertEveryVerdictNamesAnAssertion(updates);
1298
- return (await this.httpClient.request(LABELS_PATH, {
1299
- labels: updates,
1309
+ const verdicts = updates.map((update) => toWireVerdict(update));
1310
+ assertAbstainedCarriesNoExtras(verdicts);
1311
+ return (await this.httpClient.request(VERDICTS_PATH, {
1312
+ verdicts,
1300
1313
  ...experimentId === void 0 ? {} : require_http.experimentIdWireFields(experimentId)
1301
- })).labels;
1314
+ })).verdicts;
1302
1315
  }
1303
1316
  async skip(target, experimentId) {
1304
1317
  return this.save({
@@ -1309,7 +1322,7 @@ var LabelsClient = class {
1309
1322
  async abstain(target, experimentId) {
1310
1323
  return this.save({
1311
1324
  ...target,
1312
- abstain: true
1325
+ verdict: "abstained"
1313
1326
  }, experimentId);
1314
1327
  }
1315
1328
  async archive(target, experimentId) {
@@ -1324,19 +1337,73 @@ var LabelsClient = class {
1324
1337
  }
1325
1338
  async saveHumanAll(updates) {
1326
1339
  assertEveryHumanVerdictNamesAnAssertion(updates);
1327
- return (await this.httpClient.request(HUMAN_LABELS_PATH, { labels: updates })).labels;
1340
+ const verdicts = updates.map((update) => toWireVerdict(update));
1341
+ return (await this.httpClient.request(HUMAN_VERDICTS_PATH, { verdicts })).verdicts.map((outcome) => ({
1342
+ ...outcome,
1343
+ label: outcome.verdict === "pass"
1344
+ }));
1328
1345
  }
1329
1346
  async get(traceId) {
1330
- const [labels] = await this.getAll([traceId]);
1331
- return labels ?? null;
1347
+ const [verdicts] = await this.getAll([traceId]);
1348
+ return verdicts ?? null;
1332
1349
  }
1333
1350
  async getAll(traceIds) {
1334
1351
  if (traceIds.length === 0) return [];
1335
1352
  const query = new URLSearchParams({ traceIds: traceIds.join(",") });
1336
- return (await this.httpClient.get(`${LABELS_PATH}?${query.toString()}`)).labels;
1353
+ return (await this.httpClient.get(`${VERDICTS_PATH}?${query.toString()}`)).verdicts;
1354
+ }
1355
+ async generateEvidence(traceId, assertionId) {
1356
+ return (await this.httpClient.get(verdictEvidencePath(traceId, assertionId))).evidence;
1337
1357
  }
1338
1358
  async generateLabelEvidence(traceId, assertionId) {
1339
- return (await this.httpClient.get(labelEvidencePath(traceId, assertionId))).evidence;
1359
+ return this.generateEvidence(traceId, assertionId);
1360
+ }
1361
+ };
1362
+ const LabelsClient = VerdictsClient;
1363
+ //#endregion
1364
+ //#region src/graders.ts
1365
+ const GRADER_VERDICTS_PATH = "/api/sdk/graderVerdicts";
1366
+ function withDeprecatedGraderFields(row) {
1367
+ return {
1368
+ ...row,
1369
+ label: row.verdict === null ? null : row.verdict === "pass",
1370
+ labelReason: row.reason,
1371
+ labelConfidence: row.confidence
1372
+ };
1373
+ }
1374
+ var GradersClient = class {
1375
+ constructor(httpClient) {
1376
+ this.httpClient = httpClient;
1377
+ }
1378
+ async getVerdicts(params) {
1379
+ const hasTraceIds = params.traceIds !== void 0 && params.traceIds.length > 0;
1380
+ const hasGraderId = params.graderId !== void 0;
1381
+ if (!hasTraceIds && !hasGraderId) throw new require_http.BitfabError("Pass traceIds, graderId, or both: there is nothing to read otherwise.");
1382
+ const query = new URLSearchParams();
1383
+ if (params.traceIds !== void 0 && params.traceIds.length > 0) query.set("traceIds", params.traceIds.join(","));
1384
+ if (params.graderId !== void 0) query.set("graderId", params.graderId);
1385
+ if (params.limit !== void 0) query.set("limit", String(params.limit));
1386
+ return (await this.httpClient.get(`${GRADER_VERDICTS_PATH}?${query.toString()}`)).verdicts.map(withDeprecatedGraderFields);
1387
+ }
1388
+ async saveVerdict(update) {
1389
+ const [outcome] = await this.saveVerdictAll([update]);
1390
+ return outcome;
1391
+ }
1392
+ async saveVerdictAll(updates) {
1393
+ const verdicts = updates.map((update) => toWireVerdict(update));
1394
+ return (await this.httpClient.request(GRADER_VERDICTS_PATH, { verdicts })).verdicts.map((outcome) => ({
1395
+ ...outcome,
1396
+ label: outcome.verdict === "pass"
1397
+ }));
1398
+ }
1399
+ async getLabels(params) {
1400
+ return this.getVerdicts(params);
1401
+ }
1402
+ async saveLabel(update) {
1403
+ return this.saveVerdict(update);
1404
+ }
1405
+ async saveLabelAll(updates) {
1406
+ return this.saveVerdictAll(updates);
1340
1407
  }
1341
1408
  };
1342
1409
  //#endregion
@@ -3465,7 +3532,7 @@ async function runReplaySession(httpClient, fn, session, fullExperimentUrl, maxC
3465
3532
  throw new ReplayError(cause.message, resultItems, experimentId, fullExperimentUrl, cause);
3466
3533
  }
3467
3534
  if (missing.length > 0) try {
3468
- console.error(`Bitfab: server has no persisted trace for ${missing.length} of ${completedCount} completed replay item(s) (experiment ${experimentId}). Their replay token usage is unavailable and they cannot be labeled.`);
3535
+ console.error(`Bitfab: server has no persisted trace for ${missing.length} of ${completedCount} completed replay item(s) (experiment ${experimentId}). Their replay token usage is unavailable and they cannot be given a verdict.`);
3469
3536
  } catch {}
3470
3537
  }
3471
3538
  const result = {
@@ -4820,7 +4887,8 @@ var Bitfab = class {
4820
4887
  this.organizationMembers = new OrganizationMembersClient(this.httpClient);
4821
4888
  this.traces = new TracesClient(this.httpClient);
4822
4889
  this.spans = new SpansClient(this.httpClient);
4823
- this.labels = new LabelsClient(this.httpClient);
4890
+ this.verdicts = new VerdictsClient(this.httpClient);
4891
+ this.labels = this.verdicts;
4824
4892
  this.graders = new GradersClient(this.httpClient);
4825
4893
  this.experiments = new ExperimentsClient(this.httpClient);
4826
4894
  }
@@ -5910,7 +5978,7 @@ var Bitfab = class {
5910
5978
  await runWithSeedContext({ traceId }, async () => target(...args));
5911
5979
  } finally {
5912
5980
  try {
5913
- const { flushTraces } = await Promise.resolve().then(() => require("./http-C9CDbT4U.cjs")).then((n) => n.http_exports);
5981
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-DIz8mEMq.cjs")).then((n) => n.http_exports);
5914
5982
  await flushTraces(3e4);
5915
5983
  } finally {
5916
5984
  unrecorded = activeTraceStates.delete(traceId);
@@ -6098,7 +6166,7 @@ async function seedFromRegistry(registry, pipeline, cases, options = {}) {
6098
6166
  metadata: seedCase.metadata,
6099
6167
  sessionId: seedCase.sessionId
6100
6168
  }));
6101
- const { flushTraces } = await Promise.resolve().then(() => require("./http-C9CDbT4U.cjs")).then((n) => n.http_exports);
6169
+ const { flushTraces } = await Promise.resolve().then(() => require("./http-DIz8mEMq.cjs")).then((n) => n.http_exports);
6102
6170
  await flushTraces(3e4);
6103
6171
  return {
6104
6172
  pipeline,
@@ -6281,6 +6349,12 @@ Object.defineProperty(exports, "TracesClient", {
6281
6349
  return TracesClient;
6282
6350
  }
6283
6351
  });
6352
+ Object.defineProperty(exports, "VerdictsClient", {
6353
+ enumerable: true,
6354
+ get: function() {
6355
+ return VerdictsClient;
6356
+ }
6357
+ });
6284
6358
  Object.defineProperty(exports, "defineReplayRegistry", {
6285
6359
  enumerable: true,
6286
6360
  get: function() {
@@ -6336,4 +6410,4 @@ Object.defineProperty(exports, "serializeReplayResult", {
6336
6410
  }
6337
6411
  });
6338
6412
 
6339
- //# sourceMappingURL=src-CSzXKvXs.cjs.map
6413
+ //# sourceMappingURL=src-rJcHXJEz.cjs.map