braintrust 2.2.0 → 2.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braintrust",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "SDK for integrating Braintrust",
5
5
  "repository": {
6
6
  "type": "git",
@@ -119,6 +119,7 @@
119
119
  "@next/env": "^14.2.3",
120
120
  "@types/nunjucks": "^3.2.6",
121
121
  "@vercel/functions": "^1.0.2",
122
+ "ajv": "^8.17.1",
122
123
  "argparse": "^2.0.1",
123
124
  "boxen": "^8.0.1",
124
125
  "chalk": "^4.1.2",
@@ -14,6 +14,7 @@ type Source = (typeof VALID_SOURCES)[number];
14
14
  declare const PARENT_ID_FIELD = "_parent_id";
15
15
  declare const ASYNC_SCORING_CONTROL_FIELD = "_async_scoring_control";
16
16
  declare const SKIP_ASYNC_SCORING_FIELD = "_skip_async_scoring";
17
+ declare const OBJECT_ID_KEYS: readonly ["experiment_id", "dataset_id", "prompt_session_id", "project_id", "log_id", "function_data"];
17
18
  type TransactionId = string;
18
19
 
19
20
  declare const AsyncScoringControl: z.ZodUnion<[z.ZodObject<{
@@ -5043,13 +5044,13 @@ type MergeRowSkipFieldObj = {
5043
5044
  declare function mergeRowBatch<T extends {
5044
5045
  id: string;
5045
5046
  [IS_MERGE_FIELD]?: boolean | null;
5046
- [PARENT_ID_FIELD]?: string | null;
5047
- } & MergeRowSkipFieldObj>(rows: T[]): T[][];
5048
- declare function batchItems(args: {
5049
- items: string[][];
5047
+ } & MergeRowSkipFieldObj>(rows: T[]): T[];
5048
+ declare function batchItems<T>(args: {
5049
+ items: T[];
5050
5050
  batchMaxNumItems?: number;
5051
5051
  batchMaxNumBytes?: number;
5052
- }): string[][][];
5052
+ getByteSize: (item: T) => number;
5053
+ }): T[][];
5053
5054
 
5054
5055
  interface Score {
5055
5056
  name: string;
@@ -5289,7 +5290,7 @@ declare function parseParent(parent: InvokeFunctionType["parent"]): string | und
5289
5290
  */
5290
5291
  declare function makeScorerPropagatedEvent(parent: string | undefined): Record<string, unknown>;
5291
5292
 
5292
- declare const spanTypeAttributeValues: readonly ["llm", "score", "function", "eval", "task", "tool", "automation", "facet", "preprocessor", "classifier"];
5293
+ declare const spanTypeAttributeValues: readonly ["llm", "score", "function", "eval", "task", "tool", "automation", "facet", "preprocessor", "classifier", "review"];
5293
5294
  declare enum SpanTypeAttribute {
5294
5295
  LLM = "llm",
5295
5296
  SCORE = "score",
@@ -5300,7 +5301,8 @@ declare enum SpanTypeAttribute {
5300
5301
  AUTOMATION = "automation",
5301
5302
  FACET = "facet",
5302
5303
  PREPROCESSOR = "preprocessor",
5303
- CLASSIFIER = "classifier"
5304
+ CLASSIFIER = "classifier",
5305
+ REVIEW = "review"
5304
5306
  }
5305
5307
  type SpanType = (typeof spanTypeAttributeValues)[number];
5306
5308
  declare const spanPurposeAttributeValues: readonly ["scorer"];
@@ -5325,4 +5327,4 @@ declare function base64ToUint8Array(base64: string): Uint8Array;
5325
5327
  declare function uint8ArrayToString(uint8Array: Uint8Array): string;
5326
5328
  declare function stringToUint8Array(str: string): Uint8Array;
5327
5329
 
5328
- export { ARRAY_DELETE_FIELD, ASYNC_SCORING_CONTROL_FIELD, AUDIT_METADATA_FIELD, AUDIT_SOURCE_FIELD, type AnyDatasetRecord, BT_CURSOR_HEADER, BT_FOUND_EXISTING_HEADER, BT_IMPERSONATE_USER, BT_PARENT, type BackgroundLogEvent, CREATED_FIELD, type CommentEvent, DEFAULT_IS_LEGACY_DATASET, type DatasetEvent, type DatasetRecord, type ExperimentEvent, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, ExtraFieldsError, ID_FIELD, IS_MERGE_FIELD, type IdField, type InputField, type LogCommentFullArgs, type LogFeedbackFullArgs, type LoggingEvent, MERGE_PATHS_FIELD, OBJECT_DELETE_FIELD, type OtherExperimentLogFields, PARENT_ID_FIELD, type ParentExperimentIds, type ParentPlaygroundLogIds, type ParentProjectLogIds, type PlaygroundLogEvent, SKIP_ASYNC_SCORING_FIELD, type SanitizedExperimentLogPartialArgs, type Score, type Scorer, type ScorerArgs, type Source, SpanComponentsV1, SpanComponentsV2, SpanComponentsV3, type SpanComponentsV3Data, SpanComponentsV4, type SpanComponentsV4Data, SpanObjectTypeV1, SpanObjectTypeV2, SpanObjectTypeV3, type SpanPurpose, SpanRowIdsV1, SpanRowIdsV2, type SpanType, SpanTypeAttribute, TRANSACTION_ID_FIELD, type TransactionId, VALID_SOURCES, _urljoin, base64ToUint8Array, batchItems, camelToSnakeCase, capitalize, concatUint8Arrays, constructJsonArray, deterministicReplacer, ensureDatasetRecord, ensureLegacyDatasetRecord, ensureNewDatasetRecord, forEachMissingKey, getObjValueByPath, getRecordKeys, isArray, isEmpty, isNumber, isObject, isObjectOrArray, loadPrettyXact, lowercase, makeScorerPropagatedEvent, mapAt, mapSetDefault, mapSetNotPresent, mergeDicts, mergeDictsWithPaths, mergeGitMetadataSettings, mergeRowBatch, notEmpty, objectNullish, parseNoStrip, parseParent, prettifyXact, recordAt, recordFind, recordSetDefault, resolveParentHeader, snakeToCamelCase, snakeToTitleCase, spanComponentsV3Schema, spanComponentsV4Schema, spanObjectTypeV3EnumSchema, spanObjectTypeV3ToString, spanObjectTypeV3ToTypedString, spanPurposeAttributeValues, spanTypeAttributeValues, stringToUint8Array, uint8ArrayToBase64, uint8ArrayToString };
5330
+ export { ARRAY_DELETE_FIELD, ASYNC_SCORING_CONTROL_FIELD, AUDIT_METADATA_FIELD, AUDIT_SOURCE_FIELD, type AnyDatasetRecord, BT_CURSOR_HEADER, BT_FOUND_EXISTING_HEADER, BT_IMPERSONATE_USER, BT_PARENT, type BackgroundLogEvent, CREATED_FIELD, type CommentEvent, DEFAULT_IS_LEGACY_DATASET, type DatasetEvent, type DatasetRecord, type ExperimentEvent, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, ExtraFieldsError, ID_FIELD, IS_MERGE_FIELD, type IdField, type InputField, type LogCommentFullArgs, type LogFeedbackFullArgs, type LoggingEvent, MERGE_PATHS_FIELD, OBJECT_DELETE_FIELD, OBJECT_ID_KEYS, type OtherExperimentLogFields, PARENT_ID_FIELD, type ParentExperimentIds, type ParentPlaygroundLogIds, type ParentProjectLogIds, type PlaygroundLogEvent, SKIP_ASYNC_SCORING_FIELD, type SanitizedExperimentLogPartialArgs, type Score, type Scorer, type ScorerArgs, type Source, SpanComponentsV1, SpanComponentsV2, SpanComponentsV3, type SpanComponentsV3Data, SpanComponentsV4, type SpanComponentsV4Data, SpanObjectTypeV1, SpanObjectTypeV2, SpanObjectTypeV3, type SpanPurpose, SpanRowIdsV1, SpanRowIdsV2, type SpanType, SpanTypeAttribute, TRANSACTION_ID_FIELD, type TransactionId, VALID_SOURCES, _urljoin, base64ToUint8Array, batchItems, camelToSnakeCase, capitalize, concatUint8Arrays, constructJsonArray, deterministicReplacer, ensureDatasetRecord, ensureLegacyDatasetRecord, ensureNewDatasetRecord, forEachMissingKey, getObjValueByPath, getRecordKeys, isArray, isEmpty, isNumber, isObject, isObjectOrArray, loadPrettyXact, lowercase, makeScorerPropagatedEvent, mapAt, mapSetDefault, mapSetNotPresent, mergeDicts, mergeDictsWithPaths, mergeGitMetadataSettings, mergeRowBatch, notEmpty, objectNullish, parseNoStrip, parseParent, prettifyXact, recordAt, recordFind, recordSetDefault, resolveParentHeader, snakeToCamelCase, snakeToTitleCase, spanComponentsV3Schema, spanComponentsV4Schema, spanObjectTypeV3EnumSchema, spanObjectTypeV3ToString, spanObjectTypeV3ToTypedString, spanPurposeAttributeValues, spanTypeAttributeValues, stringToUint8Array, uint8ArrayToBase64, uint8ArrayToString };
@@ -14,6 +14,7 @@ type Source = (typeof VALID_SOURCES)[number];
14
14
  declare const PARENT_ID_FIELD = "_parent_id";
15
15
  declare const ASYNC_SCORING_CONTROL_FIELD = "_async_scoring_control";
16
16
  declare const SKIP_ASYNC_SCORING_FIELD = "_skip_async_scoring";
17
+ declare const OBJECT_ID_KEYS: readonly ["experiment_id", "dataset_id", "prompt_session_id", "project_id", "log_id", "function_data"];
17
18
  type TransactionId = string;
18
19
 
19
20
  declare const AsyncScoringControl: z.ZodUnion<[z.ZodObject<{
@@ -5043,13 +5044,13 @@ type MergeRowSkipFieldObj = {
5043
5044
  declare function mergeRowBatch<T extends {
5044
5045
  id: string;
5045
5046
  [IS_MERGE_FIELD]?: boolean | null;
5046
- [PARENT_ID_FIELD]?: string | null;
5047
- } & MergeRowSkipFieldObj>(rows: T[]): T[][];
5048
- declare function batchItems(args: {
5049
- items: string[][];
5047
+ } & MergeRowSkipFieldObj>(rows: T[]): T[];
5048
+ declare function batchItems<T>(args: {
5049
+ items: T[];
5050
5050
  batchMaxNumItems?: number;
5051
5051
  batchMaxNumBytes?: number;
5052
- }): string[][][];
5052
+ getByteSize: (item: T) => number;
5053
+ }): T[][];
5053
5054
 
5054
5055
  interface Score {
5055
5056
  name: string;
@@ -5289,7 +5290,7 @@ declare function parseParent(parent: InvokeFunctionType["parent"]): string | und
5289
5290
  */
5290
5291
  declare function makeScorerPropagatedEvent(parent: string | undefined): Record<string, unknown>;
5291
5292
 
5292
- declare const spanTypeAttributeValues: readonly ["llm", "score", "function", "eval", "task", "tool", "automation", "facet", "preprocessor", "classifier"];
5293
+ declare const spanTypeAttributeValues: readonly ["llm", "score", "function", "eval", "task", "tool", "automation", "facet", "preprocessor", "classifier", "review"];
5293
5294
  declare enum SpanTypeAttribute {
5294
5295
  LLM = "llm",
5295
5296
  SCORE = "score",
@@ -5300,7 +5301,8 @@ declare enum SpanTypeAttribute {
5300
5301
  AUTOMATION = "automation",
5301
5302
  FACET = "facet",
5302
5303
  PREPROCESSOR = "preprocessor",
5303
- CLASSIFIER = "classifier"
5304
+ CLASSIFIER = "classifier",
5305
+ REVIEW = "review"
5304
5306
  }
5305
5307
  type SpanType = (typeof spanTypeAttributeValues)[number];
5306
5308
  declare const spanPurposeAttributeValues: readonly ["scorer"];
@@ -5325,4 +5327,4 @@ declare function base64ToUint8Array(base64: string): Uint8Array;
5325
5327
  declare function uint8ArrayToString(uint8Array: Uint8Array): string;
5326
5328
  declare function stringToUint8Array(str: string): Uint8Array;
5327
5329
 
5328
- export { ARRAY_DELETE_FIELD, ASYNC_SCORING_CONTROL_FIELD, AUDIT_METADATA_FIELD, AUDIT_SOURCE_FIELD, type AnyDatasetRecord, BT_CURSOR_HEADER, BT_FOUND_EXISTING_HEADER, BT_IMPERSONATE_USER, BT_PARENT, type BackgroundLogEvent, CREATED_FIELD, type CommentEvent, DEFAULT_IS_LEGACY_DATASET, type DatasetEvent, type DatasetRecord, type ExperimentEvent, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, ExtraFieldsError, ID_FIELD, IS_MERGE_FIELD, type IdField, type InputField, type LogCommentFullArgs, type LogFeedbackFullArgs, type LoggingEvent, MERGE_PATHS_FIELD, OBJECT_DELETE_FIELD, type OtherExperimentLogFields, PARENT_ID_FIELD, type ParentExperimentIds, type ParentPlaygroundLogIds, type ParentProjectLogIds, type PlaygroundLogEvent, SKIP_ASYNC_SCORING_FIELD, type SanitizedExperimentLogPartialArgs, type Score, type Scorer, type ScorerArgs, type Source, SpanComponentsV1, SpanComponentsV2, SpanComponentsV3, type SpanComponentsV3Data, SpanComponentsV4, type SpanComponentsV4Data, SpanObjectTypeV1, SpanObjectTypeV2, SpanObjectTypeV3, type SpanPurpose, SpanRowIdsV1, SpanRowIdsV2, type SpanType, SpanTypeAttribute, TRANSACTION_ID_FIELD, type TransactionId, VALID_SOURCES, _urljoin, base64ToUint8Array, batchItems, camelToSnakeCase, capitalize, concatUint8Arrays, constructJsonArray, deterministicReplacer, ensureDatasetRecord, ensureLegacyDatasetRecord, ensureNewDatasetRecord, forEachMissingKey, getObjValueByPath, getRecordKeys, isArray, isEmpty, isNumber, isObject, isObjectOrArray, loadPrettyXact, lowercase, makeScorerPropagatedEvent, mapAt, mapSetDefault, mapSetNotPresent, mergeDicts, mergeDictsWithPaths, mergeGitMetadataSettings, mergeRowBatch, notEmpty, objectNullish, parseNoStrip, parseParent, prettifyXact, recordAt, recordFind, recordSetDefault, resolveParentHeader, snakeToCamelCase, snakeToTitleCase, spanComponentsV3Schema, spanComponentsV4Schema, spanObjectTypeV3EnumSchema, spanObjectTypeV3ToString, spanObjectTypeV3ToTypedString, spanPurposeAttributeValues, spanTypeAttributeValues, stringToUint8Array, uint8ArrayToBase64, uint8ArrayToString };
5330
+ export { ARRAY_DELETE_FIELD, ASYNC_SCORING_CONTROL_FIELD, AUDIT_METADATA_FIELD, AUDIT_SOURCE_FIELD, type AnyDatasetRecord, BT_CURSOR_HEADER, BT_FOUND_EXISTING_HEADER, BT_IMPERSONATE_USER, BT_PARENT, type BackgroundLogEvent, CREATED_FIELD, type CommentEvent, DEFAULT_IS_LEGACY_DATASET, type DatasetEvent, type DatasetRecord, type ExperimentEvent, type ExperimentLogFullArgs, type ExperimentLogPartialArgs, ExtraFieldsError, ID_FIELD, IS_MERGE_FIELD, type IdField, type InputField, type LogCommentFullArgs, type LogFeedbackFullArgs, type LoggingEvent, MERGE_PATHS_FIELD, OBJECT_DELETE_FIELD, OBJECT_ID_KEYS, type OtherExperimentLogFields, PARENT_ID_FIELD, type ParentExperimentIds, type ParentPlaygroundLogIds, type ParentProjectLogIds, type PlaygroundLogEvent, SKIP_ASYNC_SCORING_FIELD, type SanitizedExperimentLogPartialArgs, type Score, type Scorer, type ScorerArgs, type Source, SpanComponentsV1, SpanComponentsV2, SpanComponentsV3, type SpanComponentsV3Data, SpanComponentsV4, type SpanComponentsV4Data, SpanObjectTypeV1, SpanObjectTypeV2, SpanObjectTypeV3, type SpanPurpose, SpanRowIdsV1, SpanRowIdsV2, type SpanType, SpanTypeAttribute, TRANSACTION_ID_FIELD, type TransactionId, VALID_SOURCES, _urljoin, base64ToUint8Array, batchItems, camelToSnakeCase, capitalize, concatUint8Arrays, constructJsonArray, deterministicReplacer, ensureDatasetRecord, ensureLegacyDatasetRecord, ensureNewDatasetRecord, forEachMissingKey, getObjValueByPath, getRecordKeys, isArray, isEmpty, isNumber, isObject, isObjectOrArray, loadPrettyXact, lowercase, makeScorerPropagatedEvent, mapAt, mapSetDefault, mapSetNotPresent, mergeDicts, mergeDictsWithPaths, mergeGitMetadataSettings, mergeRowBatch, notEmpty, objectNullish, parseNoStrip, parseParent, prettifyXact, recordAt, recordFind, recordSetDefault, resolveParentHeader, snakeToCamelCase, snakeToTitleCase, spanComponentsV3Schema, spanComponentsV4Schema, spanObjectTypeV3EnumSchema, spanObjectTypeV3ToString, spanObjectTypeV3ToTypedString, spanPurposeAttributeValues, spanTypeAttributeValues, stringToUint8Array, uint8ArrayToBase64, uint8ArrayToString };
@@ -12,6 +12,14 @@ var VALID_SOURCES = ["app", "api", "external"];
12
12
  var PARENT_ID_FIELD = "_parent_id";
13
13
  var ASYNC_SCORING_CONTROL_FIELD = "_async_scoring_control";
14
14
  var SKIP_ASYNC_SCORING_FIELD = "_skip_async_scoring";
15
+ var OBJECT_ID_KEYS = [
16
+ "experiment_id",
17
+ "dataset_id",
18
+ "prompt_session_id",
19
+ "project_id",
20
+ "log_id",
21
+ "function_data"
22
+ ];
15
23
 
16
24
  // util/span_identifier_v3.ts
17
25
  var _uuid = require('uuid'); var uuid3 = _interopRequireWildcard(_uuid); var uuid2 = _interopRequireWildcard(_uuid); var uuid = _interopRequireWildcard(_uuid);
@@ -810,72 +818,8 @@ function getObjValueByPath(row, path) {
810
818
  return curr;
811
819
  }
812
820
 
813
- // util/graph_util.ts
814
- function depthFirstSearch(args) {
815
- const { graph, firstVisitF, lastVisitF } = args;
816
- for (const vs of graph.values()) {
817
- for (const v of vs.values()) {
818
- if (!graph.has(v)) {
819
- throw new Error(`Outgoing vertex ${v} must be a key in the graph`);
820
- }
821
- }
822
- }
823
- const firstVisitedVertices = /* @__PURE__ */ new Set();
824
- const visitationOrder = _nullishCoalesce(args.visitationOrder, () => ( [...graph.keys()]));
825
- const events = visitationOrder.map((vertex) => ({ eventType: "first", vertex, extras: {} })).reverse();
826
- while (events.length) {
827
- const { eventType, vertex, extras } = events.pop();
828
- if (eventType === "last") {
829
- _optionalChain([lastVisitF, 'optionalCall', _8 => _8(vertex)]);
830
- continue;
831
- }
832
- if (firstVisitedVertices.has(vertex)) {
833
- continue;
834
- }
835
- firstVisitedVertices.add(vertex);
836
- _optionalChain([firstVisitF, 'optionalCall', _9 => _9(vertex, { parentVertex: extras.parentVertex })]);
837
- events.push({ eventType: "last", vertex, extras: {} });
838
- mapAt(graph, vertex).forEach((child) => {
839
- events.push({
840
- eventType: "first",
841
- vertex: child,
842
- extras: { parentVertex: vertex }
843
- });
844
- });
845
- }
846
- }
847
- function undirectedConnectedComponents(graph) {
848
- const directedGraph = new Map(
849
- [...graph.vertices].map((v) => [v, /* @__PURE__ */ new Set()])
850
- );
851
- for (const [i, j] of graph.edges) {
852
- mapAt(directedGraph, i).add(j);
853
- mapAt(directedGraph, j).add(i);
854
- }
855
- let labelCounter = 0;
856
- const vertexLabels = /* @__PURE__ */ new Map();
857
- const firstVisitF = (vertex, args) => {
858
- const label = _optionalChain([args, 'optionalAccess', _10 => _10.parentVertex]) !== void 0 ? mapAt(vertexLabels, _optionalChain([args, 'optionalAccess', _11 => _11.parentVertex])) : labelCounter++;
859
- vertexLabels.set(vertex, label);
860
- };
861
- depthFirstSearch({ graph: directedGraph, firstVisitF });
862
- const output = Array.from({ length: labelCounter }).map(() => []);
863
- for (const [vertex, label] of vertexLabels.entries()) {
864
- output[label].push(vertex);
865
- }
866
- return output;
867
- }
868
- function topologicalSort(graph, visitationOrder) {
869
- const reverseOrdering = [];
870
- const lastVisitF = (vertex) => {
871
- reverseOrdering.push(vertex);
872
- };
873
- depthFirstSearch({ graph, lastVisitF, visitationOrder });
874
- return reverseOrdering.reverse();
875
- }
876
-
877
821
  // util/merge_row_batch.ts
878
- function generateMergedRowKey(row, useParentIdForId) {
822
+ function generateMergedRowKey(row) {
879
823
  return JSON.stringify(
880
824
  [
881
825
  "org_id",
@@ -884,7 +828,7 @@ function generateMergedRowKey(row, useParentIdForId) {
884
828
  "dataset_id",
885
829
  "prompt_session_id",
886
830
  "log_id",
887
- _nullishCoalesce(useParentIdForId, () => ( false)) ? PARENT_ID_FIELD : "id"
831
+ "id"
888
832
  ].map((k) => row[k])
889
833
  );
890
834
  }
@@ -938,96 +882,34 @@ function mergeRowBatch(rows) {
938
882
  rowGroups.set(key, row);
939
883
  }
940
884
  }
941
- const merged = [...rowGroups.values()];
942
- const rowToLabel = new Map(
943
- merged.map((r, i) => [generateMergedRowKey(r), i])
944
- );
945
- const graph = new Map(
946
- Array.from({ length: merged.length }).map((_, i) => [i, /* @__PURE__ */ new Set()])
947
- );
948
- merged.forEach((r, i) => {
949
- const parentId = r[PARENT_ID_FIELD];
950
- if (!parentId) {
951
- return;
952
- }
953
- const parentRowKey = generateMergedRowKey(
954
- r,
955
- true
956
- /* useParentIdForId */
957
- );
958
- const parentLabel = rowToLabel.get(parentRowKey);
959
- if (parentLabel !== void 0) {
960
- mapAt(graph, parentLabel).add(i);
961
- }
962
- });
963
- const connectedComponents = undirectedConnectedComponents({
964
- vertices: new Set(graph.keys()),
965
- edges: new Set(
966
- [...graph.entries()].flatMap(
967
- ([k, vs]) => [...vs].map((v) => {
968
- const ret = [k, v];
969
- return ret;
970
- })
971
- )
972
- )
973
- });
974
- const buckets = connectedComponents.map(
975
- (cc) => topologicalSort(
976
- graph,
977
- cc
978
- /* visitationOrder */
979
- )
980
- );
981
- return buckets.map((bucket) => bucket.map((i) => merged[i]));
885
+ return [...rowGroups.values()];
982
886
  }
983
887
  function batchItems(args) {
984
- let { items } = args;
888
+ const { items } = args;
985
889
  const batchMaxNumItems = _nullishCoalesce(args.batchMaxNumItems, () => ( Number.POSITIVE_INFINITY));
986
890
  const batchMaxNumBytes = _nullishCoalesce(args.batchMaxNumBytes, () => ( Number.POSITIVE_INFINITY));
891
+ const getByteSize = args.getByteSize;
987
892
  const output = [];
988
- let nextItems = [];
989
- let batchSet = [];
990
893
  let batch = [];
991
894
  let batchLen = 0;
992
895
  function addToBatch(item) {
993
896
  batch.push(item);
994
- batchLen += item.length;
897
+ batchLen += getByteSize(item);
995
898
  }
996
899
  function flushBatch() {
997
- batchSet.push(batch);
900
+ output.push(batch);
998
901
  batch = [];
999
902
  batchLen = 0;
1000
903
  }
1001
- while (items.length) {
1002
- for (const bucket of items) {
1003
- let i = 0;
1004
- for (const item of bucket) {
1005
- if (batch.length === 0 || item.length + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems) {
1006
- addToBatch(item);
1007
- } else if (i === 0) {
1008
- flushBatch();
1009
- addToBatch(item);
1010
- } else {
1011
- break;
1012
- }
1013
- ++i;
1014
- }
1015
- if (i < bucket.length) {
1016
- nextItems.push(bucket.slice(i));
1017
- }
1018
- if (batchLen >= batchMaxNumBytes || batch.length > batchMaxNumItems) {
1019
- flushBatch();
1020
- }
1021
- }
1022
- if (batch.length) {
904
+ for (const item of items) {
905
+ const itemSize = getByteSize(item);
906
+ if (batch.length > 0 && !(itemSize + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems)) {
1023
907
  flushBatch();
1024
908
  }
1025
- if (batchSet.length) {
1026
- output.push(batchSet);
1027
- batchSet = [];
1028
- }
1029
- items = nextItems;
1030
- nextItems = [];
909
+ addToBatch(item);
910
+ }
911
+ if (batch.length > 0) {
912
+ flushBatch();
1031
913
  }
1032
914
  return output;
1033
915
  }
@@ -1344,7 +1226,8 @@ var spanTypeAttributeValues = [
1344
1226
  "automation",
1345
1227
  "facet",
1346
1228
  "preprocessor",
1347
- "classifier"
1229
+ "classifier",
1230
+ "review"
1348
1231
  ];
1349
1232
  var SpanTypeAttribute = /* @__PURE__ */ ((SpanTypeAttribute2) => {
1350
1233
  SpanTypeAttribute2["LLM"] = "llm";
@@ -1357,6 +1240,7 @@ var SpanTypeAttribute = /* @__PURE__ */ ((SpanTypeAttribute2) => {
1357
1240
  SpanTypeAttribute2["FACET"] = "facet";
1358
1241
  SpanTypeAttribute2["PREPROCESSOR"] = "preprocessor";
1359
1242
  SpanTypeAttribute2["CLASSIFIER"] = "classifier";
1243
+ SpanTypeAttribute2["REVIEW"] = "review";
1360
1244
  return SpanTypeAttribute2;
1361
1245
  })(SpanTypeAttribute || {});
1362
1246
  var spanPurposeAttributeValues = ["scorer"];
@@ -1510,4 +1394,5 @@ function objectNullish(object) {
1510
1394
 
1511
1395
 
1512
1396
 
1513
- exports.ARRAY_DELETE_FIELD = ARRAY_DELETE_FIELD; exports.ASYNC_SCORING_CONTROL_FIELD = ASYNC_SCORING_CONTROL_FIELD; exports.AUDIT_METADATA_FIELD = AUDIT_METADATA_FIELD; exports.AUDIT_SOURCE_FIELD = AUDIT_SOURCE_FIELD; exports.BT_CURSOR_HEADER = BT_CURSOR_HEADER; exports.BT_FOUND_EXISTING_HEADER = BT_FOUND_EXISTING_HEADER; exports.BT_IMPERSONATE_USER = BT_IMPERSONATE_USER; exports.BT_PARENT = BT_PARENT; exports.CREATED_FIELD = CREATED_FIELD; exports.DEFAULT_IS_LEGACY_DATASET = DEFAULT_IS_LEGACY_DATASET; exports.ExtraFieldsError = ExtraFieldsError; exports.ID_FIELD = ID_FIELD; exports.IS_MERGE_FIELD = IS_MERGE_FIELD; exports.MERGE_PATHS_FIELD = MERGE_PATHS_FIELD; exports.OBJECT_DELETE_FIELD = OBJECT_DELETE_FIELD; exports.PARENT_ID_FIELD = PARENT_ID_FIELD; exports.SKIP_ASYNC_SCORING_FIELD = SKIP_ASYNC_SCORING_FIELD; exports.SpanComponentsV1 = SpanComponentsV1; exports.SpanComponentsV2 = SpanComponentsV2; exports.SpanComponentsV3 = SpanComponentsV3; exports.SpanComponentsV4 = SpanComponentsV4; exports.SpanObjectTypeV1 = SpanObjectTypeV1; exports.SpanObjectTypeV2 = SpanObjectTypeV2; exports.SpanObjectTypeV3 = SpanObjectTypeV3; exports.SpanRowIdsV1 = SpanRowIdsV1; exports.SpanRowIdsV2 = SpanRowIdsV2; exports.SpanTypeAttribute = SpanTypeAttribute; exports.TRANSACTION_ID_FIELD = TRANSACTION_ID_FIELD; exports.VALID_SOURCES = VALID_SOURCES; exports._urljoin = _urljoin; exports.base64ToUint8Array = base64ToUint8Array; exports.batchItems = batchItems; exports.camelToSnakeCase = camelToSnakeCase; exports.capitalize = capitalize; exports.concatUint8Arrays = concatUint8Arrays; exports.constructJsonArray = constructJsonArray; exports.deterministicReplacer = deterministicReplacer; exports.ensureDatasetRecord = ensureDatasetRecord; exports.ensureLegacyDatasetRecord = ensureLegacyDatasetRecord; exports.ensureNewDatasetRecord = ensureNewDatasetRecord; exports.forEachMissingKey = forEachMissingKey; exports.getObjValueByPath = getObjValueByPath; exports.getRecordKeys = getRecordKeys; exports.isArray = isArray; exports.isEmpty = isEmpty; exports.isNumber = isNumber; exports.isObject = isObject; exports.isObjectOrArray = isObjectOrArray; exports.loadPrettyXact = loadPrettyXact; exports.lowercase = lowercase; exports.makeScorerPropagatedEvent = makeScorerPropagatedEvent; exports.mapAt = mapAt; exports.mapSetDefault = mapSetDefault; exports.mapSetNotPresent = mapSetNotPresent; exports.mergeDicts = mergeDicts; exports.mergeDictsWithPaths = mergeDictsWithPaths; exports.mergeGitMetadataSettings = mergeGitMetadataSettings; exports.mergeRowBatch = mergeRowBatch; exports.notEmpty = notEmpty; exports.objectNullish = objectNullish; exports.parseNoStrip = parseNoStrip; exports.parseParent = parseParent; exports.prettifyXact = prettifyXact; exports.recordAt = recordAt; exports.recordFind = recordFind; exports.recordSetDefault = recordSetDefault; exports.resolveParentHeader = resolveParentHeader; exports.snakeToCamelCase = snakeToCamelCase; exports.snakeToTitleCase = snakeToTitleCase; exports.spanComponentsV3Schema = spanComponentsV3Schema; exports.spanComponentsV4Schema = spanComponentsV4Schema; exports.spanObjectTypeV3EnumSchema = spanObjectTypeV3EnumSchema; exports.spanObjectTypeV3ToString = spanObjectTypeV3ToString; exports.spanObjectTypeV3ToTypedString = spanObjectTypeV3ToTypedString; exports.spanPurposeAttributeValues = spanPurposeAttributeValues; exports.spanTypeAttributeValues = spanTypeAttributeValues; exports.stringToUint8Array = stringToUint8Array; exports.uint8ArrayToBase64 = uint8ArrayToBase64; exports.uint8ArrayToString = uint8ArrayToString;
1397
+
1398
+ exports.ARRAY_DELETE_FIELD = ARRAY_DELETE_FIELD; exports.ASYNC_SCORING_CONTROL_FIELD = ASYNC_SCORING_CONTROL_FIELD; exports.AUDIT_METADATA_FIELD = AUDIT_METADATA_FIELD; exports.AUDIT_SOURCE_FIELD = AUDIT_SOURCE_FIELD; exports.BT_CURSOR_HEADER = BT_CURSOR_HEADER; exports.BT_FOUND_EXISTING_HEADER = BT_FOUND_EXISTING_HEADER; exports.BT_IMPERSONATE_USER = BT_IMPERSONATE_USER; exports.BT_PARENT = BT_PARENT; exports.CREATED_FIELD = CREATED_FIELD; exports.DEFAULT_IS_LEGACY_DATASET = DEFAULT_IS_LEGACY_DATASET; exports.ExtraFieldsError = ExtraFieldsError; exports.ID_FIELD = ID_FIELD; exports.IS_MERGE_FIELD = IS_MERGE_FIELD; exports.MERGE_PATHS_FIELD = MERGE_PATHS_FIELD; exports.OBJECT_DELETE_FIELD = OBJECT_DELETE_FIELD; exports.OBJECT_ID_KEYS = OBJECT_ID_KEYS; exports.PARENT_ID_FIELD = PARENT_ID_FIELD; exports.SKIP_ASYNC_SCORING_FIELD = SKIP_ASYNC_SCORING_FIELD; exports.SpanComponentsV1 = SpanComponentsV1; exports.SpanComponentsV2 = SpanComponentsV2; exports.SpanComponentsV3 = SpanComponentsV3; exports.SpanComponentsV4 = SpanComponentsV4; exports.SpanObjectTypeV1 = SpanObjectTypeV1; exports.SpanObjectTypeV2 = SpanObjectTypeV2; exports.SpanObjectTypeV3 = SpanObjectTypeV3; exports.SpanRowIdsV1 = SpanRowIdsV1; exports.SpanRowIdsV2 = SpanRowIdsV2; exports.SpanTypeAttribute = SpanTypeAttribute; exports.TRANSACTION_ID_FIELD = TRANSACTION_ID_FIELD; exports.VALID_SOURCES = VALID_SOURCES; exports._urljoin = _urljoin; exports.base64ToUint8Array = base64ToUint8Array; exports.batchItems = batchItems; exports.camelToSnakeCase = camelToSnakeCase; exports.capitalize = capitalize; exports.concatUint8Arrays = concatUint8Arrays; exports.constructJsonArray = constructJsonArray; exports.deterministicReplacer = deterministicReplacer; exports.ensureDatasetRecord = ensureDatasetRecord; exports.ensureLegacyDatasetRecord = ensureLegacyDatasetRecord; exports.ensureNewDatasetRecord = ensureNewDatasetRecord; exports.forEachMissingKey = forEachMissingKey; exports.getObjValueByPath = getObjValueByPath; exports.getRecordKeys = getRecordKeys; exports.isArray = isArray; exports.isEmpty = isEmpty; exports.isNumber = isNumber; exports.isObject = isObject; exports.isObjectOrArray = isObjectOrArray; exports.loadPrettyXact = loadPrettyXact; exports.lowercase = lowercase; exports.makeScorerPropagatedEvent = makeScorerPropagatedEvent; exports.mapAt = mapAt; exports.mapSetDefault = mapSetDefault; exports.mapSetNotPresent = mapSetNotPresent; exports.mergeDicts = mergeDicts; exports.mergeDictsWithPaths = mergeDictsWithPaths; exports.mergeGitMetadataSettings = mergeGitMetadataSettings; exports.mergeRowBatch = mergeRowBatch; exports.notEmpty = notEmpty; exports.objectNullish = objectNullish; exports.parseNoStrip = parseNoStrip; exports.parseParent = parseParent; exports.prettifyXact = prettifyXact; exports.recordAt = recordAt; exports.recordFind = recordFind; exports.recordSetDefault = recordSetDefault; exports.resolveParentHeader = resolveParentHeader; exports.snakeToCamelCase = snakeToCamelCase; exports.snakeToTitleCase = snakeToTitleCase; exports.spanComponentsV3Schema = spanComponentsV3Schema; exports.spanComponentsV4Schema = spanComponentsV4Schema; exports.spanObjectTypeV3EnumSchema = spanObjectTypeV3EnumSchema; exports.spanObjectTypeV3ToString = spanObjectTypeV3ToString; exports.spanObjectTypeV3ToTypedString = spanObjectTypeV3ToTypedString; exports.spanPurposeAttributeValues = spanPurposeAttributeValues; exports.spanTypeAttributeValues = spanTypeAttributeValues; exports.stringToUint8Array = stringToUint8Array; exports.uint8ArrayToBase64 = uint8ArrayToBase64; exports.uint8ArrayToString = uint8ArrayToString;
@@ -12,6 +12,14 @@ var VALID_SOURCES = ["app", "api", "external"];
12
12
  var PARENT_ID_FIELD = "_parent_id";
13
13
  var ASYNC_SCORING_CONTROL_FIELD = "_async_scoring_control";
14
14
  var SKIP_ASYNC_SCORING_FIELD = "_skip_async_scoring";
15
+ var OBJECT_ID_KEYS = [
16
+ "experiment_id",
17
+ "dataset_id",
18
+ "prompt_session_id",
19
+ "project_id",
20
+ "log_id",
21
+ "function_data"
22
+ ];
15
23
 
16
24
  // util/span_identifier_v3.ts
17
25
  import * as uuid3 from "uuid";
@@ -810,72 +818,8 @@ function getObjValueByPath(row, path) {
810
818
  return curr;
811
819
  }
812
820
 
813
- // util/graph_util.ts
814
- function depthFirstSearch(args) {
815
- const { graph, firstVisitF, lastVisitF } = args;
816
- for (const vs of graph.values()) {
817
- for (const v of vs.values()) {
818
- if (!graph.has(v)) {
819
- throw new Error(`Outgoing vertex ${v} must be a key in the graph`);
820
- }
821
- }
822
- }
823
- const firstVisitedVertices = /* @__PURE__ */ new Set();
824
- const visitationOrder = args.visitationOrder ?? [...graph.keys()];
825
- const events = visitationOrder.map((vertex) => ({ eventType: "first", vertex, extras: {} })).reverse();
826
- while (events.length) {
827
- const { eventType, vertex, extras } = events.pop();
828
- if (eventType === "last") {
829
- lastVisitF?.(vertex);
830
- continue;
831
- }
832
- if (firstVisitedVertices.has(vertex)) {
833
- continue;
834
- }
835
- firstVisitedVertices.add(vertex);
836
- firstVisitF?.(vertex, { parentVertex: extras.parentVertex });
837
- events.push({ eventType: "last", vertex, extras: {} });
838
- mapAt(graph, vertex).forEach((child) => {
839
- events.push({
840
- eventType: "first",
841
- vertex: child,
842
- extras: { parentVertex: vertex }
843
- });
844
- });
845
- }
846
- }
847
- function undirectedConnectedComponents(graph) {
848
- const directedGraph = new Map(
849
- [...graph.vertices].map((v) => [v, /* @__PURE__ */ new Set()])
850
- );
851
- for (const [i, j] of graph.edges) {
852
- mapAt(directedGraph, i).add(j);
853
- mapAt(directedGraph, j).add(i);
854
- }
855
- let labelCounter = 0;
856
- const vertexLabels = /* @__PURE__ */ new Map();
857
- const firstVisitF = (vertex, args) => {
858
- const label = args?.parentVertex !== void 0 ? mapAt(vertexLabels, args?.parentVertex) : labelCounter++;
859
- vertexLabels.set(vertex, label);
860
- };
861
- depthFirstSearch({ graph: directedGraph, firstVisitF });
862
- const output = Array.from({ length: labelCounter }).map(() => []);
863
- for (const [vertex, label] of vertexLabels.entries()) {
864
- output[label].push(vertex);
865
- }
866
- return output;
867
- }
868
- function topologicalSort(graph, visitationOrder) {
869
- const reverseOrdering = [];
870
- const lastVisitF = (vertex) => {
871
- reverseOrdering.push(vertex);
872
- };
873
- depthFirstSearch({ graph, lastVisitF, visitationOrder });
874
- return reverseOrdering.reverse();
875
- }
876
-
877
821
  // util/merge_row_batch.ts
878
- function generateMergedRowKey(row, useParentIdForId) {
822
+ function generateMergedRowKey(row) {
879
823
  return JSON.stringify(
880
824
  [
881
825
  "org_id",
@@ -884,7 +828,7 @@ function generateMergedRowKey(row, useParentIdForId) {
884
828
  "dataset_id",
885
829
  "prompt_session_id",
886
830
  "log_id",
887
- useParentIdForId ?? false ? PARENT_ID_FIELD : "id"
831
+ "id"
888
832
  ].map((k) => row[k])
889
833
  );
890
834
  }
@@ -938,96 +882,34 @@ function mergeRowBatch(rows) {
938
882
  rowGroups.set(key, row);
939
883
  }
940
884
  }
941
- const merged = [...rowGroups.values()];
942
- const rowToLabel = new Map(
943
- merged.map((r, i) => [generateMergedRowKey(r), i])
944
- );
945
- const graph = new Map(
946
- Array.from({ length: merged.length }).map((_, i) => [i, /* @__PURE__ */ new Set()])
947
- );
948
- merged.forEach((r, i) => {
949
- const parentId = r[PARENT_ID_FIELD];
950
- if (!parentId) {
951
- return;
952
- }
953
- const parentRowKey = generateMergedRowKey(
954
- r,
955
- true
956
- /* useParentIdForId */
957
- );
958
- const parentLabel = rowToLabel.get(parentRowKey);
959
- if (parentLabel !== void 0) {
960
- mapAt(graph, parentLabel).add(i);
961
- }
962
- });
963
- const connectedComponents = undirectedConnectedComponents({
964
- vertices: new Set(graph.keys()),
965
- edges: new Set(
966
- [...graph.entries()].flatMap(
967
- ([k, vs]) => [...vs].map((v) => {
968
- const ret = [k, v];
969
- return ret;
970
- })
971
- )
972
- )
973
- });
974
- const buckets = connectedComponents.map(
975
- (cc) => topologicalSort(
976
- graph,
977
- cc
978
- /* visitationOrder */
979
- )
980
- );
981
- return buckets.map((bucket) => bucket.map((i) => merged[i]));
885
+ return [...rowGroups.values()];
982
886
  }
983
887
  function batchItems(args) {
984
- let { items } = args;
888
+ const { items } = args;
985
889
  const batchMaxNumItems = args.batchMaxNumItems ?? Number.POSITIVE_INFINITY;
986
890
  const batchMaxNumBytes = args.batchMaxNumBytes ?? Number.POSITIVE_INFINITY;
891
+ const getByteSize = args.getByteSize;
987
892
  const output = [];
988
- let nextItems = [];
989
- let batchSet = [];
990
893
  let batch = [];
991
894
  let batchLen = 0;
992
895
  function addToBatch(item) {
993
896
  batch.push(item);
994
- batchLen += item.length;
897
+ batchLen += getByteSize(item);
995
898
  }
996
899
  function flushBatch() {
997
- batchSet.push(batch);
900
+ output.push(batch);
998
901
  batch = [];
999
902
  batchLen = 0;
1000
903
  }
1001
- while (items.length) {
1002
- for (const bucket of items) {
1003
- let i = 0;
1004
- for (const item of bucket) {
1005
- if (batch.length === 0 || item.length + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems) {
1006
- addToBatch(item);
1007
- } else if (i === 0) {
1008
- flushBatch();
1009
- addToBatch(item);
1010
- } else {
1011
- break;
1012
- }
1013
- ++i;
1014
- }
1015
- if (i < bucket.length) {
1016
- nextItems.push(bucket.slice(i));
1017
- }
1018
- if (batchLen >= batchMaxNumBytes || batch.length > batchMaxNumItems) {
1019
- flushBatch();
1020
- }
1021
- }
1022
- if (batch.length) {
904
+ for (const item of items) {
905
+ const itemSize = getByteSize(item);
906
+ if (batch.length > 0 && !(itemSize + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems)) {
1023
907
  flushBatch();
1024
908
  }
1025
- if (batchSet.length) {
1026
- output.push(batchSet);
1027
- batchSet = [];
1028
- }
1029
- items = nextItems;
1030
- nextItems = [];
909
+ addToBatch(item);
910
+ }
911
+ if (batch.length > 0) {
912
+ flushBatch();
1031
913
  }
1032
914
  return output;
1033
915
  }
@@ -1344,7 +1226,8 @@ var spanTypeAttributeValues = [
1344
1226
  "automation",
1345
1227
  "facet",
1346
1228
  "preprocessor",
1347
- "classifier"
1229
+ "classifier",
1230
+ "review"
1348
1231
  ];
1349
1232
  var SpanTypeAttribute = /* @__PURE__ */ ((SpanTypeAttribute2) => {
1350
1233
  SpanTypeAttribute2["LLM"] = "llm";
@@ -1357,6 +1240,7 @@ var SpanTypeAttribute = /* @__PURE__ */ ((SpanTypeAttribute2) => {
1357
1240
  SpanTypeAttribute2["FACET"] = "facet";
1358
1241
  SpanTypeAttribute2["PREPROCESSOR"] = "preprocessor";
1359
1242
  SpanTypeAttribute2["CLASSIFIER"] = "classifier";
1243
+ SpanTypeAttribute2["REVIEW"] = "review";
1360
1244
  return SpanTypeAttribute2;
1361
1245
  })(SpanTypeAttribute || {});
1362
1246
  var spanPurposeAttributeValues = ["scorer"];
@@ -1446,6 +1330,7 @@ export {
1446
1330
  IS_MERGE_FIELD,
1447
1331
  MERGE_PATHS_FIELD,
1448
1332
  OBJECT_DELETE_FIELD,
1333
+ OBJECT_ID_KEYS,
1449
1334
  PARENT_ID_FIELD,
1450
1335
  SKIP_ASYNC_SCORING_FIELD,
1451
1336
  SpanComponentsV1,