braintrust 2.2.1-rc.0 → 2.2.2

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.
@@ -360,7 +360,7 @@ declare class SpanComponentsV4 {
360
360
  private static fromJsonObj;
361
361
  }
362
362
 
363
- declare const spanTypeAttributeValues: readonly ["llm", "score", "function", "eval", "task", "tool", "automation", "facet", "preprocessor", "classifier"];
363
+ declare const spanTypeAttributeValues: readonly ["llm", "score", "function", "eval", "task", "tool", "automation", "facet", "preprocessor", "classifier", "review"];
364
364
  type SpanType = (typeof spanTypeAttributeValues)[number];
365
365
 
366
366
  declare const AnyModelParams: z.ZodObject<{
@@ -360,7 +360,7 @@ declare class SpanComponentsV4 {
360
360
  private static fromJsonObj;
361
361
  }
362
362
 
363
- declare const spanTypeAttributeValues: readonly ["llm", "score", "function", "eval", "task", "tool", "automation", "facet", "preprocessor", "classifier"];
363
+ declare const spanTypeAttributeValues: readonly ["llm", "score", "function", "eval", "task", "tool", "automation", "facet", "preprocessor", "classifier", "review"];
364
364
  type SpanType = (typeof spanTypeAttributeValues)[number];
365
365
 
366
366
  declare const AnyModelParams: z.ZodObject<{
package/dev/dist/index.js CHANGED
@@ -2159,7 +2159,8 @@ var SpanType = _v3.z.union([
2159
2159
  "automation",
2160
2160
  "facet",
2161
2161
  "preprocessor",
2162
- "classifier"
2162
+ "classifier",
2163
+ "review"
2163
2164
  ]),
2164
2165
  _v3.z.null()
2165
2166
  ]);
@@ -5273,12 +5274,19 @@ function updateSpanImpl({
5273
5274
  parentObjectType,
5274
5275
  parentObjectId,
5275
5276
  id,
5277
+ root_span_id,
5278
+ span_id,
5276
5279
  event
5277
5280
  }) {
5281
+ if (isEmpty2(root_span_id) !== isEmpty2(span_id)) {
5282
+ throw new Error("both root_span_id and span_id must be set, or neither");
5283
+ }
5284
+ const hasExplicitSpanIds = root_span_id !== void 0 && span_id !== void 0;
5278
5285
  const updateEvent = deepCopyEvent(
5279
5286
  validateAndSanitizeExperimentLogPartialArgs({
5287
+ ...event,
5280
5288
  id,
5281
- ...event
5289
+ ...hasExplicitSpanIds ? { root_span_id, span_id } : {}
5282
5290
  })
5283
5291
  );
5284
5292
  const parentIds = async () => new SpanComponentsV3({
@@ -5601,7 +5609,7 @@ var Logger = (_class7 = class {
5601
5609
  * @param event The event data to update the span with. Must include `id`. See {@link Experiment.log} for a full list of valid fields.
5602
5610
  */
5603
5611
  updateSpan(event) {
5604
- const { id, ...eventRest } = event;
5612
+ const { id, root_span_id, span_id, ...eventRest } = event;
5605
5613
  if (!id) {
5606
5614
  throw new Error("Span id is required to update a span");
5607
5615
  }
@@ -5610,6 +5618,8 @@ var Logger = (_class7 = class {
5610
5618
  parentObjectType: this.parentObjectType(),
5611
5619
  parentObjectId: this.lazyId,
5612
5620
  id,
5621
+ root_span_id,
5622
+ span_id,
5613
5623
  event: eventRest
5614
5624
  });
5615
5625
  }
@@ -7293,7 +7303,7 @@ View complete results in Braintrust or run experiment.summarize() again.`
7293
7303
  * @param event The event data to update the span with. Must include `id`. See {@link Experiment.log} for a full list of valid fields.
7294
7304
  */
7295
7305
  updateSpan(event) {
7296
- const { id, ...eventRest } = event;
7306
+ const { id, root_span_id, span_id, ...eventRest } = event;
7297
7307
  if (!id) {
7298
7308
  throw new Error("Span id is required to update a span");
7299
7309
  }
@@ -7302,6 +7312,8 @@ View complete results in Braintrust or run experiment.summarize() again.`
7302
7312
  parentObjectType: this.parentObjectType(),
7303
7313
  parentObjectId: this.lazyId,
7304
7314
  id,
7315
+ root_span_id,
7316
+ span_id,
7305
7317
  event: eventRest
7306
7318
  });
7307
7319
  }
@@ -8461,7 +8473,7 @@ function configureNode() {
8461
8473
  var _express = require('express'); var _express2 = _interopRequireDefault(_express);
8462
8474
  var _cors = require('cors'); var _cors2 = _interopRequireDefault(_cors);
8463
8475
 
8464
- // ../node_modules/.pnpm/async@3.2.5/node_modules/async/dist/async.mjs
8476
+ // ../node_modules/async/dist/async.mjs
8465
8477
  function initialParams(fn) {
8466
8478
  return function(...args) {
8467
8479
  var callback = args.pop();
@@ -8586,7 +8598,6 @@ function isArrayLike(value) {
8586
8598
  return value && typeof value.length === "number" && value.length >= 0 && value.length % 1 === 0;
8587
8599
  }
8588
8600
  var breakLoop = {};
8589
- var breakLoop$1 = breakLoop;
8590
8601
  function once(fn) {
8591
8602
  function wrapper(...args) {
8592
8603
  if (fn === null) return;
@@ -8678,7 +8689,7 @@ function asyncEachOfLimit(generator, limit, iteratee, callback) {
8678
8689
  canceled = true;
8679
8690
  return;
8680
8691
  }
8681
- if (result === breakLoop$1 || done && running <= 0) {
8692
+ if (result === breakLoop || done && running <= 0) {
8682
8693
  done = true;
8683
8694
  return callback(null);
8684
8695
  }
@@ -8721,7 +8732,7 @@ var eachOfLimit$2 = (limit) => {
8721
8732
  } else if (err === false) {
8722
8733
  done = true;
8723
8734
  canceled = true;
8724
- } else if (value === breakLoop$1 || done && running <= 0) {
8735
+ } else if (value === breakLoop || done && running <= 0) {
8725
8736
  done = true;
8726
8737
  return callback(null);
8727
8738
  } else if (!looping) {
@@ -8764,7 +8775,7 @@ function eachOfArrayLike(coll, iteratee, callback) {
8764
8775
  if (canceled === true) return;
8765
8776
  if (err) {
8766
8777
  callback(err);
8767
- } else if (++completed === length || value === breakLoop$1) {
8778
+ } else if (++completed === length || value === breakLoop) {
8768
8779
  callback(null);
8769
8780
  }
8770
8781
  }
@@ -9160,7 +9171,7 @@ function _createTester(check, getResult) {
9160
9171
  if (check(result) && !testResult) {
9161
9172
  testPassed = true;
9162
9173
  testResult = getResult(true, value);
9163
- return callback(null, breakLoop$1);
9174
+ return callback(null, breakLoop);
9164
9175
  }
9165
9176
  callback();
9166
9177
  });
@@ -11343,6 +11354,7 @@ var CodeParameters = class {
11343
11354
  this.metadata = opts.metadata;
11344
11355
  }
11345
11356
  async toFunctionDefinition(projectNameToId) {
11357
+ const schema = serializeEvalParameterstoParametersSchema(this.schema);
11346
11358
  return {
11347
11359
  project_id: await projectNameToId.resolve(this.project),
11348
11360
  name: this.name,
@@ -11351,8 +11363,8 @@ var CodeParameters = class {
11351
11363
  function_type: "parameters",
11352
11364
  function_data: {
11353
11365
  type: "parameters",
11354
- data: {},
11355
- __schema: serializeEvalParameterstoParametersSchema(this.schema)
11366
+ data: getDefaultDataFromParametersSchema(schema),
11367
+ __schema: schema
11356
11368
  },
11357
11369
  if_exists: this.ifExists,
11358
11370
  metadata: this.metadata
@@ -11434,6 +11446,16 @@ function serializeEvalParameterstoParametersSchema(parameters) {
11434
11446
  additionalProperties: true
11435
11447
  };
11436
11448
  }
11449
+ function getDefaultDataFromParametersSchema(schema) {
11450
+ return Object.fromEntries(
11451
+ Object.entries(schema.properties).flatMap(([name, value]) => {
11452
+ if (!("default" in value)) {
11453
+ return [];
11454
+ }
11455
+ return [[name, value.default]];
11456
+ })
11457
+ );
11458
+ }
11437
11459
  function serializeRemoteEvalParametersContainer(parameters) {
11438
11460
  if (RemoteEvalParameters.isParameters(parameters)) {
11439
11461
  return {
@@ -1,10 +1,10 @@
1
1
  // src/node.ts
2
- import { AsyncLocalStorage } from "async_hooks";
3
- import * as path from "path";
4
- import * as fs from "fs/promises";
5
- import * as os from "os";
6
- import * as fsSync from "fs";
7
- import * as crypto from "crypto";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ import * as path from "node:path";
4
+ import * as fs from "node:fs/promises";
5
+ import * as os from "node:os";
6
+ import * as fsSync from "node:fs";
7
+ import * as crypto from "node:crypto";
8
8
 
9
9
  // src/isomorph.ts
10
10
  var DefaultAsyncLocalStorage = class {
@@ -2159,7 +2159,8 @@ var SpanType = z6.union([
2159
2159
  "automation",
2160
2160
  "facet",
2161
2161
  "preprocessor",
2162
- "classifier"
2162
+ "classifier",
2163
+ "review"
2163
2164
  ]),
2164
2165
  z6.null()
2165
2166
  ]);
@@ -5273,12 +5274,19 @@ function updateSpanImpl({
5273
5274
  parentObjectType,
5274
5275
  parentObjectId,
5275
5276
  id,
5277
+ root_span_id,
5278
+ span_id,
5276
5279
  event
5277
5280
  }) {
5281
+ if (isEmpty2(root_span_id) !== isEmpty2(span_id)) {
5282
+ throw new Error("both root_span_id and span_id must be set, or neither");
5283
+ }
5284
+ const hasExplicitSpanIds = root_span_id !== void 0 && span_id !== void 0;
5278
5285
  const updateEvent = deepCopyEvent(
5279
5286
  validateAndSanitizeExperimentLogPartialArgs({
5287
+ ...event,
5280
5288
  id,
5281
- ...event
5289
+ ...hasExplicitSpanIds ? { root_span_id, span_id } : {}
5282
5290
  })
5283
5291
  );
5284
5292
  const parentIds = async () => new SpanComponentsV3({
@@ -5601,7 +5609,7 @@ var Logger = class {
5601
5609
  * @param event The event data to update the span with. Must include `id`. See {@link Experiment.log} for a full list of valid fields.
5602
5610
  */
5603
5611
  updateSpan(event) {
5604
- const { id, ...eventRest } = event;
5612
+ const { id, root_span_id, span_id, ...eventRest } = event;
5605
5613
  if (!id) {
5606
5614
  throw new Error("Span id is required to update a span");
5607
5615
  }
@@ -5610,6 +5618,8 @@ var Logger = class {
5610
5618
  parentObjectType: this.parentObjectType(),
5611
5619
  parentObjectId: this.lazyId,
5612
5620
  id,
5621
+ root_span_id,
5622
+ span_id,
5613
5623
  event: eventRest
5614
5624
  });
5615
5625
  }
@@ -7293,7 +7303,7 @@ View complete results in Braintrust or run experiment.summarize() again.`
7293
7303
  * @param event The event data to update the span with. Must include `id`. See {@link Experiment.log} for a full list of valid fields.
7294
7304
  */
7295
7305
  updateSpan(event) {
7296
- const { id, ...eventRest } = event;
7306
+ const { id, root_span_id, span_id, ...eventRest } = event;
7297
7307
  if (!id) {
7298
7308
  throw new Error("Span id is required to update a span");
7299
7309
  }
@@ -7302,6 +7312,8 @@ View complete results in Braintrust or run experiment.summarize() again.`
7302
7312
  parentObjectType: this.parentObjectType(),
7303
7313
  parentObjectId: this.lazyId,
7304
7314
  id,
7315
+ root_span_id,
7316
+ span_id,
7305
7317
  event: eventRest
7306
7318
  });
7307
7319
  }
@@ -8461,7 +8473,7 @@ function configureNode() {
8461
8473
  import express from "express";
8462
8474
  import cors from "cors";
8463
8475
 
8464
- // ../node_modules/.pnpm/async@3.2.5/node_modules/async/dist/async.mjs
8476
+ // ../node_modules/async/dist/async.mjs
8465
8477
  function initialParams(fn) {
8466
8478
  return function(...args) {
8467
8479
  var callback = args.pop();
@@ -8586,7 +8598,6 @@ function isArrayLike(value) {
8586
8598
  return value && typeof value.length === "number" && value.length >= 0 && value.length % 1 === 0;
8587
8599
  }
8588
8600
  var breakLoop = {};
8589
- var breakLoop$1 = breakLoop;
8590
8601
  function once(fn) {
8591
8602
  function wrapper(...args) {
8592
8603
  if (fn === null) return;
@@ -8678,7 +8689,7 @@ function asyncEachOfLimit(generator, limit, iteratee, callback) {
8678
8689
  canceled = true;
8679
8690
  return;
8680
8691
  }
8681
- if (result === breakLoop$1 || done && running <= 0) {
8692
+ if (result === breakLoop || done && running <= 0) {
8682
8693
  done = true;
8683
8694
  return callback(null);
8684
8695
  }
@@ -8721,7 +8732,7 @@ var eachOfLimit$2 = (limit) => {
8721
8732
  } else if (err === false) {
8722
8733
  done = true;
8723
8734
  canceled = true;
8724
- } else if (value === breakLoop$1 || done && running <= 0) {
8735
+ } else if (value === breakLoop || done && running <= 0) {
8725
8736
  done = true;
8726
8737
  return callback(null);
8727
8738
  } else if (!looping) {
@@ -8764,7 +8775,7 @@ function eachOfArrayLike(coll, iteratee, callback) {
8764
8775
  if (canceled === true) return;
8765
8776
  if (err) {
8766
8777
  callback(err);
8767
- } else if (++completed === length || value === breakLoop$1) {
8778
+ } else if (++completed === length || value === breakLoop) {
8768
8779
  callback(null);
8769
8780
  }
8770
8781
  }
@@ -9160,7 +9171,7 @@ function _createTester(check, getResult) {
9160
9171
  if (check(result) && !testResult) {
9161
9172
  testPassed = true;
9162
9173
  testResult = getResult(true, value);
9163
- return callback(null, breakLoop$1);
9174
+ return callback(null, breakLoop);
9164
9175
  }
9165
9176
  callback();
9166
9177
  });
@@ -11343,6 +11354,7 @@ var CodeParameters = class {
11343
11354
  this.metadata = opts.metadata;
11344
11355
  }
11345
11356
  async toFunctionDefinition(projectNameToId) {
11357
+ const schema = serializeEvalParameterstoParametersSchema(this.schema);
11346
11358
  return {
11347
11359
  project_id: await projectNameToId.resolve(this.project),
11348
11360
  name: this.name,
@@ -11351,8 +11363,8 @@ var CodeParameters = class {
11351
11363
  function_type: "parameters",
11352
11364
  function_data: {
11353
11365
  type: "parameters",
11354
- data: {},
11355
- __schema: serializeEvalParameterstoParametersSchema(this.schema)
11366
+ data: getDefaultDataFromParametersSchema(schema),
11367
+ __schema: schema
11356
11368
  },
11357
11369
  if_exists: this.ifExists,
11358
11370
  metadata: this.metadata
@@ -11434,6 +11446,16 @@ function serializeEvalParameterstoParametersSchema(parameters) {
11434
11446
  additionalProperties: true
11435
11447
  };
11436
11448
  }
11449
+ function getDefaultDataFromParametersSchema(schema) {
11450
+ return Object.fromEntries(
11451
+ Object.entries(schema.properties).flatMap(([name, value]) => {
11452
+ if (!("default" in value)) {
11453
+ return [];
11454
+ }
11455
+ return [[name, value.default]];
11456
+ })
11457
+ );
11458
+ }
11437
11459
  function serializeRemoteEvalParametersContainer(parameters) {
11438
11460
  if (RemoteEvalParameters.isParameters(parameters)) {
11439
11461
  return {