braintrust 0.0.182 → 0.0.184

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.
@@ -13,7 +13,7 @@ declare class LazyValue<T> {
13
13
  private value;
14
14
  constructor(callable: () => Promise<T>);
15
15
  get(): Promise<T>;
16
- get hasComputed(): boolean;
16
+ get hasSucceeded(): boolean;
17
17
  }
18
18
 
19
19
  /**
@@ -1274,6 +1274,7 @@ declare class SpanImpl implements Span {
1274
1274
  declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET> extends ObjectFetcher<DatasetRecord<IsLegacyDataset>> {
1275
1275
  private state;
1276
1276
  private readonly lazyMetadata;
1277
+ private readonly __braintrust_dataset_marker;
1277
1278
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectDatasetMetadata>, pinnedVersion?: string, legacy?: IsLegacyDataset);
1278
1279
  get id(): Promise<string>;
1279
1280
  get name(): Promise<string>;
@@ -1343,6 +1344,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
1343
1344
  * @deprecated This function is deprecated. You can simply remove it from your code.
1344
1345
  */
1345
1346
  close(): Promise<string>;
1347
+ static isDataset(data: unknown): data is Dataset;
1346
1348
  }
1347
1349
  type CompiledPromptParams = Omit<NonNullable<PromptData["options"]>["params"], "use_cache"> & {
1348
1350
  model: NonNullable<NonNullable<PromptData["options"]>["model"]>;
package/dist/browser.d.ts CHANGED
@@ -13,7 +13,7 @@ declare class LazyValue<T> {
13
13
  private value;
14
14
  constructor(callable: () => Promise<T>);
15
15
  get(): Promise<T>;
16
- get hasComputed(): boolean;
16
+ get hasSucceeded(): boolean;
17
17
  }
18
18
 
19
19
  /**
@@ -1274,6 +1274,7 @@ declare class SpanImpl implements Span {
1274
1274
  declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET> extends ObjectFetcher<DatasetRecord<IsLegacyDataset>> {
1275
1275
  private state;
1276
1276
  private readonly lazyMetadata;
1277
+ private readonly __braintrust_dataset_marker;
1277
1278
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectDatasetMetadata>, pinnedVersion?: string, legacy?: IsLegacyDataset);
1278
1279
  get id(): Promise<string>;
1279
1280
  get name(): Promise<string>;
@@ -1343,6 +1344,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
1343
1344
  * @deprecated This function is deprecated. You can simply remove it from your code.
1344
1345
  */
1345
1346
  close(): Promise<string>;
1347
+ static isDataset(data: unknown): data is Dataset;
1346
1348
  }
1347
1349
  type CompiledPromptParams = Omit<NonNullable<PromptData["options"]>["params"], "use_cache"> & {
1348
1350
  model: NonNullable<NonNullable<PromptData["options"]>["model"]>;
package/dist/browser.js CHANGED
@@ -148,20 +148,28 @@ function isEmpty(a) {
148
148
  var LazyValue = class {
149
149
  callable;
150
150
  value = {
151
- hasComputed: false
151
+ computedState: "uninitialized"
152
152
  };
153
153
  constructor(callable) {
154
154
  this.callable = callable;
155
155
  }
156
156
  get() {
157
- if (this.value.hasComputed) {
157
+ if (this.value.computedState !== "uninitialized") {
158
158
  return this.value.val;
159
159
  }
160
- this.value = { hasComputed: true, val: this.callable() };
160
+ this.value = {
161
+ computedState: "in_progress",
162
+ val: this.callable().then((x) => {
163
+ this.value.computedState = "succeeded";
164
+ return x;
165
+ })
166
+ };
161
167
  return this.value.val;
162
168
  }
163
- get hasComputed() {
164
- return this.value.hasComputed;
169
+ // If this is true, the caller should be able to obtain the LazyValue without
170
+ // it throwing.
171
+ get hasSucceeded() {
172
+ return this.value.computedState === "succeeded";
165
173
  }
166
174
  };
167
175
 
@@ -1636,7 +1644,7 @@ var Logger = class {
1636
1644
  async export() {
1637
1645
  return new import_core.SpanComponentsV3({
1638
1646
  object_type: this.parentObjectType(),
1639
- ...this.computeMetadataArgs && !this.lazyId.hasComputed ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
1647
+ ...this.computeMetadataArgs && !this.lazyId.hasSucceeded ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
1640
1648
  }).toStr();
1641
1649
  }
1642
1650
  /*
@@ -3371,7 +3379,7 @@ var SpanImpl = class _SpanImpl {
3371
3379
  async export() {
3372
3380
  return new import_core.SpanComponentsV3({
3373
3381
  object_type: this.parentObjectType,
3374
- ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasComputed ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
3382
+ ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasSucceeded ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
3375
3383
  row_id: this.id,
3376
3384
  span_id: this.spanId,
3377
3385
  root_span_id: this.rootSpanId,
@@ -3437,6 +3445,7 @@ var Dataset = class extends ObjectFetcher {
3437
3445
  this.lazyMetadata = lazyMetadata;
3438
3446
  }
3439
3447
  lazyMetadata;
3448
+ __braintrust_dataset_marker = true;
3440
3449
  get id() {
3441
3450
  return (async () => {
3442
3451
  return (await this.lazyMetadata.get()).dataset.id;
@@ -3639,6 +3648,9 @@ var Dataset = class extends ObjectFetcher {
3639
3648
  );
3640
3649
  return this.id;
3641
3650
  }
3651
+ static isDataset(data) {
3652
+ return typeof data === "object" && data !== null && "__braintrust_dataset_marker" in data;
3653
+ }
3642
3654
  };
3643
3655
  function renderMessage(render, message) {
3644
3656
  return {
package/dist/browser.mjs CHANGED
@@ -90,20 +90,28 @@ function isEmpty(a) {
90
90
  var LazyValue = class {
91
91
  callable;
92
92
  value = {
93
- hasComputed: false
93
+ computedState: "uninitialized"
94
94
  };
95
95
  constructor(callable) {
96
96
  this.callable = callable;
97
97
  }
98
98
  get() {
99
- if (this.value.hasComputed) {
99
+ if (this.value.computedState !== "uninitialized") {
100
100
  return this.value.val;
101
101
  }
102
- this.value = { hasComputed: true, val: this.callable() };
102
+ this.value = {
103
+ computedState: "in_progress",
104
+ val: this.callable().then((x) => {
105
+ this.value.computedState = "succeeded";
106
+ return x;
107
+ })
108
+ };
103
109
  return this.value.val;
104
110
  }
105
- get hasComputed() {
106
- return this.value.hasComputed;
111
+ // If this is true, the caller should be able to obtain the LazyValue without
112
+ // it throwing.
113
+ get hasSucceeded() {
114
+ return this.value.computedState === "succeeded";
107
115
  }
108
116
  };
109
117
 
@@ -1584,7 +1592,7 @@ var Logger = class {
1584
1592
  async export() {
1585
1593
  return new SpanComponentsV3({
1586
1594
  object_type: this.parentObjectType(),
1587
- ...this.computeMetadataArgs && !this.lazyId.hasComputed ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
1595
+ ...this.computeMetadataArgs && !this.lazyId.hasSucceeded ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
1588
1596
  }).toStr();
1589
1597
  }
1590
1598
  /*
@@ -3319,7 +3327,7 @@ var SpanImpl = class _SpanImpl {
3319
3327
  async export() {
3320
3328
  return new SpanComponentsV3({
3321
3329
  object_type: this.parentObjectType,
3322
- ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasComputed ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
3330
+ ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasSucceeded ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
3323
3331
  row_id: this.id,
3324
3332
  span_id: this.spanId,
3325
3333
  root_span_id: this.rootSpanId,
@@ -3385,6 +3393,7 @@ var Dataset = class extends ObjectFetcher {
3385
3393
  this.lazyMetadata = lazyMetadata;
3386
3394
  }
3387
3395
  lazyMetadata;
3396
+ __braintrust_dataset_marker = true;
3388
3397
  get id() {
3389
3398
  return (async () => {
3390
3399
  return (await this.lazyMetadata.get()).dataset.id;
@@ -3587,6 +3596,9 @@ var Dataset = class extends ObjectFetcher {
3587
3596
  );
3588
3597
  return this.id;
3589
3598
  }
3599
+ static isDataset(data) {
3600
+ return typeof data === "object" && data !== null && "__braintrust_dataset_marker" in data;
3601
+ }
3590
3602
  };
3591
3603
  function renderMessage(render, message) {
3592
3604
  return {
package/dist/cli.js CHANGED
@@ -1236,7 +1236,7 @@ var require_package = __commonJS({
1236
1236
  "package.json"(exports2, module2) {
1237
1237
  module2.exports = {
1238
1238
  name: "braintrust",
1239
- version: "0.0.182",
1239
+ version: "0.0.184",
1240
1240
  description: "SDK for integrating Braintrust",
1241
1241
  repository: {
1242
1242
  type: "git",
@@ -1311,7 +1311,7 @@ var require_package = __commonJS({
1311
1311
  },
1312
1312
  dependencies: {
1313
1313
  "@ai-sdk/provider": "^1.0.1",
1314
- "@braintrust/core": "0.0.76",
1314
+ "@braintrust/core": "0.0.78",
1315
1315
  "@next/env": "^14.2.3",
1316
1316
  "@vercel/functions": "^1.0.2",
1317
1317
  ai: "^3.2.16",
@@ -1416,20 +1416,28 @@ function isEmpty(a) {
1416
1416
  var LazyValue = class {
1417
1417
  callable;
1418
1418
  value = {
1419
- hasComputed: false
1419
+ computedState: "uninitialized"
1420
1420
  };
1421
1421
  constructor(callable) {
1422
1422
  this.callable = callable;
1423
1423
  }
1424
1424
  get() {
1425
- if (this.value.hasComputed) {
1425
+ if (this.value.computedState !== "uninitialized") {
1426
1426
  return this.value.val;
1427
1427
  }
1428
- this.value = { hasComputed: true, val: this.callable() };
1428
+ this.value = {
1429
+ computedState: "in_progress",
1430
+ val: this.callable().then((x) => {
1431
+ this.value.computedState = "succeeded";
1432
+ return x;
1433
+ })
1434
+ };
1429
1435
  return this.value.val;
1430
1436
  }
1431
- get hasComputed() {
1432
- return this.value.hasComputed;
1437
+ // If this is true, the caller should be able to obtain the LazyValue without
1438
+ // it throwing.
1439
+ get hasSucceeded() {
1440
+ return this.value.computedState === "succeeded";
1433
1441
  }
1434
1442
  };
1435
1443
 
@@ -2884,7 +2892,7 @@ var Logger = class {
2884
2892
  async export() {
2885
2893
  return new import_core.SpanComponentsV3({
2886
2894
  object_type: this.parentObjectType(),
2887
- ...this.computeMetadataArgs && !this.lazyId.hasComputed ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
2895
+ ...this.computeMetadataArgs && !this.lazyId.hasSucceeded ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
2888
2896
  }).toStr();
2889
2897
  }
2890
2898
  /*
@@ -4338,7 +4346,7 @@ var SpanImpl = class _SpanImpl {
4338
4346
  async export() {
4339
4347
  return new import_core.SpanComponentsV3({
4340
4348
  object_type: this.parentObjectType,
4341
- ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasComputed ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
4349
+ ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasSucceeded ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
4342
4350
  row_id: this.id,
4343
4351
  span_id: this.spanId,
4344
4352
  root_span_id: this.rootSpanId,
@@ -4404,6 +4412,7 @@ var Dataset = class extends ObjectFetcher {
4404
4412
  this.lazyMetadata = lazyMetadata;
4405
4413
  }
4406
4414
  lazyMetadata;
4415
+ __braintrust_dataset_marker = true;
4407
4416
  get id() {
4408
4417
  return (async () => {
4409
4418
  return (await this.lazyMetadata.get()).dataset.id;
@@ -4606,6 +4615,9 @@ var Dataset = class extends ObjectFetcher {
4606
4615
  );
4607
4616
  return this.id;
4608
4617
  }
4618
+ static isDataset(data) {
4619
+ return typeof data === "object" && data !== null && "__braintrust_dataset_marker" in data;
4620
+ }
4609
4621
  };
4610
4622
  function renderMessage(render, message) {
4611
4623
  return {
@@ -6099,7 +6111,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
6099
6111
  const q = queue(
6100
6112
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6101
6113
  async (datum) => {
6102
- const eventDataset = experiment ? experiment.dataset : evaluator.data instanceof Dataset ? evaluator.data : void 0;
6114
+ const eventDataset = experiment ? experiment.dataset : Dataset.isDataset(evaluator.data) ? evaluator.data : void 0;
6103
6115
  const baseEvent = {
6104
6116
  name: "eval",
6105
6117
  spanAttributes: {
@@ -7821,7 +7833,7 @@ async function initExperiment2(evaluator, evaluatorData) {
7821
7833
  baseExperimentId: evaluator.baseExperimentId,
7822
7834
  gitMetadataSettings: evaluator.gitMetadataSettings,
7823
7835
  repoInfo: evaluator.repoInfo,
7824
- dataset: data instanceof Dataset ? data : void 0,
7836
+ dataset: Dataset.isDataset(data) ? data : void 0,
7825
7837
  setCurrent: false
7826
7838
  });
7827
7839
  const info = await logger.summarize({ summarizeScores: false });
package/dist/index.d.mts CHANGED
@@ -15,7 +15,7 @@ declare class LazyValue<T> {
15
15
  private value;
16
16
  constructor(callable: () => Promise<T>);
17
17
  get(): Promise<T>;
18
- get hasComputed(): boolean;
18
+ get hasSucceeded(): boolean;
19
19
  }
20
20
 
21
21
  /**
@@ -1276,6 +1276,7 @@ declare class SpanImpl implements Span {
1276
1276
  declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET> extends ObjectFetcher<DatasetRecord<IsLegacyDataset>> {
1277
1277
  private state;
1278
1278
  private readonly lazyMetadata;
1279
+ private readonly __braintrust_dataset_marker;
1279
1280
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectDatasetMetadata>, pinnedVersion?: string, legacy?: IsLegacyDataset);
1280
1281
  get id(): Promise<string>;
1281
1282
  get name(): Promise<string>;
@@ -1345,6 +1346,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
1345
1346
  * @deprecated This function is deprecated. You can simply remove it from your code.
1346
1347
  */
1347
1348
  close(): Promise<string>;
1349
+ static isDataset(data: unknown): data is Dataset;
1348
1350
  }
1349
1351
  type CompiledPromptParams = Omit<NonNullable<PromptData["options"]>["params"], "use_cache"> & {
1350
1352
  model: NonNullable<NonNullable<PromptData["options"]>["model"]>;
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ declare class LazyValue<T> {
15
15
  private value;
16
16
  constructor(callable: () => Promise<T>);
17
17
  get(): Promise<T>;
18
- get hasComputed(): boolean;
18
+ get hasSucceeded(): boolean;
19
19
  }
20
20
 
21
21
  /**
@@ -1276,6 +1276,7 @@ declare class SpanImpl implements Span {
1276
1276
  declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY_DATASET> extends ObjectFetcher<DatasetRecord<IsLegacyDataset>> {
1277
1277
  private state;
1278
1278
  private readonly lazyMetadata;
1279
+ private readonly __braintrust_dataset_marker;
1279
1280
  constructor(state: BraintrustState, lazyMetadata: LazyValue<ProjectDatasetMetadata>, pinnedVersion?: string, legacy?: IsLegacyDataset);
1280
1281
  get id(): Promise<string>;
1281
1282
  get name(): Promise<string>;
@@ -1345,6 +1346,7 @@ declare class Dataset<IsLegacyDataset extends boolean = typeof DEFAULT_IS_LEGACY
1345
1346
  * @deprecated This function is deprecated. You can simply remove it from your code.
1346
1347
  */
1347
1348
  close(): Promise<string>;
1349
+ static isDataset(data: unknown): data is Dataset;
1348
1350
  }
1349
1351
  type CompiledPromptParams = Omit<NonNullable<PromptData["options"]>["params"], "use_cache"> & {
1350
1352
  model: NonNullable<NonNullable<PromptData["options"]>["model"]>;
package/dist/index.js CHANGED
@@ -384,20 +384,28 @@ function isEmpty(a) {
384
384
  var LazyValue = class {
385
385
  callable;
386
386
  value = {
387
- hasComputed: false
387
+ computedState: "uninitialized"
388
388
  };
389
389
  constructor(callable) {
390
390
  this.callable = callable;
391
391
  }
392
392
  get() {
393
- if (this.value.hasComputed) {
393
+ if (this.value.computedState !== "uninitialized") {
394
394
  return this.value.val;
395
395
  }
396
- this.value = { hasComputed: true, val: this.callable() };
396
+ this.value = {
397
+ computedState: "in_progress",
398
+ val: this.callable().then((x) => {
399
+ this.value.computedState = "succeeded";
400
+ return x;
401
+ })
402
+ };
397
403
  return this.value.val;
398
404
  }
399
- get hasComputed() {
400
- return this.value.hasComputed;
405
+ // If this is true, the caller should be able to obtain the LazyValue without
406
+ // it throwing.
407
+ get hasSucceeded() {
408
+ return this.value.computedState === "succeeded";
401
409
  }
402
410
  };
403
411
 
@@ -1872,7 +1880,7 @@ var Logger = class {
1872
1880
  async export() {
1873
1881
  return new import_core.SpanComponentsV3({
1874
1882
  object_type: this.parentObjectType(),
1875
- ...this.computeMetadataArgs && !this.lazyId.hasComputed ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
1883
+ ...this.computeMetadataArgs && !this.lazyId.hasSucceeded ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
1876
1884
  }).toStr();
1877
1885
  }
1878
1886
  /*
@@ -3607,7 +3615,7 @@ var SpanImpl = class _SpanImpl {
3607
3615
  async export() {
3608
3616
  return new import_core.SpanComponentsV3({
3609
3617
  object_type: this.parentObjectType,
3610
- ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasComputed ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
3618
+ ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasSucceeded ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
3611
3619
  row_id: this.id,
3612
3620
  span_id: this.spanId,
3613
3621
  root_span_id: this.rootSpanId,
@@ -3673,6 +3681,7 @@ var Dataset = class extends ObjectFetcher {
3673
3681
  this.lazyMetadata = lazyMetadata;
3674
3682
  }
3675
3683
  lazyMetadata;
3684
+ __braintrust_dataset_marker = true;
3676
3685
  get id() {
3677
3686
  return (async () => {
3678
3687
  return (await this.lazyMetadata.get()).dataset.id;
@@ -3875,6 +3884,9 @@ var Dataset = class extends ObjectFetcher {
3875
3884
  );
3876
3885
  return this.id;
3877
3886
  }
3887
+ static isDataset(data) {
3888
+ return typeof data === "object" && data !== null && "__braintrust_dataset_marker" in data;
3889
+ }
3878
3890
  };
3879
3891
  function renderMessage(render, message) {
3880
3892
  return {
@@ -5485,7 +5497,7 @@ async function Eval(name, evaluator, reporterOrOpts) {
5485
5497
  baseExperimentId: evaluator.baseExperimentId,
5486
5498
  gitMetadataSettings: evaluator.gitMetadataSettings,
5487
5499
  repoInfo: evaluator.repoInfo,
5488
- dataset: data instanceof Dataset ? data : void 0
5500
+ dataset: Dataset.isDataset(data) ? data : void 0
5489
5501
  });
5490
5502
  if (experiment && options.onStart) {
5491
5503
  const summary = await experiment.summarize({ summarizeScores: false });
@@ -5636,7 +5648,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
5636
5648
  const q = queue(
5637
5649
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5638
5650
  async (datum) => {
5639
- const eventDataset = experiment ? experiment.dataset : evaluator.data instanceof Dataset ? evaluator.data : void 0;
5651
+ const eventDataset = experiment ? experiment.dataset : Dataset.isDataset(evaluator.data) ? evaluator.data : void 0;
5640
5652
  const baseEvent = {
5641
5653
  name: "eval",
5642
5654
  spanAttributes: {
@@ -6776,14 +6788,16 @@ function postProcessPrompt(prompt) {
6776
6788
  {
6777
6789
  role: "assistant",
6778
6790
  content: textPart?.text,
6779
- tool_calls: toolCallParts.map((part) => ({
6780
- id: part.toolCallId,
6781
- function: {
6782
- name: part.toolName,
6783
- arguments: JSON.stringify(part.args)
6784
- },
6785
- type: "function"
6786
- }))
6791
+ ...toolCallParts.length > 0 ? {
6792
+ tool_calls: toolCallParts.map((part) => ({
6793
+ id: part.toolCallId,
6794
+ function: {
6795
+ name: part.toolName,
6796
+ arguments: JSON.stringify(part.args)
6797
+ },
6798
+ type: "function"
6799
+ }))
6800
+ } : {}
6787
6801
  }
6788
6802
  ];
6789
6803
  case "user":
package/dist/index.mjs CHANGED
@@ -310,20 +310,28 @@ function isEmpty(a) {
310
310
  var LazyValue = class {
311
311
  callable;
312
312
  value = {
313
- hasComputed: false
313
+ computedState: "uninitialized"
314
314
  };
315
315
  constructor(callable) {
316
316
  this.callable = callable;
317
317
  }
318
318
  get() {
319
- if (this.value.hasComputed) {
319
+ if (this.value.computedState !== "uninitialized") {
320
320
  return this.value.val;
321
321
  }
322
- this.value = { hasComputed: true, val: this.callable() };
322
+ this.value = {
323
+ computedState: "in_progress",
324
+ val: this.callable().then((x) => {
325
+ this.value.computedState = "succeeded";
326
+ return x;
327
+ })
328
+ };
323
329
  return this.value.val;
324
330
  }
325
- get hasComputed() {
326
- return this.value.hasComputed;
331
+ // If this is true, the caller should be able to obtain the LazyValue without
332
+ // it throwing.
333
+ get hasSucceeded() {
334
+ return this.value.computedState === "succeeded";
327
335
  }
328
336
  };
329
337
 
@@ -1804,7 +1812,7 @@ var Logger = class {
1804
1812
  async export() {
1805
1813
  return new SpanComponentsV3({
1806
1814
  object_type: this.parentObjectType(),
1807
- ...this.computeMetadataArgs && !this.lazyId.hasComputed ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
1815
+ ...this.computeMetadataArgs && !this.lazyId.hasSucceeded ? { compute_object_metadata_args: this.computeMetadataArgs } : { object_id: await this.lazyId.get() }
1808
1816
  }).toStr();
1809
1817
  }
1810
1818
  /*
@@ -3539,7 +3547,7 @@ var SpanImpl = class _SpanImpl {
3539
3547
  async export() {
3540
3548
  return new SpanComponentsV3({
3541
3549
  object_type: this.parentObjectType,
3542
- ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasComputed ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
3550
+ ...this.parentComputeObjectMetadataArgs && !this.parentObjectId.hasSucceeded ? { compute_object_metadata_args: this.parentComputeObjectMetadataArgs } : { object_id: await this.parentObjectId.get() },
3543
3551
  row_id: this.id,
3544
3552
  span_id: this.spanId,
3545
3553
  root_span_id: this.rootSpanId,
@@ -3605,6 +3613,7 @@ var Dataset = class extends ObjectFetcher {
3605
3613
  this.lazyMetadata = lazyMetadata;
3606
3614
  }
3607
3615
  lazyMetadata;
3616
+ __braintrust_dataset_marker = true;
3608
3617
  get id() {
3609
3618
  return (async () => {
3610
3619
  return (await this.lazyMetadata.get()).dataset.id;
@@ -3807,6 +3816,9 @@ var Dataset = class extends ObjectFetcher {
3807
3816
  );
3808
3817
  return this.id;
3809
3818
  }
3819
+ static isDataset(data) {
3820
+ return typeof data === "object" && data !== null && "__braintrust_dataset_marker" in data;
3821
+ }
3810
3822
  };
3811
3823
  function renderMessage(render, message) {
3812
3824
  return {
@@ -5419,7 +5431,7 @@ async function Eval(name, evaluator, reporterOrOpts) {
5419
5431
  baseExperimentId: evaluator.baseExperimentId,
5420
5432
  gitMetadataSettings: evaluator.gitMetadataSettings,
5421
5433
  repoInfo: evaluator.repoInfo,
5422
- dataset: data instanceof Dataset ? data : void 0
5434
+ dataset: Dataset.isDataset(data) ? data : void 0
5423
5435
  });
5424
5436
  if (experiment && options.onStart) {
5425
5437
  const summary = await experiment.summarize({ summarizeScores: false });
@@ -5570,7 +5582,7 @@ async function runEvaluatorInternal(experiment, evaluator, progressReporter, fil
5570
5582
  const q = queue(
5571
5583
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5572
5584
  async (datum) => {
5573
- const eventDataset = experiment ? experiment.dataset : evaluator.data instanceof Dataset ? evaluator.data : void 0;
5585
+ const eventDataset = experiment ? experiment.dataset : Dataset.isDataset(evaluator.data) ? evaluator.data : void 0;
5574
5586
  const baseEvent = {
5575
5587
  name: "eval",
5576
5588
  spanAttributes: {
@@ -6712,14 +6724,16 @@ function postProcessPrompt(prompt) {
6712
6724
  {
6713
6725
  role: "assistant",
6714
6726
  content: textPart?.text,
6715
- tool_calls: toolCallParts.map((part) => ({
6716
- id: part.toolCallId,
6717
- function: {
6718
- name: part.toolName,
6719
- arguments: JSON.stringify(part.args)
6720
- },
6721
- type: "function"
6722
- }))
6727
+ ...toolCallParts.length > 0 ? {
6728
+ tool_calls: toolCallParts.map((part) => ({
6729
+ id: part.toolCallId,
6730
+ function: {
6731
+ name: part.toolName,
6732
+ arguments: JSON.stringify(part.args)
6733
+ },
6734
+ type: "function"
6735
+ }))
6736
+ } : {}
6723
6737
  }
6724
6738
  ];
6725
6739
  case "user":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braintrust",
3
- "version": "0.0.182",
3
+ "version": "0.0.184",
4
4
  "description": "SDK for integrating Braintrust",
5
5
  "repository": {
6
6
  "type": "git",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@ai-sdk/provider": "^1.0.1",
78
- "@braintrust/core": "0.0.76",
78
+ "@braintrust/core": "0.0.78",
79
79
  "@next/env": "^14.2.3",
80
80
  "@vercel/functions": "^1.0.2",
81
81
  "ai": "^3.2.16",
package/turbo.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "extends": ["//"],
3
- "pipeline": {
3
+ "tasks": {
4
4
  "build": {
5
5
  "outputs": ["**/dist/**"]
6
6
  },