braintrust 3.30.0 → 3.31.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.
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: "3.30.0",
1239
+ version: "3.31.0",
1240
1240
  description: "SDK for integrating Braintrust",
1241
1241
  repository: {
1242
1242
  type: "git",
@@ -5356,6 +5356,7 @@ var ProjectSettings = import_v36.z.union([
5356
5356
  ]),
5357
5357
  disable_realtime_queries: import_v36.z.union([import_v36.z.boolean(), import_v36.z.null()]),
5358
5358
  monitor_charts_use_metrics_start: import_v36.z.union([import_v36.z.boolean(), import_v36.z.null()]),
5359
+ blind_reviews: import_v36.z.union([import_v36.z.boolean(), import_v36.z.null()]),
5359
5360
  default_preprocessor: NullableSavedFunctionId
5360
5361
  }).partial(),
5361
5362
  import_v36.z.null()
@@ -5417,6 +5418,7 @@ var WindowedAutomationConfig = import_v36.z.object({
5417
5418
  auto_approve_tools: import_v36.z.array(import_v36.z.string().min(1)).optional().default([]),
5418
5419
  harness: import_v36.z.enum(["native", "codex", "claude-code"]).optional(),
5419
5420
  model: import_v36.z.string().min(1).optional(),
5421
+ endpoint_name: import_v36.z.string().min(1).optional(),
5420
5422
  reasoning_effort: import_v36.z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).optional()
5421
5423
  }).optional(),
5422
5424
  actions: import_v36.z.array(
@@ -7208,7 +7210,7 @@ var INSTRUMENTATION_NAMES = {
7208
7210
  var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
7209
7211
  "braintrust.spanInstrumentationName"
7210
7212
  );
7211
- var SDK_VERSION = true ? "3.30.0" : "0.0.0";
7213
+ var SDK_VERSION = true ? "3.31.0" : "0.0.0";
7212
7214
  function withSpanInstrumentationName(args, instrumentationName) {
7213
7215
  return {
7214
7216
  ...args,
@@ -14769,19 +14771,29 @@ function buildSpanScores(results) {
14769
14771
  function _internalPrepareEvaluatorScore(scoreValue, name) {
14770
14772
  if (scoreValue === null) return { results: null };
14771
14773
  if (Array.isArray(scoreValue)) {
14774
+ const names = /* @__PURE__ */ new Set();
14772
14775
  for (const score of scoreValue) {
14773
14776
  if (!(typeof score === "object" && !isEmpty2(score))) {
14774
14777
  throw new Error(
14775
14778
  `When returning an array of scores, each score must be a non-empty object. Got: ${JSON.stringify(score)}`
14776
14779
  );
14777
14780
  }
14781
+ if (typeof score.name !== "string") {
14782
+ throw new Error(
14783
+ `When returning an array of scores, each score must have a name. Got: ${JSON.stringify(score)}`
14784
+ );
14785
+ }
14786
+ if (names.has(score.name)) {
14787
+ throw new Error(`Duplicate score name '${score.name}' in score array`);
14788
+ }
14789
+ names.add(score.name);
14778
14790
  }
14779
14791
  }
14780
14792
  let results;
14781
14793
  if (Array.isArray(scoreValue)) {
14782
14794
  results = scoreValue;
14783
14795
  } else if (typeof scoreValue === "object" && !isEmpty2(scoreValue)) {
14784
- results = [scoreValue];
14796
+ results = [{ ...scoreValue, name: scoreValue.name ?? name }];
14785
14797
  } else {
14786
14798
  results = [{ name, score: scoreValue }];
14787
14799
  }
@@ -23562,6 +23574,12 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
23562
23574
  if (!activeEntry) {
23563
23575
  return result;
23564
23576
  }
23577
+ const executionOptions = args[1];
23578
+ const toolCallId = isObject(executionOptions) ? executionOptions.toolCallId : void 0;
23579
+ const toolInput = {
23580
+ input: serializeToolExecutionInput(args),
23581
+ ...typeof toolCallId === "string" ? { metadata: { toolCallId } } : {}
23582
+ };
23565
23583
  if (isAsyncGenerator2(result)) {
23566
23584
  return (async function* () {
23567
23585
  const span = activeEntry.parentSpan.startSpan(
@@ -23575,7 +23593,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
23575
23593
  INSTRUMENTATION_NAMES.AI_SDK
23576
23594
  )
23577
23595
  );
23578
- span.log({ input: serializeToolExecutionInput(args) });
23596
+ span.log(toolInput);
23579
23597
  try {
23580
23598
  let lastValue;
23581
23599
  for await (const value of result) {
@@ -23593,7 +23611,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
23593
23611
  }
23594
23612
  return activeEntry.parentSpan.traced(
23595
23613
  async (span) => {
23596
- span.log({ input: serializeToolExecutionInput(args) });
23614
+ span.log(toolInput);
23597
23615
  const awaitedResult = await result;
23598
23616
  span.log({ output: awaitedResult });
23599
23617
  return awaitedResult;
@@ -37715,14 +37733,17 @@ function getMetricsFromResponse(response) {
37715
37733
  if (!isRecord(usageMetadata)) {
37716
37734
  continue;
37717
37735
  }
37718
- const inputTokenDetails = usageMetadata.input_token_details;
37736
+ const inputTokenDetails = isRecord(usageMetadata.input_token_details) ? usageMetadata.input_token_details : {};
37719
37737
  const outputTokenDetails = usageMetadata.output_token_details;
37720
37738
  return normalizeTokenMetrics({
37721
37739
  total_tokens: usageMetadata.total_tokens,
37722
37740
  prompt_tokens: usageMetadata.input_tokens,
37723
37741
  completion_tokens: usageMetadata.output_tokens,
37724
- prompt_cache_creation_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_creation : void 0,
37725
- prompt_cached_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_read : void 0,
37742
+ // Prefer TTL-specific cache writes over the aggregate when available.
37743
+ prompt_cache_creation_tokens: inputTokenDetails.ephemeral_5m_input_tokens == null && inputTokenDetails.ephemeral_1h_input_tokens == null ? inputTokenDetails.cache_creation : void 0,
37744
+ prompt_cache_creation_5m_tokens: inputTokenDetails.ephemeral_5m_input_tokens,
37745
+ prompt_cache_creation_1h_tokens: inputTokenDetails.ephemeral_1h_input_tokens,
37746
+ prompt_cached_tokens: inputTokenDetails.cache_read,
37726
37747
  completion_reasoning_tokens: isRecord(outputTokenDetails) ? outputTokenDetails.reasoning : void 0
37727
37748
  });
37728
37749
  }
@@ -4031,6 +4031,7 @@ var ProjectSettings = import_v36.z.union([
4031
4031
  ]),
4032
4032
  disable_realtime_queries: import_v36.z.union([import_v36.z.boolean(), import_v36.z.null()]),
4033
4033
  monitor_charts_use_metrics_start: import_v36.z.union([import_v36.z.boolean(), import_v36.z.null()]),
4034
+ blind_reviews: import_v36.z.union([import_v36.z.boolean(), import_v36.z.null()]),
4034
4035
  default_preprocessor: NullableSavedFunctionId
4035
4036
  }).partial(),
4036
4037
  import_v36.z.null()
@@ -4092,6 +4093,7 @@ var WindowedAutomationConfig = import_v36.z.object({
4092
4093
  auto_approve_tools: import_v36.z.array(import_v36.z.string().min(1)).optional().default([]),
4093
4094
  harness: import_v36.z.enum(["native", "codex", "claude-code"]).optional(),
4094
4095
  model: import_v36.z.string().min(1).optional(),
4096
+ endpoint_name: import_v36.z.string().min(1).optional(),
4095
4097
  reasoning_effort: import_v36.z.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).optional()
4096
4098
  }).optional(),
4097
4099
  actions: import_v36.z.array(
@@ -5883,7 +5885,7 @@ var INSTRUMENTATION_NAMES = {
5883
5885
  var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
5884
5886
  "braintrust.spanInstrumentationName"
5885
5887
  );
5886
- var SDK_VERSION = true ? "3.30.0" : "0.0.0";
5888
+ var SDK_VERSION = true ? "3.31.0" : "0.0.0";
5887
5889
  function withSpanInstrumentationName(args, instrumentationName) {
5888
5890
  return {
5889
5891
  ...args,
@@ -20034,6 +20036,12 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
20034
20036
  if (!activeEntry) {
20035
20037
  return result;
20036
20038
  }
20039
+ const executionOptions = args[1];
20040
+ const toolCallId = isObject(executionOptions) ? executionOptions.toolCallId : void 0;
20041
+ const toolInput = {
20042
+ input: serializeToolExecutionInput(args),
20043
+ ...typeof toolCallId === "string" ? { metadata: { toolCallId } } : {}
20044
+ };
20037
20045
  if (isAsyncGenerator(result)) {
20038
20046
  return (async function* () {
20039
20047
  const span = activeEntry.parentSpan.startSpan(
@@ -20047,7 +20055,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
20047
20055
  INSTRUMENTATION_NAMES.AI_SDK
20048
20056
  )
20049
20057
  );
20050
- span.log({ input: serializeToolExecutionInput(args) });
20058
+ span.log(toolInput);
20051
20059
  try {
20052
20060
  let lastValue;
20053
20061
  for await (const value of result) {
@@ -20065,7 +20073,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
20065
20073
  }
20066
20074
  return activeEntry.parentSpan.traced(
20067
20075
  async (span) => {
20068
- span.log({ input: serializeToolExecutionInput(args) });
20076
+ span.log(toolInput);
20069
20077
  const awaitedResult = await result;
20070
20078
  span.log({ output: awaitedResult });
20071
20079
  return awaitedResult;
@@ -34187,14 +34195,17 @@ function getMetricsFromResponse(response) {
34187
34195
  if (!isRecord(usageMetadata)) {
34188
34196
  continue;
34189
34197
  }
34190
- const inputTokenDetails = usageMetadata.input_token_details;
34198
+ const inputTokenDetails = isRecord(usageMetadata.input_token_details) ? usageMetadata.input_token_details : {};
34191
34199
  const outputTokenDetails = usageMetadata.output_token_details;
34192
34200
  return normalizeTokenMetrics({
34193
34201
  total_tokens: usageMetadata.total_tokens,
34194
34202
  prompt_tokens: usageMetadata.input_tokens,
34195
34203
  completion_tokens: usageMetadata.output_tokens,
34196
- prompt_cache_creation_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_creation : void 0,
34197
- prompt_cached_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_read : void 0,
34204
+ // Prefer TTL-specific cache writes over the aggregate when available.
34205
+ prompt_cache_creation_tokens: inputTokenDetails.ephemeral_5m_input_tokens == null && inputTokenDetails.ephemeral_1h_input_tokens == null ? inputTokenDetails.cache_creation : void 0,
34206
+ prompt_cache_creation_5m_tokens: inputTokenDetails.ephemeral_5m_input_tokens,
34207
+ prompt_cache_creation_1h_tokens: inputTokenDetails.ephemeral_1h_input_tokens,
34208
+ prompt_cached_tokens: inputTokenDetails.cache_read,
34198
34209
  completion_reasoning_tokens: isRecord(outputTokenDetails) ? outputTokenDetails.reasoning : void 0
34199
34210
  });
34200
34211
  }
@@ -45206,8 +45217,8 @@ function normalizeScores(result) {
45206
45217
  (s) => s !== null && s !== void 0 && typeof s === "object" && isScore(s)
45207
45218
  );
45208
45219
  }
45209
- if (typeof result === "object" && result !== null && isScore(result)) {
45210
- return [result];
45220
+ if (typeof result === "object" && result !== null && "score" in result) {
45221
+ return [{ ...result, name: result.name ?? "score" }];
45211
45222
  }
45212
45223
  return [];
45213
45224
  }
@@ -47790,19 +47801,29 @@ function buildSpanScores(results) {
47790
47801
  function _internalPrepareEvaluatorScore(scoreValue, name) {
47791
47802
  if (scoreValue === null) return { results: null };
47792
47803
  if (Array.isArray(scoreValue)) {
47804
+ const names = /* @__PURE__ */ new Set();
47793
47805
  for (const score of scoreValue) {
47794
47806
  if (!(typeof score === "object" && !isEmpty2(score))) {
47795
47807
  throw new Error(
47796
47808
  `When returning an array of scores, each score must be a non-empty object. Got: ${JSON.stringify(score)}`
47797
47809
  );
47798
47810
  }
47811
+ if (typeof score.name !== "string") {
47812
+ throw new Error(
47813
+ `When returning an array of scores, each score must have a name. Got: ${JSON.stringify(score)}`
47814
+ );
47815
+ }
47816
+ if (names.has(score.name)) {
47817
+ throw new Error(`Duplicate score name '${score.name}' in score array`);
47818
+ }
47819
+ names.add(score.name);
47799
47820
  }
47800
47821
  }
47801
47822
  let results;
47802
47823
  if (Array.isArray(scoreValue)) {
47803
47824
  results = scoreValue;
47804
47825
  } else if (typeof scoreValue === "object" && !isEmpty2(scoreValue)) {
47805
- results = [scoreValue];
47826
+ results = [{ ...scoreValue, name: scoreValue.name ?? name }];
47806
47827
  } else {
47807
47828
  results = [{ name, score: scoreValue }];
47808
47829
  }
@@ -3818,6 +3818,7 @@ var ProjectSettings = z6.union([
3818
3818
  ]),
3819
3819
  disable_realtime_queries: z6.union([z6.boolean(), z6.null()]),
3820
3820
  monitor_charts_use_metrics_start: z6.union([z6.boolean(), z6.null()]),
3821
+ blind_reviews: z6.union([z6.boolean(), z6.null()]),
3821
3822
  default_preprocessor: NullableSavedFunctionId
3822
3823
  }).partial(),
3823
3824
  z6.null()
@@ -3879,6 +3880,7 @@ var WindowedAutomationConfig = z6.object({
3879
3880
  auto_approve_tools: z6.array(z6.string().min(1)).optional().default([]),
3880
3881
  harness: z6.enum(["native", "codex", "claude-code"]).optional(),
3881
3882
  model: z6.string().min(1).optional(),
3883
+ endpoint_name: z6.string().min(1).optional(),
3882
3884
  reasoning_effort: z6.enum(["none", "minimal", "low", "medium", "high", "xhigh", "max"]).optional()
3883
3885
  }).optional(),
3884
3886
  actions: z6.array(
@@ -5672,7 +5674,7 @@ var INSTRUMENTATION_NAMES = {
5672
5674
  var INTERNAL_SPAN_INSTRUMENTATION_NAME = /* @__PURE__ */ Symbol.for(
5673
5675
  "braintrust.spanInstrumentationName"
5674
5676
  );
5675
- var SDK_VERSION = true ? "3.30.0" : "0.0.0";
5677
+ var SDK_VERSION = true ? "3.31.0" : "0.0.0";
5676
5678
  function withSpanInstrumentationName(args, instrumentationName) {
5677
5679
  return {
5678
5680
  ...args,
@@ -19823,6 +19825,12 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
19823
19825
  if (!activeEntry) {
19824
19826
  return result;
19825
19827
  }
19828
+ const executionOptions = args[1];
19829
+ const toolCallId = isObject(executionOptions) ? executionOptions.toolCallId : void 0;
19830
+ const toolInput = {
19831
+ input: serializeToolExecutionInput(args),
19832
+ ...typeof toolCallId === "string" ? { metadata: { toolCallId } } : {}
19833
+ };
19826
19834
  if (isAsyncGenerator(result)) {
19827
19835
  return (async function* () {
19828
19836
  const span = activeEntry.parentSpan.startSpan(
@@ -19836,7 +19844,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
19836
19844
  INSTRUMENTATION_NAMES.AI_SDK
19837
19845
  )
19838
19846
  );
19839
- span.log({ input: serializeToolExecutionInput(args) });
19847
+ span.log(toolInput);
19840
19848
  try {
19841
19849
  let lastValue;
19842
19850
  for await (const value of result) {
@@ -19854,7 +19862,7 @@ function prepareAISDKChildTracing(params, self, parentSpan, denyOutputPaths, aiS
19854
19862
  }
19855
19863
  return activeEntry.parentSpan.traced(
19856
19864
  async (span) => {
19857
- span.log({ input: serializeToolExecutionInput(args) });
19865
+ span.log(toolInput);
19858
19866
  const awaitedResult = await result;
19859
19867
  span.log({ output: awaitedResult });
19860
19868
  return awaitedResult;
@@ -33976,14 +33984,17 @@ function getMetricsFromResponse(response) {
33976
33984
  if (!isRecord(usageMetadata)) {
33977
33985
  continue;
33978
33986
  }
33979
- const inputTokenDetails = usageMetadata.input_token_details;
33987
+ const inputTokenDetails = isRecord(usageMetadata.input_token_details) ? usageMetadata.input_token_details : {};
33980
33988
  const outputTokenDetails = usageMetadata.output_token_details;
33981
33989
  return normalizeTokenMetrics({
33982
33990
  total_tokens: usageMetadata.total_tokens,
33983
33991
  prompt_tokens: usageMetadata.input_tokens,
33984
33992
  completion_tokens: usageMetadata.output_tokens,
33985
- prompt_cache_creation_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_creation : void 0,
33986
- prompt_cached_tokens: isRecord(inputTokenDetails) ? inputTokenDetails.cache_read : void 0,
33993
+ // Prefer TTL-specific cache writes over the aggregate when available.
33994
+ prompt_cache_creation_tokens: inputTokenDetails.ephemeral_5m_input_tokens == null && inputTokenDetails.ephemeral_1h_input_tokens == null ? inputTokenDetails.cache_creation : void 0,
33995
+ prompt_cache_creation_5m_tokens: inputTokenDetails.ephemeral_5m_input_tokens,
33996
+ prompt_cache_creation_1h_tokens: inputTokenDetails.ephemeral_1h_input_tokens,
33997
+ prompt_cached_tokens: inputTokenDetails.cache_read,
33987
33998
  completion_reasoning_tokens: isRecord(outputTokenDetails) ? outputTokenDetails.reasoning : void 0
33988
33999
  });
33989
34000
  }
@@ -44995,8 +45006,8 @@ function normalizeScores(result) {
44995
45006
  (s) => s !== null && s !== void 0 && typeof s === "object" && isScore(s)
44996
45007
  );
44997
45008
  }
44998
- if (typeof result === "object" && result !== null && isScore(result)) {
44999
- return [result];
45009
+ if (typeof result === "object" && result !== null && "score" in result) {
45010
+ return [{ ...result, name: result.name ?? "score" }];
45000
45011
  }
45001
45012
  return [];
45002
45013
  }
@@ -47579,19 +47590,29 @@ function buildSpanScores(results) {
47579
47590
  function _internalPrepareEvaluatorScore(scoreValue, name) {
47580
47591
  if (scoreValue === null) return { results: null };
47581
47592
  if (Array.isArray(scoreValue)) {
47593
+ const names = /* @__PURE__ */ new Set();
47582
47594
  for (const score of scoreValue) {
47583
47595
  if (!(typeof score === "object" && !isEmpty2(score))) {
47584
47596
  throw new Error(
47585
47597
  `When returning an array of scores, each score must be a non-empty object. Got: ${JSON.stringify(score)}`
47586
47598
  );
47587
47599
  }
47600
+ if (typeof score.name !== "string") {
47601
+ throw new Error(
47602
+ `When returning an array of scores, each score must have a name. Got: ${JSON.stringify(score)}`
47603
+ );
47604
+ }
47605
+ if (names.has(score.name)) {
47606
+ throw new Error(`Duplicate score name '${score.name}' in score array`);
47607
+ }
47608
+ names.add(score.name);
47588
47609
  }
47589
47610
  }
47590
47611
  let results;
47591
47612
  if (Array.isArray(scoreValue)) {
47592
47613
  results = scoreValue;
47593
47614
  } else if (typeof scoreValue === "object" && !isEmpty2(scoreValue)) {
47594
- results = [scoreValue];
47615
+ results = [{ ...scoreValue, name: scoreValue.name ?? name }];
47595
47616
  } else {
47596
47617
  results = [{ name, score: scoreValue }];
47597
47618
  }