braintrust 0.0.122 → 0.0.123

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/browser.js CHANGED
@@ -1362,6 +1362,15 @@ function rng() {
1362
1362
  return getRandomValues(rnds8);
1363
1363
  }
1364
1364
 
1365
+ // ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/regex.js
1366
+ var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
1367
+
1368
+ // ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/validate.js
1369
+ function validate(uuid) {
1370
+ return typeof uuid === "string" && regex_default.test(uuid);
1371
+ }
1372
+ var validate_default = validate;
1373
+
1365
1374
  // ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/stringify.js
1366
1375
  var byteToHex = [];
1367
1376
  for (let i = 0; i < 256; ++i) {
@@ -1370,6 +1379,41 @@ for (let i = 0; i < 256; ++i) {
1370
1379
  function unsafeStringify(arr, offset = 0) {
1371
1380
  return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
1372
1381
  }
1382
+ function stringify(arr, offset = 0) {
1383
+ const uuid = unsafeStringify(arr, offset);
1384
+ if (!validate_default(uuid)) {
1385
+ throw TypeError("Stringified UUID is invalid");
1386
+ }
1387
+ return uuid;
1388
+ }
1389
+ var stringify_default = stringify;
1390
+
1391
+ // ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/parse.js
1392
+ function parse(uuid) {
1393
+ if (!validate_default(uuid)) {
1394
+ throw TypeError("Invalid UUID");
1395
+ }
1396
+ let v;
1397
+ const arr = new Uint8Array(16);
1398
+ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
1399
+ arr[1] = v >>> 16 & 255;
1400
+ arr[2] = v >>> 8 & 255;
1401
+ arr[3] = v & 255;
1402
+ arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
1403
+ arr[5] = v & 255;
1404
+ arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
1405
+ arr[7] = v & 255;
1406
+ arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
1407
+ arr[9] = v & 255;
1408
+ arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 1099511627776 & 255;
1409
+ arr[11] = v / 4294967296 & 255;
1410
+ arr[12] = v >>> 24 & 255;
1411
+ arr[13] = v >>> 16 & 255;
1412
+ arr[14] = v >>> 8 & 255;
1413
+ arr[15] = v & 255;
1414
+ return arr;
1415
+ }
1416
+ var parse_default = parse;
1373
1417
 
1374
1418
  // ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-browser/native.js
1375
1419
  var randomUUID = typeof crypto !== "undefined" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
@@ -1397,451 +1441,61 @@ function v4(options, buf, offset) {
1397
1441
  }
1398
1442
  var v4_default = v4;
1399
1443
 
1400
- // ../core/js/dist/index.mjs
1401
- var TRANSACTION_ID_FIELD = "_xact_id";
1402
- var IS_MERGE_FIELD = "_is_merge";
1403
- var MERGE_PATHS_FIELD = "_merge_paths";
1404
- var AUDIT_SOURCE_FIELD = "_audit_source";
1405
- var AUDIT_METADATA_FIELD = "_audit_metadata";
1406
- var VALID_SOURCES = ["app", "api", "external"];
1407
- var PARENT_ID_FIELD = "_parent_id";
1408
- function mergeDicts(mergeInto, mergeFrom) {
1409
- for (const [k, mergeFromV] of Object.entries(mergeFrom)) {
1410
- const mergeIntoV = mergeInto[k];
1411
- if (mergeIntoV instanceof Object && !Array.isArray(mergeIntoV) && mergeFrom instanceof Object && !Array.isArray(mergeFromV)) {
1412
- mergeDicts(
1413
- mergeIntoV,
1414
- mergeFromV
1415
- );
1416
- } else {
1417
- mergeInto[k] = mergeFromV;
1418
- }
1419
- }
1420
- return mergeInto;
1421
- }
1422
- function constructJsonArray(items) {
1423
- return `[${items.join(",")}]`;
1424
- }
1425
- function mapAt(m, k) {
1426
- const ret = m.get(k);
1427
- if (ret === void 0) {
1428
- throw new Error(`Map does not contain key ${k}`);
1444
+ // ../../node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
1445
+ var util;
1446
+ (function(util2) {
1447
+ util2.assertEqual = (val) => val;
1448
+ function assertIs(_arg) {
1429
1449
  }
1430
- return ret;
1431
- }
1432
- function depthFirstSearch(args) {
1433
- var _a2;
1434
- const { graph, firstVisitF, lastVisitF } = args;
1435
- for (const vs of graph.values()) {
1436
- for (const v of vs.values()) {
1437
- if (!graph.has(v)) {
1438
- throw new Error(`Outgoing vertex ${v} must be a key in the graph`);
1439
- }
1440
- }
1450
+ util2.assertIs = assertIs;
1451
+ function assertNever(_x) {
1452
+ throw new Error();
1441
1453
  }
1442
- const firstVisitedVertices = /* @__PURE__ */ new Set();
1443
- const visitationOrder = (_a2 = args.visitationOrder) != null ? _a2 : [...graph.keys()];
1444
- const events = visitationOrder.map((vertex) => ({ eventType: "first", vertex, extras: {} })).reverse();
1445
- while (events.length) {
1446
- const { eventType, vertex, extras } = events.pop();
1447
- if (eventType === "last") {
1448
- lastVisitF == null ? void 0 : lastVisitF(vertex);
1449
- continue;
1454
+ util2.assertNever = assertNever;
1455
+ util2.arrayToEnum = (items) => {
1456
+ const obj = {};
1457
+ for (const item of items) {
1458
+ obj[item] = item;
1450
1459
  }
1451
- if (firstVisitedVertices.has(vertex)) {
1452
- continue;
1460
+ return obj;
1461
+ };
1462
+ util2.getValidEnumValues = (obj) => {
1463
+ const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
1464
+ const filtered = {};
1465
+ for (const k of validKeys) {
1466
+ filtered[k] = obj[k];
1453
1467
  }
1454
- firstVisitedVertices.add(vertex);
1455
- firstVisitF == null ? void 0 : firstVisitF(vertex, { parentVertex: extras.parentVertex });
1456
- events.push({ eventType: "last", vertex, extras: {} });
1457
- mapAt(graph, vertex).forEach((child) => {
1458
- events.push({
1459
- eventType: "first",
1460
- vertex: child,
1461
- extras: { parentVertex: vertex }
1462
- });
1463
- });
1464
- }
1465
- }
1466
- function undirectedConnectedComponents(graph) {
1467
- const directedGraph = new Map(
1468
- [...graph.vertices].map((v) => [v, /* @__PURE__ */ new Set()])
1469
- );
1470
- for (const [i, j] of graph.edges) {
1471
- mapAt(directedGraph, i).add(j);
1472
- mapAt(directedGraph, j).add(i);
1473
- }
1474
- let labelCounter = 0;
1475
- const vertexLabels = /* @__PURE__ */ new Map();
1476
- const firstVisitF = (vertex, args) => {
1477
- const label = (args == null ? void 0 : args.parentVertex) !== void 0 ? mapAt(vertexLabels, args == null ? void 0 : args.parentVertex) : labelCounter++;
1478
- vertexLabels.set(vertex, label);
1468
+ return util2.objectValues(filtered);
1479
1469
  };
1480
- depthFirstSearch({ graph: directedGraph, firstVisitF });
1481
- const output = Array.from({ length: labelCounter }).map(() => []);
1482
- for (const [vertex, label] of vertexLabels.entries()) {
1483
- output[label].push(vertex);
1484
- }
1485
- return output;
1486
- }
1487
- function topologicalSort(graph, visitationOrder) {
1488
- const reverseOrdering = [];
1489
- const lastVisitF = (vertex) => {
1490
- reverseOrdering.push(vertex);
1470
+ util2.objectValues = (obj) => {
1471
+ return util2.objectKeys(obj).map(function(e) {
1472
+ return obj[e];
1473
+ });
1491
1474
  };
1492
- depthFirstSearch({ graph, lastVisitF, visitationOrder });
1493
- return reverseOrdering.reverse();
1494
- }
1495
- function generateMergedRowKey(row, useParentIdForId) {
1496
- return JSON.stringify(
1497
- [
1498
- "org_id",
1499
- "project_id",
1500
- "experiment_id",
1501
- "dataset_id",
1502
- "prompt_session_id",
1503
- "log_id",
1504
- (useParentIdForId != null ? useParentIdForId : false) ? PARENT_ID_FIELD : "id"
1505
- ].map((k) => row[k])
1506
- );
1507
- }
1508
- function mergeRowBatch(rows) {
1509
- for (const row of rows) {
1510
- if (row.id === void 0) {
1511
- throw new Error(
1512
- "Logged row is missing an id. This is an internal braintrust error. Please contact us at info@braintrustdata.com for help"
1513
- );
1514
- }
1515
- }
1516
- const rowGroups = /* @__PURE__ */ new Map();
1517
- for (const row of rows) {
1518
- const key = generateMergedRowKey(row);
1519
- const existingRow = rowGroups.get(key);
1520
- if (existingRow !== void 0 && row[IS_MERGE_FIELD]) {
1521
- const preserveNoMerge = !existingRow[IS_MERGE_FIELD];
1522
- mergeDicts(existingRow, row);
1523
- if (preserveNoMerge) {
1524
- delete existingRow[IS_MERGE_FIELD];
1475
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
1476
+ const keys = [];
1477
+ for (const key in object) {
1478
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
1479
+ keys.push(key);
1525
1480
  }
1526
- } else {
1527
- rowGroups.set(key, row);
1528
- }
1529
- }
1530
- const merged = [...rowGroups.values()];
1531
- const rowToLabel = new Map(
1532
- merged.map((r, i) => [generateMergedRowKey(r), i])
1533
- );
1534
- const graph = new Map(
1535
- Array.from({ length: merged.length }).map((_, i) => [i, /* @__PURE__ */ new Set()])
1536
- );
1537
- merged.forEach((r, i) => {
1538
- const parentId = r[PARENT_ID_FIELD];
1539
- if (!parentId) {
1540
- return;
1541
1481
  }
1542
- const parentRowKey = generateMergedRowKey(
1543
- r,
1544
- true
1545
- /* useParentIdForId */
1546
- );
1547
- const parentLabel = rowToLabel.get(parentRowKey);
1548
- if (parentLabel !== void 0) {
1549
- mapAt(graph, parentLabel).add(i);
1482
+ return keys;
1483
+ };
1484
+ util2.find = (arr, checker) => {
1485
+ for (const item of arr) {
1486
+ if (checker(item))
1487
+ return item;
1550
1488
  }
1551
- });
1552
- const connectedComponents = undirectedConnectedComponents({
1553
- vertices: new Set(graph.keys()),
1554
- edges: new Set(
1555
- [...graph.entries()].flatMap(
1556
- ([k, vs]) => [...vs].map((v) => {
1557
- const ret = [k, v];
1558
- return ret;
1559
- })
1560
- )
1561
- )
1562
- });
1563
- const buckets = connectedComponents.map(
1564
- (cc) => topologicalSort(
1565
- graph,
1566
- cc
1567
- /* visitationOrder */
1568
- )
1569
- );
1570
- return buckets.map((bucket) => bucket.map((i) => merged[i]));
1571
- }
1572
- function batchItems(args) {
1573
- var _a2, _b;
1574
- let { items } = args;
1575
- const batchMaxNumItems = (_a2 = args.batchMaxNumItems) != null ? _a2 : Number.POSITIVE_INFINITY;
1576
- const batchMaxNumBytes = (_b = args.batchMaxNumBytes) != null ? _b : Number.POSITIVE_INFINITY;
1577
- const output = [];
1578
- let nextItems = [];
1579
- let batchSet = [];
1580
- let batch = [];
1581
- let batchLen = 0;
1582
- function addToBatch(item) {
1583
- batch.push(item);
1584
- batchLen += item.length;
1585
- }
1586
- function flushBatch() {
1587
- batchSet.push(batch);
1588
- batch = [];
1589
- batchLen = 0;
1489
+ return void 0;
1490
+ };
1491
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
1492
+ function joinValues(array, separator = " | ") {
1493
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
1590
1494
  }
1591
- while (items.length) {
1592
- for (const bucket of items) {
1593
- let i = 0;
1594
- for (const item of bucket) {
1595
- if (batch.length === 0 || item.length + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems) {
1596
- addToBatch(item);
1597
- } else if (i === 0) {
1598
- flushBatch();
1599
- addToBatch(item);
1600
- } else {
1601
- break;
1602
- }
1603
- ++i;
1604
- }
1605
- if (i < bucket.length) {
1606
- nextItems.push(bucket.slice(i));
1607
- }
1608
- if (batchLen >= batchMaxNumBytes || batch.length > batchMaxNumItems) {
1609
- flushBatch();
1610
- }
1611
- }
1612
- if (batch.length) {
1613
- flushBatch();
1614
- }
1615
- if (batchSet.length) {
1616
- output.push(batchSet);
1617
- batchSet = [];
1618
- }
1619
- items = nextItems;
1620
- nextItems = [];
1621
- }
1622
- return output;
1623
- }
1624
- var DEFAULT_IS_LEGACY_DATASET = true;
1625
- function ensureDatasetRecord(r, legacy) {
1626
- if (legacy) {
1627
- return ensureLegacyDatasetRecord(r);
1628
- } else {
1629
- return ensureNewDatasetRecord(r);
1630
- }
1631
- }
1632
- function ensureLegacyDatasetRecord(r) {
1633
- if ("output" in r) {
1634
- return r;
1635
- }
1636
- const row = {
1637
- ...r,
1638
- output: r.expected
1639
- };
1640
- delete row.expected;
1641
- return row;
1642
- }
1643
- function ensureNewDatasetRecord(r) {
1644
- if ("expected" in r) {
1645
- return r;
1646
- }
1647
- const row = {
1648
- ...r,
1649
- tags: null,
1650
- expected: r.output
1651
- };
1652
- delete row.output;
1653
- return row;
1654
- }
1655
- function makeLegacyEvent(e) {
1656
- if (!("dataset_id" in e) || !("expected" in e)) {
1657
- return e;
1658
- }
1659
- const event = {
1660
- ...e,
1661
- output: e.expected
1662
- };
1663
- delete event.expected;
1664
- if (MERGE_PATHS_FIELD in event) {
1665
- for (const path of event[MERGE_PATHS_FIELD] || []) {
1666
- if (path.length > 0 && path[0] === "expected") {
1667
- path[0] = "output";
1668
- }
1669
- }
1670
- }
1671
- return event;
1672
- }
1673
- var SpanParentObjectType = /* @__PURE__ */ ((SpanParentObjectType2) => {
1674
- SpanParentObjectType2["EXPERIMENT"] = "experiment";
1675
- SpanParentObjectType2["PROJECT_LOGS"] = "project_logs";
1676
- return SpanParentObjectType2;
1677
- })(SpanParentObjectType || {});
1678
- var _OBJECT_TYPE_TO_PREFIX = {
1679
- [
1680
- "experiment"
1681
- /* EXPERIMENT */
1682
- ]: "ex",
1683
- [
1684
- "project_logs"
1685
- /* PROJECT_LOGS */
1686
- ]: "pl"
1687
- };
1688
- var _PREFIX_TO_OBJECT_TYPE = Object.fromEntries(
1689
- Object.entries(_OBJECT_TYPE_TO_PREFIX).map(([k, v]) => [v, k])
1690
- );
1691
- var _SEP = ":";
1692
- var SpanParentComponents = class _SpanParentComponents {
1693
- constructor(args) {
1694
- this.objectType = args.objectType;
1695
- this.objectId = args.objectId;
1696
- this.rowId = args.rowId;
1697
- if (!(typeof this.objectType === "string")) {
1698
- throw new Error("objectType must be a string");
1699
- }
1700
- if (!(typeof this.objectId === "string")) {
1701
- throw new Error("objectId must be a string");
1702
- }
1703
- if (!(typeof this.rowId === "string")) {
1704
- throw new Error("rowId must be a string");
1705
- }
1706
- const objectTypePrefix = _OBJECT_TYPE_TO_PREFIX[this.objectType];
1707
- if (objectTypePrefix.includes(_SEP)) {
1708
- throw new Error(
1709
- `objectType prefix ${objectTypePrefix} may not contain separator character ${_SEP}`
1710
- );
1711
- }
1712
- if (this.objectId.includes(_SEP)) {
1713
- throw new Error(
1714
- `objectId ${this.objectId} may not contain separator character ${_SEP}`
1715
- );
1716
- }
1717
- }
1718
- toStr() {
1719
- return [
1720
- _OBJECT_TYPE_TO_PREFIX[this.objectType],
1721
- this.objectId,
1722
- this.rowId
1723
- ].join(_SEP);
1724
- }
1725
- static fromStr(s) {
1726
- const items = s.split(_SEP);
1727
- if (items.length < 3) {
1728
- throw new Error(
1729
- `Serialized parent components string must have at least three components. Provided string ${s} has only ${items.length}`
1730
- );
1731
- }
1732
- return new _SpanParentComponents({
1733
- objectType: _PREFIX_TO_OBJECT_TYPE[items[0]],
1734
- objectId: items[1],
1735
- rowId: items.slice(2).join(_SEP)
1736
- });
1737
- }
1738
- asDict() {
1739
- const out = (() => {
1740
- switch (this.objectType) {
1741
- case "experiment":
1742
- return { experiment_id: this.objectId };
1743
- case "project_logs":
1744
- return { project_id: this.objectId, log_id: "g" };
1745
- default:
1746
- throw new Error("Impossible");
1747
- }
1748
- })();
1749
- if (this.rowId) {
1750
- out[PARENT_ID_FIELD] = this.rowId;
1751
- }
1752
- return out;
1753
- }
1754
- };
1755
- var SpanTypeAttribute = /* @__PURE__ */ ((SpanTypeAttribute2) => {
1756
- SpanTypeAttribute2["LLM"] = "llm";
1757
- SpanTypeAttribute2["SCORE"] = "score";
1758
- SpanTypeAttribute2["FUNCTION"] = "function";
1759
- SpanTypeAttribute2["EVAL"] = "eval";
1760
- SpanTypeAttribute2["TASK"] = "task";
1761
- SpanTypeAttribute2["TOOL"] = "tool";
1762
- return SpanTypeAttribute2;
1763
- })(SpanTypeAttribute || {});
1764
- function mergeGitMetadataSettings(s1, s2) {
1765
- var _a2;
1766
- if (s1.collect === "all") {
1767
- return s2;
1768
- } else if (s2.collect === "all") {
1769
- return s1;
1770
- } else if (s1.collect === "none") {
1771
- return s1;
1772
- } else if (s2.collect === "none") {
1773
- return s2;
1774
- }
1775
- const fields = ((_a2 = s1.fields) != null ? _a2 : []).filter((f) => {
1776
- var _a22;
1777
- return ((_a22 = s2.fields) != null ? _a22 : []).includes(f);
1778
- });
1779
- const collect = fields.length > 0 ? "some" : "none";
1780
- return { collect, fields };
1781
- }
1782
- var TOP_BITS = BigInt("0x0DE1") << BigInt(48);
1783
- var MOD = BigInt(1) << BigInt(64);
1784
- var COPRIME = BigInt("205891132094649");
1785
- var COPRIME_INVERSE = BigInt("1522336535492693385");
1786
-
1787
- // ../core/js/typespecs/dist/index.mjs
1788
- var import_zod_to_openapi = __toESM(require_dist(), 1);
1789
-
1790
- // ../../node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/index.mjs
1791
- var util;
1792
- (function(util2) {
1793
- util2.assertEqual = (val) => val;
1794
- function assertIs(_arg) {
1795
- }
1796
- util2.assertIs = assertIs;
1797
- function assertNever(_x) {
1798
- throw new Error();
1799
- }
1800
- util2.assertNever = assertNever;
1801
- util2.arrayToEnum = (items) => {
1802
- const obj = {};
1803
- for (const item of items) {
1804
- obj[item] = item;
1805
- }
1806
- return obj;
1807
- };
1808
- util2.getValidEnumValues = (obj) => {
1809
- const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
1810
- const filtered = {};
1811
- for (const k of validKeys) {
1812
- filtered[k] = obj[k];
1813
- }
1814
- return util2.objectValues(filtered);
1815
- };
1816
- util2.objectValues = (obj) => {
1817
- return util2.objectKeys(obj).map(function(e) {
1818
- return obj[e];
1819
- });
1820
- };
1821
- util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
1822
- const keys = [];
1823
- for (const key in object) {
1824
- if (Object.prototype.hasOwnProperty.call(object, key)) {
1825
- keys.push(key);
1826
- }
1827
- }
1828
- return keys;
1829
- };
1830
- util2.find = (arr, checker) => {
1831
- for (const item of arr) {
1832
- if (checker(item))
1833
- return item;
1834
- }
1835
- return void 0;
1836
- };
1837
- util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
1838
- function joinValues(array, separator = " | ") {
1839
- return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
1840
- }
1841
- util2.joinValues = joinValues;
1842
- util2.jsonStringifyReplacer = (_, value) => {
1843
- if (typeof value === "bigint") {
1844
- return value.toString();
1495
+ util2.joinValues = joinValues;
1496
+ util2.jsonStringifyReplacer = (_, value) => {
1497
+ if (typeof value === "bigint") {
1498
+ return value.toString();
1845
1499
  }
1846
1500
  return value;
1847
1501
  };
@@ -5403,124 +5057,562 @@ var coerce = {
5403
5057
  bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
5404
5058
  date: (arg) => ZodDate.create({ ...arg, coerce: true })
5405
5059
  };
5406
- var NEVER = INVALID;
5407
- var z = /* @__PURE__ */ Object.freeze({
5408
- __proto__: null,
5409
- defaultErrorMap: errorMap,
5410
- setErrorMap,
5411
- getErrorMap,
5412
- makeIssue,
5413
- EMPTY_PATH,
5414
- addIssueToContext,
5415
- ParseStatus,
5416
- INVALID,
5417
- DIRTY,
5418
- OK,
5419
- isAborted,
5420
- isDirty,
5421
- isValid,
5422
- isAsync,
5423
- get util() {
5424
- return util;
5425
- },
5426
- get objectUtil() {
5427
- return objectUtil;
5428
- },
5429
- ZodParsedType,
5430
- getParsedType,
5431
- ZodType,
5432
- ZodString,
5433
- ZodNumber,
5434
- ZodBigInt,
5435
- ZodBoolean,
5436
- ZodDate,
5437
- ZodSymbol,
5438
- ZodUndefined,
5439
- ZodNull,
5440
- ZodAny,
5441
- ZodUnknown,
5442
- ZodNever,
5443
- ZodVoid,
5444
- ZodArray,
5445
- ZodObject,
5446
- ZodUnion,
5447
- ZodDiscriminatedUnion,
5448
- ZodIntersection,
5449
- ZodTuple,
5450
- ZodRecord,
5451
- ZodMap,
5452
- ZodSet,
5453
- ZodFunction,
5454
- ZodLazy,
5455
- ZodLiteral,
5456
- ZodEnum,
5457
- ZodNativeEnum,
5458
- ZodPromise,
5459
- ZodEffects,
5460
- ZodTransformer: ZodEffects,
5461
- ZodOptional,
5462
- ZodNullable,
5463
- ZodDefault,
5464
- ZodCatch,
5465
- ZodNaN,
5466
- BRAND,
5467
- ZodBranded,
5468
- ZodPipeline,
5469
- ZodReadonly,
5470
- custom,
5471
- Schema: ZodType,
5472
- ZodSchema: ZodType,
5473
- late,
5474
- get ZodFirstPartyTypeKind() {
5475
- return ZodFirstPartyTypeKind;
5476
- },
5477
- coerce,
5478
- any: anyType,
5479
- array: arrayType,
5480
- bigint: bigIntType,
5481
- boolean: booleanType,
5482
- date: dateType,
5483
- discriminatedUnion: discriminatedUnionType,
5484
- effect: effectsType,
5485
- "enum": enumType,
5486
- "function": functionType,
5487
- "instanceof": instanceOfType,
5488
- intersection: intersectionType,
5489
- lazy: lazyType,
5490
- literal: literalType,
5491
- map: mapType,
5492
- nan: nanType,
5493
- nativeEnum: nativeEnumType,
5494
- never: neverType,
5495
- "null": nullType,
5496
- nullable: nullableType,
5497
- number: numberType,
5498
- object: objectType,
5499
- oboolean,
5500
- onumber,
5501
- optional: optionalType,
5502
- ostring,
5503
- pipeline: pipelineType,
5504
- preprocess: preprocessType,
5505
- promise: promiseType,
5506
- record: recordType,
5507
- set: setType,
5508
- strictObject: strictObjectType,
5509
- string: stringType,
5510
- symbol: symbolType,
5511
- transformer: effectsType,
5512
- tuple: tupleType,
5513
- "undefined": undefinedType,
5514
- union: unionType,
5515
- unknown: unknownType,
5516
- "void": voidType,
5517
- NEVER,
5518
- ZodIssueCode,
5519
- quotelessJson,
5520
- ZodError
5521
- });
5060
+ var NEVER = INVALID;
5061
+ var z = /* @__PURE__ */ Object.freeze({
5062
+ __proto__: null,
5063
+ defaultErrorMap: errorMap,
5064
+ setErrorMap,
5065
+ getErrorMap,
5066
+ makeIssue,
5067
+ EMPTY_PATH,
5068
+ addIssueToContext,
5069
+ ParseStatus,
5070
+ INVALID,
5071
+ DIRTY,
5072
+ OK,
5073
+ isAborted,
5074
+ isDirty,
5075
+ isValid,
5076
+ isAsync,
5077
+ get util() {
5078
+ return util;
5079
+ },
5080
+ get objectUtil() {
5081
+ return objectUtil;
5082
+ },
5083
+ ZodParsedType,
5084
+ getParsedType,
5085
+ ZodType,
5086
+ ZodString,
5087
+ ZodNumber,
5088
+ ZodBigInt,
5089
+ ZodBoolean,
5090
+ ZodDate,
5091
+ ZodSymbol,
5092
+ ZodUndefined,
5093
+ ZodNull,
5094
+ ZodAny,
5095
+ ZodUnknown,
5096
+ ZodNever,
5097
+ ZodVoid,
5098
+ ZodArray,
5099
+ ZodObject,
5100
+ ZodUnion,
5101
+ ZodDiscriminatedUnion,
5102
+ ZodIntersection,
5103
+ ZodTuple,
5104
+ ZodRecord,
5105
+ ZodMap,
5106
+ ZodSet,
5107
+ ZodFunction,
5108
+ ZodLazy,
5109
+ ZodLiteral,
5110
+ ZodEnum,
5111
+ ZodNativeEnum,
5112
+ ZodPromise,
5113
+ ZodEffects,
5114
+ ZodTransformer: ZodEffects,
5115
+ ZodOptional,
5116
+ ZodNullable,
5117
+ ZodDefault,
5118
+ ZodCatch,
5119
+ ZodNaN,
5120
+ BRAND,
5121
+ ZodBranded,
5122
+ ZodPipeline,
5123
+ ZodReadonly,
5124
+ custom,
5125
+ Schema: ZodType,
5126
+ ZodSchema: ZodType,
5127
+ late,
5128
+ get ZodFirstPartyTypeKind() {
5129
+ return ZodFirstPartyTypeKind;
5130
+ },
5131
+ coerce,
5132
+ any: anyType,
5133
+ array: arrayType,
5134
+ bigint: bigIntType,
5135
+ boolean: booleanType,
5136
+ date: dateType,
5137
+ discriminatedUnion: discriminatedUnionType,
5138
+ effect: effectsType,
5139
+ "enum": enumType,
5140
+ "function": functionType,
5141
+ "instanceof": instanceOfType,
5142
+ intersection: intersectionType,
5143
+ lazy: lazyType,
5144
+ literal: literalType,
5145
+ map: mapType,
5146
+ nan: nanType,
5147
+ nativeEnum: nativeEnumType,
5148
+ never: neverType,
5149
+ "null": nullType,
5150
+ nullable: nullableType,
5151
+ number: numberType,
5152
+ object: objectType,
5153
+ oboolean,
5154
+ onumber,
5155
+ optional: optionalType,
5156
+ ostring,
5157
+ pipeline: pipelineType,
5158
+ preprocess: preprocessType,
5159
+ promise: promiseType,
5160
+ record: recordType,
5161
+ set: setType,
5162
+ strictObject: strictObjectType,
5163
+ string: stringType,
5164
+ symbol: symbolType,
5165
+ transformer: effectsType,
5166
+ tuple: tupleType,
5167
+ "undefined": undefinedType,
5168
+ union: unionType,
5169
+ unknown: unknownType,
5170
+ "void": voidType,
5171
+ NEVER,
5172
+ ZodIssueCode,
5173
+ quotelessJson,
5174
+ ZodError
5175
+ });
5176
+
5177
+ // ../core/js/dist/index.mjs
5178
+ var TRANSACTION_ID_FIELD = "_xact_id";
5179
+ var IS_MERGE_FIELD = "_is_merge";
5180
+ var MERGE_PATHS_FIELD = "_merge_paths";
5181
+ var AUDIT_SOURCE_FIELD = "_audit_source";
5182
+ var AUDIT_METADATA_FIELD = "_audit_metadata";
5183
+ var VALID_SOURCES = ["app", "api", "external"];
5184
+ var PARENT_ID_FIELD = "_parent_id";
5185
+ function mergeDicts(mergeInto, mergeFrom) {
5186
+ for (const [k, mergeFromV] of Object.entries(mergeFrom)) {
5187
+ const mergeIntoV = mergeInto[k];
5188
+ if (mergeIntoV instanceof Object && !Array.isArray(mergeIntoV) && mergeFrom instanceof Object && !Array.isArray(mergeFromV)) {
5189
+ mergeDicts(
5190
+ mergeIntoV,
5191
+ mergeFromV
5192
+ );
5193
+ } else {
5194
+ mergeInto[k] = mergeFromV;
5195
+ }
5196
+ }
5197
+ return mergeInto;
5198
+ }
5199
+ function constructJsonArray(items) {
5200
+ return `[${items.join(",")}]`;
5201
+ }
5202
+ function mapAt(m, k) {
5203
+ const ret = m.get(k);
5204
+ if (ret === void 0) {
5205
+ throw new Error(`Map does not contain key ${k}`);
5206
+ }
5207
+ return ret;
5208
+ }
5209
+ function depthFirstSearch(args) {
5210
+ var _a2;
5211
+ const { graph, firstVisitF, lastVisitF } = args;
5212
+ for (const vs of graph.values()) {
5213
+ for (const v of vs.values()) {
5214
+ if (!graph.has(v)) {
5215
+ throw new Error(`Outgoing vertex ${v} must be a key in the graph`);
5216
+ }
5217
+ }
5218
+ }
5219
+ const firstVisitedVertices = /* @__PURE__ */ new Set();
5220
+ const visitationOrder = (_a2 = args.visitationOrder) != null ? _a2 : [...graph.keys()];
5221
+ const events = visitationOrder.map((vertex) => ({ eventType: "first", vertex, extras: {} })).reverse();
5222
+ while (events.length) {
5223
+ const { eventType, vertex, extras } = events.pop();
5224
+ if (eventType === "last") {
5225
+ lastVisitF == null ? void 0 : lastVisitF(vertex);
5226
+ continue;
5227
+ }
5228
+ if (firstVisitedVertices.has(vertex)) {
5229
+ continue;
5230
+ }
5231
+ firstVisitedVertices.add(vertex);
5232
+ firstVisitF == null ? void 0 : firstVisitF(vertex, { parentVertex: extras.parentVertex });
5233
+ events.push({ eventType: "last", vertex, extras: {} });
5234
+ mapAt(graph, vertex).forEach((child) => {
5235
+ events.push({
5236
+ eventType: "first",
5237
+ vertex: child,
5238
+ extras: { parentVertex: vertex }
5239
+ });
5240
+ });
5241
+ }
5242
+ }
5243
+ function undirectedConnectedComponents(graph) {
5244
+ const directedGraph = new Map(
5245
+ [...graph.vertices].map((v) => [v, /* @__PURE__ */ new Set()])
5246
+ );
5247
+ for (const [i, j] of graph.edges) {
5248
+ mapAt(directedGraph, i).add(j);
5249
+ mapAt(directedGraph, j).add(i);
5250
+ }
5251
+ let labelCounter = 0;
5252
+ const vertexLabels = /* @__PURE__ */ new Map();
5253
+ const firstVisitF = (vertex, args) => {
5254
+ const label = (args == null ? void 0 : args.parentVertex) !== void 0 ? mapAt(vertexLabels, args == null ? void 0 : args.parentVertex) : labelCounter++;
5255
+ vertexLabels.set(vertex, label);
5256
+ };
5257
+ depthFirstSearch({ graph: directedGraph, firstVisitF });
5258
+ const output = Array.from({ length: labelCounter }).map(() => []);
5259
+ for (const [vertex, label] of vertexLabels.entries()) {
5260
+ output[label].push(vertex);
5261
+ }
5262
+ return output;
5263
+ }
5264
+ function topologicalSort(graph, visitationOrder) {
5265
+ const reverseOrdering = [];
5266
+ const lastVisitF = (vertex) => {
5267
+ reverseOrdering.push(vertex);
5268
+ };
5269
+ depthFirstSearch({ graph, lastVisitF, visitationOrder });
5270
+ return reverseOrdering.reverse();
5271
+ }
5272
+ function generateMergedRowKey(row, useParentIdForId) {
5273
+ return JSON.stringify(
5274
+ [
5275
+ "org_id",
5276
+ "project_id",
5277
+ "experiment_id",
5278
+ "dataset_id",
5279
+ "prompt_session_id",
5280
+ "log_id",
5281
+ (useParentIdForId != null ? useParentIdForId : false) ? PARENT_ID_FIELD : "id"
5282
+ ].map((k) => row[k])
5283
+ );
5284
+ }
5285
+ function mergeRowBatch(rows) {
5286
+ for (const row of rows) {
5287
+ if (row.id === void 0) {
5288
+ throw new Error(
5289
+ "Logged row is missing an id. This is an internal braintrust error. Please contact us at info@braintrustdata.com for help"
5290
+ );
5291
+ }
5292
+ }
5293
+ const rowGroups = /* @__PURE__ */ new Map();
5294
+ for (const row of rows) {
5295
+ const key = generateMergedRowKey(row);
5296
+ const existingRow = rowGroups.get(key);
5297
+ if (existingRow !== void 0 && row[IS_MERGE_FIELD]) {
5298
+ const preserveNoMerge = !existingRow[IS_MERGE_FIELD];
5299
+ mergeDicts(existingRow, row);
5300
+ if (preserveNoMerge) {
5301
+ delete existingRow[IS_MERGE_FIELD];
5302
+ }
5303
+ } else {
5304
+ rowGroups.set(key, row);
5305
+ }
5306
+ }
5307
+ const merged = [...rowGroups.values()];
5308
+ const rowToLabel = new Map(
5309
+ merged.map((r, i) => [generateMergedRowKey(r), i])
5310
+ );
5311
+ const graph = new Map(
5312
+ Array.from({ length: merged.length }).map((_, i) => [i, /* @__PURE__ */ new Set()])
5313
+ );
5314
+ merged.forEach((r, i) => {
5315
+ const parentId = r[PARENT_ID_FIELD];
5316
+ if (!parentId) {
5317
+ return;
5318
+ }
5319
+ const parentRowKey = generateMergedRowKey(
5320
+ r,
5321
+ true
5322
+ /* useParentIdForId */
5323
+ );
5324
+ const parentLabel = rowToLabel.get(parentRowKey);
5325
+ if (parentLabel !== void 0) {
5326
+ mapAt(graph, parentLabel).add(i);
5327
+ }
5328
+ });
5329
+ const connectedComponents = undirectedConnectedComponents({
5330
+ vertices: new Set(graph.keys()),
5331
+ edges: new Set(
5332
+ [...graph.entries()].flatMap(
5333
+ ([k, vs]) => [...vs].map((v) => {
5334
+ const ret = [k, v];
5335
+ return ret;
5336
+ })
5337
+ )
5338
+ )
5339
+ });
5340
+ const buckets = connectedComponents.map(
5341
+ (cc) => topologicalSort(
5342
+ graph,
5343
+ cc
5344
+ /* visitationOrder */
5345
+ )
5346
+ );
5347
+ return buckets.map((bucket) => bucket.map((i) => merged[i]));
5348
+ }
5349
+ function batchItems(args) {
5350
+ var _a2, _b;
5351
+ let { items } = args;
5352
+ const batchMaxNumItems = (_a2 = args.batchMaxNumItems) != null ? _a2 : Number.POSITIVE_INFINITY;
5353
+ const batchMaxNumBytes = (_b = args.batchMaxNumBytes) != null ? _b : Number.POSITIVE_INFINITY;
5354
+ const output = [];
5355
+ let nextItems = [];
5356
+ let batchSet = [];
5357
+ let batch = [];
5358
+ let batchLen = 0;
5359
+ function addToBatch(item) {
5360
+ batch.push(item);
5361
+ batchLen += item.length;
5362
+ }
5363
+ function flushBatch() {
5364
+ batchSet.push(batch);
5365
+ batch = [];
5366
+ batchLen = 0;
5367
+ }
5368
+ while (items.length) {
5369
+ for (const bucket of items) {
5370
+ let i = 0;
5371
+ for (const item of bucket) {
5372
+ if (batch.length === 0 || item.length + batchLen < batchMaxNumBytes && batch.length < batchMaxNumItems) {
5373
+ addToBatch(item);
5374
+ } else if (i === 0) {
5375
+ flushBatch();
5376
+ addToBatch(item);
5377
+ } else {
5378
+ break;
5379
+ }
5380
+ ++i;
5381
+ }
5382
+ if (i < bucket.length) {
5383
+ nextItems.push(bucket.slice(i));
5384
+ }
5385
+ if (batchLen >= batchMaxNumBytes || batch.length > batchMaxNumItems) {
5386
+ flushBatch();
5387
+ }
5388
+ }
5389
+ if (batch.length) {
5390
+ flushBatch();
5391
+ }
5392
+ if (batchSet.length) {
5393
+ output.push(batchSet);
5394
+ batchSet = [];
5395
+ }
5396
+ items = nextItems;
5397
+ nextItems = [];
5398
+ }
5399
+ return output;
5400
+ }
5401
+ var DEFAULT_IS_LEGACY_DATASET = true;
5402
+ function ensureDatasetRecord(r, legacy) {
5403
+ if (legacy) {
5404
+ return ensureLegacyDatasetRecord(r);
5405
+ } else {
5406
+ return ensureNewDatasetRecord(r);
5407
+ }
5408
+ }
5409
+ function ensureLegacyDatasetRecord(r) {
5410
+ if ("output" in r) {
5411
+ return r;
5412
+ }
5413
+ const row = {
5414
+ ...r,
5415
+ output: r.expected
5416
+ };
5417
+ delete row.expected;
5418
+ return row;
5419
+ }
5420
+ function ensureNewDatasetRecord(r) {
5421
+ if ("expected" in r) {
5422
+ return r;
5423
+ }
5424
+ const row = {
5425
+ ...r,
5426
+ tags: null,
5427
+ expected: r.output
5428
+ };
5429
+ delete row.output;
5430
+ return row;
5431
+ }
5432
+ function makeLegacyEvent(e) {
5433
+ if (!("dataset_id" in e) || !("expected" in e)) {
5434
+ return e;
5435
+ }
5436
+ const event = {
5437
+ ...e,
5438
+ output: e.expected
5439
+ };
5440
+ delete event.expected;
5441
+ if (MERGE_PATHS_FIELD in event) {
5442
+ for (const path of event[MERGE_PATHS_FIELD] || []) {
5443
+ if (path.length > 0 && path[0] === "expected") {
5444
+ path[0] = "output";
5445
+ }
5446
+ }
5447
+ }
5448
+ return event;
5449
+ }
5450
+ function tryMakeUuid(s) {
5451
+ try {
5452
+ const ret = parse_default(s);
5453
+ if (ret.length !== 16) {
5454
+ throw new Error();
5455
+ }
5456
+ return { bytes: Buffer.from(ret), isUUID: true };
5457
+ } catch (e) {
5458
+ return { bytes: Buffer.from(s, "utf-8"), isUUID: false };
5459
+ }
5460
+ }
5461
+ var ENCODING_VERSION_NUMBER = 1;
5462
+ var INVALID_ENCODING_ERRMSG = "SpanComponents string is not properly encoded. This may be due to a version mismatch between the SDK library used to export the span and the library used to decode it. Please make sure you are using the same SDK version across the board";
5463
+ var SpanObjectType = /* @__PURE__ */ ((SpanObjectType2) => {
5464
+ SpanObjectType2[SpanObjectType2["EXPERIMENT"] = 0] = "EXPERIMENT";
5465
+ SpanObjectType2[SpanObjectType2["PROJECT_LOGS"] = 1] = "PROJECT_LOGS";
5466
+ return SpanObjectType2;
5467
+ })(SpanObjectType || {});
5468
+ var SpanObjectTypeEnumSchema = z.nativeEnum(SpanObjectType);
5469
+ var SpanRowIds = class {
5470
+ constructor(args) {
5471
+ this.rowId = args.rowId;
5472
+ this.spanId = args.spanId;
5473
+ this.rootSpanId = args.rootSpanId;
5474
+ if (!this.rowId) {
5475
+ throw new Error("rowId must be nonempty string");
5476
+ }
5477
+ if (!this.spanId) {
5478
+ throw new Error("spanId must be nonempty string");
5479
+ }
5480
+ if (!this.rootSpanId) {
5481
+ throw new Error("rootSpanId must be nonempty string");
5482
+ }
5483
+ }
5484
+ toObject() {
5485
+ return {
5486
+ rowId: this.rowId,
5487
+ spanId: this.spanId,
5488
+ rootSpanId: this.rootSpanId
5489
+ };
5490
+ }
5491
+ };
5492
+ var SpanComponents = class _SpanComponents {
5493
+ constructor(args) {
5494
+ this.objectType = args.objectType;
5495
+ this.objectId = args.objectId;
5496
+ this.rowIds = args.rowIds;
5497
+ }
5498
+ toStr() {
5499
+ const allBuffers = [];
5500
+ const { bytes: rowIdBytes, isUUID: rowIdIsUUID } = this.rowIds ? tryMakeUuid(this.rowIds.rowId) : { bytes: Buffer.from(""), isUUID: false };
5501
+ allBuffers.push(
5502
+ Buffer.from([
5503
+ ENCODING_VERSION_NUMBER,
5504
+ this.objectType,
5505
+ this.rowIds ? 1 : 0,
5506
+ rowIdIsUUID ? 1 : 0
5507
+ ])
5508
+ );
5509
+ const { bytes: objectIdBytes, isUUID: objectIdIsUUID } = tryMakeUuid(
5510
+ this.objectId
5511
+ );
5512
+ if (!objectIdIsUUID) {
5513
+ throw new Error("object_id component must be a valid UUID");
5514
+ }
5515
+ allBuffers.push(objectIdBytes);
5516
+ if (this.rowIds) {
5517
+ const { bytes: spanIdBytes, isUUID: spanIdIsUUID } = tryMakeUuid(
5518
+ this.rowIds.spanId
5519
+ );
5520
+ if (!spanIdIsUUID) {
5521
+ throw new Error("span_id component must be a valid UUID");
5522
+ }
5523
+ const { bytes: rootSpanIdBytes, isUUID: rootSpanIdIsUUID } = tryMakeUuid(
5524
+ this.rowIds.rootSpanId
5525
+ );
5526
+ if (!rootSpanIdIsUUID) {
5527
+ throw new Error("root_span_id component must be a valid UUID");
5528
+ }
5529
+ allBuffers.push(spanIdBytes, rootSpanIdBytes, rowIdBytes);
5530
+ }
5531
+ return Buffer.concat(allBuffers).toString("base64");
5532
+ }
5533
+ static fromStr(s) {
5534
+ try {
5535
+ const rawBytes = Buffer.from(s, "base64");
5536
+ if (rawBytes[0] !== ENCODING_VERSION_NUMBER) {
5537
+ throw new Error();
5538
+ }
5539
+ const objectType2 = SpanObjectTypeEnumSchema.parse(rawBytes[1]);
5540
+ if (![0, 1].includes(rawBytes[2])) {
5541
+ throw new Error();
5542
+ }
5543
+ if (![0, 1].includes(rawBytes[3])) {
5544
+ throw new Error();
5545
+ }
5546
+ const hasRowId = rawBytes[2] == 1;
5547
+ const rowIdIsUUID = rawBytes[3] == 1;
5548
+ const objectId = stringify_default(rawBytes.subarray(4, 20));
5549
+ const rowIds = (() => {
5550
+ if (!hasRowId) {
5551
+ return void 0;
5552
+ }
5553
+ const spanId = stringify_default(rawBytes.subarray(20, 36));
5554
+ const rootSpanId = stringify_default(rawBytes.subarray(36, 52));
5555
+ const rowId = rowIdIsUUID ? stringify_default(rawBytes.subarray(52)) : rawBytes.subarray(52).toString("utf-8");
5556
+ return new SpanRowIds({ rowId, spanId, rootSpanId });
5557
+ })();
5558
+ return new _SpanComponents({ objectType: objectType2, objectId, rowIds });
5559
+ } catch (e) {
5560
+ throw new Error(INVALID_ENCODING_ERRMSG);
5561
+ }
5562
+ }
5563
+ objectIdFields() {
5564
+ switch (this.objectType) {
5565
+ case 0:
5566
+ return { experiment_id: this.objectId };
5567
+ case 1:
5568
+ return { project_id: this.objectId, log_id: "g" };
5569
+ default:
5570
+ throw new Error("Impossible");
5571
+ }
5572
+ }
5573
+ toObject() {
5574
+ var _a2;
5575
+ return {
5576
+ objectType: this.objectType,
5577
+ objectId: this.objectId,
5578
+ rowIds: (_a2 = this.rowIds) == null ? void 0 : _a2.toObject()
5579
+ };
5580
+ }
5581
+ };
5582
+ var SpanTypeAttribute = /* @__PURE__ */ ((SpanTypeAttribute2) => {
5583
+ SpanTypeAttribute2["LLM"] = "llm";
5584
+ SpanTypeAttribute2["SCORE"] = "score";
5585
+ SpanTypeAttribute2["FUNCTION"] = "function";
5586
+ SpanTypeAttribute2["EVAL"] = "eval";
5587
+ SpanTypeAttribute2["TASK"] = "task";
5588
+ SpanTypeAttribute2["TOOL"] = "tool";
5589
+ return SpanTypeAttribute2;
5590
+ })(SpanTypeAttribute || {});
5591
+ function mergeGitMetadataSettings(s1, s2) {
5592
+ var _a2;
5593
+ if (s1.collect === "all") {
5594
+ return s2;
5595
+ } else if (s2.collect === "all") {
5596
+ return s1;
5597
+ } else if (s1.collect === "none") {
5598
+ return s1;
5599
+ } else if (s2.collect === "none") {
5600
+ return s2;
5601
+ }
5602
+ const fields = ((_a2 = s1.fields) != null ? _a2 : []).filter((f) => {
5603
+ var _a22;
5604
+ return ((_a22 = s2.fields) != null ? _a22 : []).includes(f);
5605
+ });
5606
+ const collect = fields.length > 0 ? "some" : "none";
5607
+ return { collect, fields };
5608
+ }
5609
+ var TOP_BITS = BigInt("0x0DE1") << BigInt(48);
5610
+ var MOD = BigInt(1) << BigInt(64);
5611
+ var COPRIME = BigInt("205891132094649");
5612
+ var COPRIME_INVERSE = BigInt("1522336535492693385");
5522
5613
 
5523
5614
  // ../core/js/typespecs/dist/index.mjs
5615
+ var import_zod_to_openapi = __toESM(require_dist(), 1);
5524
5616
  var import_zod_to_openapi2 = __toESM(require_dist(), 1);
5525
5617
  var import_zod_to_openapi3 = __toESM(require_dist(), 1);
5526
5618
  var literalSchema = z.union([
@@ -6999,7 +7091,7 @@ Writer.prototype.clearCache = function clearCache() {
6999
7091
  this.templateCache.clear();
7000
7092
  }
7001
7093
  };
7002
- Writer.prototype.parse = function parse(template, tags) {
7094
+ Writer.prototype.parse = function parse2(template, tags) {
7003
7095
  var cache = this.templateCache;
7004
7096
  var cacheKey = template + ":" + (tags || mustache.tags).join(":");
7005
7097
  var isCacheEnabled = typeof cache !== "undefined";
@@ -7158,7 +7250,7 @@ var defaultWriter = new Writer();
7158
7250
  mustache.clearCache = function clearCache2() {
7159
7251
  return defaultWriter.clearCache();
7160
7252
  };
7161
- mustache.parse = function parse2(template, tags) {
7253
+ mustache.parse = function parse3(template, tags) {
7162
7254
  return defaultWriter.parse(template, tags);
7163
7255
  };
7164
7256
  mustache.render = function render2(template, view, partials, config) {
@@ -7431,11 +7523,10 @@ function logFeedbackImpl(parentObjectType, parentObjectId, {
7431
7523
  updateEvent = Object.fromEntries(
7432
7524
  Object.entries(updateEvent).filter(([_, v]) => !isEmpty(v))
7433
7525
  );
7434
- const parentIds = async () => new SpanParentComponents({
7526
+ const parentIds = async () => new SpanComponents({
7435
7527
  objectType: parentObjectType,
7436
- objectId: await parentObjectId.get(),
7437
- rowId: ""
7438
- }).asDict();
7528
+ objectId: await parentObjectId.get()
7529
+ }).objectIdFields();
7439
7530
  if (Object.keys(updateEvent).length > 0) {
7440
7531
  const record = new LazyValue(async () => {
7441
7532
  return {
@@ -7471,38 +7562,41 @@ function logFeedbackImpl(parentObjectType, parentObjectId, {
7471
7562
  }
7472
7563
  }
7473
7564
  function startSpanParentArgs(args) {
7474
- if (args.parent && args.parentId) {
7475
- throw new Error(
7476
- "Cannot specify both `parent` and `parentId`. Prefer `parent"
7477
- );
7478
- }
7479
- let parentObjectId = void 0;
7480
- let parentRowId = void 0;
7565
+ let argParentObjectId = void 0;
7566
+ let argParentSpanIds = void 0;
7481
7567
  if (args.parent) {
7482
- const parentComponents = SpanParentComponents.fromStr(args.parent);
7483
- if (args.spanParentObjectType !== parentComponents.objectType) {
7568
+ if (args.parentSpanIds) {
7569
+ throw new Error("Cannot specify both parent and parentSpanIds");
7570
+ }
7571
+ const parentComponents = SpanComponents.fromStr(args.parent);
7572
+ if (args.parentObjectType !== parentComponents.objectType) {
7484
7573
  throw new Error(
7485
- `Mismatch between expected span parent object type ${args.spanParentObjectType} and provided type ${parentComponents.objectType}`
7574
+ `Mismatch between expected span parent object type ${args.parentObjectType} and provided type ${parentComponents.objectType}`
7486
7575
  );
7487
7576
  }
7488
7577
  const computeParentObjectId = async () => {
7489
- if (await args.spanParentObjectId.get() !== parentComponents.objectId) {
7578
+ if (await args.parentObjectId.get() !== parentComponents.objectId) {
7490
7579
  throw new Error(
7491
- `Mismatch between expected span parent object id ${await args.spanParentObjectId.get()} and provided id ${parentComponents.objectId}`
7580
+ `Mismatch between expected span parent object id ${await args.parentObjectId.get()} and provided id ${parentComponents.objectId}`
7492
7581
  );
7493
7582
  }
7494
- return await args.spanParentObjectId.get();
7583
+ return await args.parentObjectId.get();
7495
7584
  };
7496
- parentObjectId = new LazyValue(computeParentObjectId);
7497
- parentRowId = parentComponents.rowId;
7585
+ argParentObjectId = new LazyValue(computeParentObjectId);
7586
+ if (parentComponents.rowIds) {
7587
+ argParentSpanIds = {
7588
+ spanId: parentComponents.rowIds.spanId,
7589
+ rootSpanId: parentComponents.rowIds.rootSpanId
7590
+ };
7591
+ }
7498
7592
  } else {
7499
- parentObjectId = args.spanParentObjectId;
7500
- parentRowId = args.parentId ?? "";
7593
+ argParentObjectId = args.parentObjectId;
7594
+ argParentSpanIds = args.parentSpanIds;
7501
7595
  }
7502
7596
  return {
7503
- parentObjectType: args.spanParentObjectType,
7504
- parentObjectId,
7505
- parentRowId
7597
+ parentObjectType: args.parentObjectType,
7598
+ parentObjectId: argParentObjectId,
7599
+ parentSpanIds: argParentSpanIds
7506
7600
  };
7507
7601
  }
7508
7602
  var Logger = class {
@@ -7533,12 +7627,8 @@ var Logger = class {
7533
7627
  get id() {
7534
7628
  return (async () => (await this.project).id)();
7535
7629
  }
7536
- spanParentObjectType() {
7537
- return SpanParentObjectType.PROJECT_LOGS;
7538
- }
7539
- async getState() {
7540
- await this.lazyMetadata.get();
7541
- return _state;
7630
+ parentObjectType() {
7631
+ return SpanObjectType.PROJECT_LOGS;
7542
7632
  }
7543
7633
  /**
7544
7634
  * Log a single event. The event will be batched and uploaded behind the scenes if `logOptions.asyncFlush` is true.
@@ -7616,9 +7706,9 @@ var Logger = class {
7616
7706
  return new SpanImpl({
7617
7707
  ...startSpanParentArgs({
7618
7708
  parent: args?.parent,
7619
- parentId: args?.parentId,
7620
- spanParentObjectType: this.spanParentObjectType(),
7621
- spanParentObjectId: this.lazyId
7709
+ parentObjectType: this.parentObjectType(),
7710
+ parentObjectId: this.lazyId,
7711
+ parentSpanIds: void 0
7622
7712
  }),
7623
7713
  ...args,
7624
7714
  defaultRootType: SpanTypeAttribute.TASK
@@ -7636,16 +7726,15 @@ var Logger = class {
7636
7726
  * @param event.source (Optional) the source of the feedback. Must be one of "external" (default), "app", or "api".
7637
7727
  */
7638
7728
  logFeedback(event) {
7639
- logFeedbackImpl(this.spanParentObjectType(), this.lazyId, event);
7729
+ logFeedbackImpl(this.parentObjectType(), this.lazyId, event);
7640
7730
  }
7641
7731
  /**
7642
7732
  * Return a serialized representation of the logger that can be used to start subspans in other places. See `Span.start_span` for more details.
7643
7733
  */
7644
7734
  async export() {
7645
- return new SpanParentComponents({
7646
- objectType: this.spanParentObjectType(),
7647
- objectId: await this.id,
7648
- rowId: ""
7735
+ return new SpanComponents({
7736
+ objectType: this.parentObjectType(),
7737
+ objectId: await this.id
7649
7738
  }).toStr();
7650
7739
  }
7651
7740
  /*
@@ -8355,21 +8444,20 @@ async function flush() {
8355
8444
  }
8356
8445
  function startSpanAndIsLogger(args) {
8357
8446
  if (args?.parent) {
8358
- if (args?.parentId) {
8359
- throw new Error(
8360
- "Cannot specify both `parent` and `parent_id`. Prefer `parent`"
8361
- );
8362
- }
8363
- const components = SpanParentComponents.fromStr(args?.parent);
8447
+ const components = SpanComponents.fromStr(args?.parent);
8448
+ const parentSpanIds = components.rowIds ? {
8449
+ spanId: components.rowIds.spanId,
8450
+ rootSpanId: components.rowIds.rootSpanId
8451
+ } : void 0;
8364
8452
  const span = new SpanImpl({
8365
8453
  ...args,
8366
8454
  parentObjectType: components.objectType,
8367
8455
  parentObjectId: new LazyValue(async () => components.objectId),
8368
- parentRowId: components.rowId
8456
+ parentSpanIds
8369
8457
  });
8370
8458
  return {
8371
8459
  span,
8372
- isLogger: components.objectType === SpanParentObjectType.PROJECT_LOGS
8460
+ isLogger: components.objectType === SpanObjectType.PROJECT_LOGS
8373
8461
  };
8374
8462
  } else {
8375
8463
  const parentObject = getSpanParentObject({
@@ -8576,8 +8664,8 @@ var Experiment = class extends ObjectFetcher {
8576
8664
  return (await this.lazyMetadata.get()).project;
8577
8665
  })();
8578
8666
  }
8579
- spanParentObjectType() {
8580
- return SpanParentObjectType.EXPERIMENT;
8667
+ parentObjectType() {
8668
+ return SpanObjectType.EXPERIMENT;
8581
8669
  }
8582
8670
  async getState() {
8583
8671
  await this.lazyMetadata.get();
@@ -8645,9 +8733,9 @@ var Experiment = class extends ObjectFetcher {
8645
8733
  return new SpanImpl({
8646
8734
  ...startSpanParentArgs({
8647
8735
  parent: args?.parent,
8648
- parentId: args?.parentId,
8649
- spanParentObjectType: this.spanParentObjectType(),
8650
- spanParentObjectId: this.lazyId
8736
+ parentObjectType: this.parentObjectType(),
8737
+ parentObjectId: this.lazyId,
8738
+ parentSpanIds: void 0
8651
8739
  }),
8652
8740
  ...args,
8653
8741
  defaultRootType: SpanTypeAttribute.EVAL
@@ -8737,16 +8825,15 @@ var Experiment = class extends ObjectFetcher {
8737
8825
  * @param event.source (Optional) the source of the feedback. Must be one of "external" (default), "app", or "api".
8738
8826
  */
8739
8827
  logFeedback(event) {
8740
- logFeedbackImpl(this.spanParentObjectType(), this.lazyId, event);
8828
+ logFeedbackImpl(this.parentObjectType(), this.lazyId, event);
8741
8829
  }
8742
8830
  /**
8743
8831
  * Return a serialized representation of the experiment that can be used to start subspans in other places. See `Span.start_span` for more details.
8744
8832
  */
8745
8833
  async export() {
8746
- return new SpanParentComponents({
8747
- objectType: this.spanParentObjectType(),
8748
- objectId: await this.id,
8749
- rowId: ""
8834
+ return new SpanComponents({
8835
+ objectType: this.parentObjectType(),
8836
+ objectId: await this.id
8750
8837
  }).toStr();
8751
8838
  }
8752
8839
  /**
@@ -8817,22 +8904,23 @@ var SpanImpl = class _SpanImpl {
8817
8904
  // For internal use only.
8818
8905
  parentObjectType;
8819
8906
  parentObjectId;
8820
- parentRowId;
8821
8907
  _id;
8908
+ spanId;
8909
+ rootSpanId;
8910
+ spanParents;
8822
8911
  kind = "span";
8823
8912
  constructor(args) {
8824
8913
  const spanAttributes = args.spanAttributes ?? {};
8825
8914
  const event = args.event ?? {};
8826
- const type = args.type ?? (args.parentRowId ? void 0 : args.defaultRootType);
8915
+ const type = args.type ?? (args.parentSpanIds ? void 0 : args.defaultRootType);
8827
8916
  this.loggedEndTime = void 0;
8828
8917
  this.parentObjectType = args.parentObjectType;
8829
8918
  this.parentObjectId = args.parentObjectId;
8830
- this.parentRowId = args.parentRowId;
8831
8919
  const callerLocation = isomorph_default.getCallerLocation();
8832
8920
  const name = (() => {
8833
8921
  if (args.name)
8834
8922
  return args.name;
8835
- if (!args.parentRowId)
8923
+ if (!args.parentSpanIds)
8836
8924
  return "root";
8837
8925
  if (callerLocation) {
8838
8926
  const pathComponents = callerLocation.caller_filename.split("/");
@@ -8857,6 +8945,14 @@ var SpanImpl = class _SpanImpl {
8857
8945
  created: (/* @__PURE__ */ new Date()).toISOString()
8858
8946
  };
8859
8947
  this._id = event.id ?? v4_default();
8948
+ this.spanId = v4_default();
8949
+ if (args.parentSpanIds) {
8950
+ this.rootSpanId = args.parentSpanIds.rootSpanId;
8951
+ this.spanParents = [args.parentSpanIds.spanId];
8952
+ } else {
8953
+ this.rootSpanId = this.spanId;
8954
+ this.spanParents = void 0;
8955
+ }
8860
8956
  this.isMerge = false;
8861
8957
  const { id: _id, ...eventRest } = event;
8862
8958
  this.log(eventRest);
@@ -8871,6 +8967,10 @@ var SpanImpl = class _SpanImpl {
8871
8967
  mergeDicts(sanitizedAndInternalData, sanitized);
8872
8968
  this.internalData = {};
8873
8969
  let partialRecord = {
8970
+ id: this.id,
8971
+ span_id: this.spanId,
8972
+ root_span_id: this.rootSpanId,
8973
+ span_parents: this.spanParents,
8874
8974
  ...sanitizedAndInternalData,
8875
8975
  [IS_MERGE_FIELD]: this.isMerge
8876
8976
  };
@@ -8879,17 +8979,15 @@ var SpanImpl = class _SpanImpl {
8879
8979
  if (partialRecord.metrics?.end) {
8880
8980
  this.loggedEndTime = partialRecord.metrics?.end;
8881
8981
  }
8882
- if ((partialRecord.tags ?? []).length > 0 && this.parentRowId) {
8982
+ if ((partialRecord.tags ?? []).length > 0 && this.spanParents?.length) {
8883
8983
  throw new Error("Tags can only be logged to the root span");
8884
8984
  }
8885
8985
  const computeRecord = async () => ({
8886
8986
  ...partialRecord,
8887
- ...new SpanParentComponents({
8987
+ ...new SpanComponents({
8888
8988
  objectType: this.parentObjectType,
8889
- objectId: await this.parentObjectId.get(),
8890
- rowId: this.parentRowId
8891
- }).asDict(),
8892
- id: this.id
8989
+ objectId: await this.parentObjectId.get()
8990
+ }).objectIdFields()
8893
8991
  });
8894
8992
  _state.globalBgLogger().log([new LazyValue(computeRecord)]);
8895
8993
  }
@@ -8914,13 +9012,14 @@ var SpanImpl = class _SpanImpl {
8914
9012
  );
8915
9013
  }
8916
9014
  startSpan(args) {
9015
+ const parentSpanIds = args?.parent ? void 0 : { spanId: this.spanId, rootSpanId: this.rootSpanId };
8917
9016
  return new _SpanImpl({
8918
9017
  ...args,
8919
9018
  ...startSpanParentArgs({
8920
9019
  parent: args?.parent,
8921
- parentId: args?.parentId ?? (args?.parent ? void 0 : this.id),
8922
- spanParentObjectType: this.parentObjectType,
8923
- spanParentObjectId: this.parentObjectId
9020
+ parentObjectType: this.parentObjectType,
9021
+ parentObjectId: this.parentObjectId,
9022
+ parentSpanIds
8924
9023
  })
8925
9024
  });
8926
9025
  }
@@ -8936,10 +9035,14 @@ var SpanImpl = class _SpanImpl {
8936
9035
  return endTime;
8937
9036
  }
8938
9037
  async export() {
8939
- return new SpanParentComponents({
9038
+ return new SpanComponents({
8940
9039
  objectType: this.parentObjectType,
8941
9040
  objectId: await this.parentObjectId.get(),
8942
- rowId: this.id
9041
+ rowIds: new SpanRowIds({
9042
+ rowId: this.id,
9043
+ spanId: this.spanId,
9044
+ rootSpanId: this.rootSpanId
9045
+ })
8943
9046
  }).toStr();
8944
9047
  }
8945
9048
  async flush() {
@@ -8964,9 +9067,6 @@ var Dataset = class extends ObjectFetcher {
8964
9067
  (r) => ensureDatasetRecord(r, isLegacyDataset)
8965
9068
  );
8966
9069
  this.lazyMetadata = lazyMetadata;
8967
- const logConn = new LazyValue(
8968
- () => this.getState().then((state) => state.logConn())
8969
- );
8970
9070
  }
8971
9071
  get id() {
8972
9072
  return (async () => {