langsmith 0.1.51 → 0.1.53

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/client.cjs CHANGED
@@ -33,6 +33,8 @@ const _uuid_js_1 = require("./utils/_uuid.cjs");
33
33
  const warn_js_1 = require("./utils/warn.cjs");
34
34
  const prompts_js_1 = require("./utils/prompts.cjs");
35
35
  const error_js_1 = require("./utils/error.cjs");
36
+ const serde_js_1 = require("./utils/serde.cjs");
37
+ const fetch_js_1 = require("./singletons/fetch.cjs");
36
38
  async function mergeRuntimeEnvIntoRunCreates(runs) {
37
39
  const runtimeEnv = await (0, env_js_1.getRuntimeEnvironment)();
38
40
  const envVars = (0, env_js_1.getLangChainEnvVarsMetadata)();
@@ -374,7 +376,7 @@ class Client {
374
376
  async _getResponse(path, queryParams) {
375
377
  const paramsString = queryParams?.toString() ?? "";
376
378
  const url = `${this.apiUrl}${path}?${paramsString}`;
377
- const response = await this.caller.call(fetch, url, {
379
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), url, {
378
380
  method: "GET",
379
381
  headers: this.headers,
380
382
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -394,7 +396,7 @@ class Client {
394
396
  queryParams.set("offset", String(offset));
395
397
  queryParams.set("limit", String(limit));
396
398
  const url = `${this.apiUrl}${path}?${queryParams}`;
397
- const response = await this.caller.call(fetch, url, {
399
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), url, {
398
400
  method: "GET",
399
401
  headers: this.headers,
400
402
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -417,7 +419,7 @@ class Client {
417
419
  async *_getCursorPaginatedList(path, body = null, requestMethod = "POST", dataKey = "runs") {
418
420
  const bodyParams = body ? { ...body } : {};
419
421
  while (true) {
420
- const response = await this.caller.call(fetch, `${this.apiUrl}${path}`, {
422
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}${path}`, {
421
423
  method: requestMethod,
422
424
  headers: { ...this.headers, "Content-Type": "application/json" },
423
425
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -517,7 +519,7 @@ class Client {
517
519
  return itemPromise;
518
520
  }
519
521
  async _getServerInfo() {
520
- const response = await fetch(`${this.apiUrl}/info`, {
522
+ const response = await (0, fetch_js_1._getFetchImplementation)()(`${this.apiUrl}/info`, {
521
523
  method: "GET",
522
524
  headers: { Accept: "application/json" },
523
525
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -565,10 +567,10 @@ class Client {
565
567
  const mergedRunCreateParams = await mergeRuntimeEnvIntoRunCreates([
566
568
  runCreate,
567
569
  ]);
568
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs`, {
570
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs`, {
569
571
  method: "POST",
570
572
  headers,
571
- body: JSON.stringify(mergedRunCreateParams[0]),
573
+ body: (0, serde_js_1.stringifyForTracing)(mergedRunCreateParams[0]),
572
574
  signal: AbortSignal.timeout(this.timeout_ms),
573
575
  ...this.fetchOptions,
574
576
  });
@@ -642,10 +644,10 @@ class Client {
642
644
  const batchItems = rawBatch[key].reverse();
643
645
  let batchItem = batchItems.pop();
644
646
  while (batchItem !== undefined) {
645
- const stringifiedBatchItem = JSON.stringify(batchItem);
647
+ const stringifiedBatchItem = (0, serde_js_1.stringifyForTracing)(batchItem);
646
648
  if (currentBatchSizeBytes > 0 &&
647
649
  currentBatchSizeBytes + stringifiedBatchItem.length > sizeLimitBytes) {
648
- await this._postBatchIngestRuns(JSON.stringify(batchChunks));
650
+ await this._postBatchIngestRuns((0, serde_js_1.stringifyForTracing)(batchChunks));
649
651
  currentBatchSizeBytes = 0;
650
652
  batchChunks.post = [];
651
653
  batchChunks.patch = [];
@@ -656,7 +658,7 @@ class Client {
656
658
  }
657
659
  }
658
660
  if (batchChunks.post.length > 0 || batchChunks.patch.length > 0) {
659
- await this._postBatchIngestRuns(JSON.stringify(batchChunks));
661
+ await this._postBatchIngestRuns((0, serde_js_1.stringifyForTracing)(batchChunks));
660
662
  }
661
663
  }
662
664
  async _postBatchIngestRuns(body) {
@@ -665,7 +667,7 @@ class Client {
665
667
  "Content-Type": "application/json",
666
668
  Accept: "application/json",
667
669
  };
668
- const response = await this.batchIngestCaller.call(fetch, `${this.apiUrl}/runs/batch`, {
670
+ const response = await this.batchIngestCaller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs/batch`, {
669
671
  method: "POST",
670
672
  headers,
671
673
  body: body,
@@ -702,10 +704,10 @@ class Client {
702
704
  return;
703
705
  }
704
706
  const headers = { ...this.headers, "Content-Type": "application/json" };
705
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}`, {
707
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs/${runId}`, {
706
708
  method: "PATCH",
707
709
  headers,
708
- body: JSON.stringify(run),
710
+ body: (0, serde_js_1.stringifyForTracing)(run),
709
711
  signal: AbortSignal.timeout(this.timeout_ms),
710
712
  ...this.fetchOptions,
711
713
  });
@@ -965,7 +967,7 @@ class Client {
965
967
  };
966
968
  // Remove undefined values from the payload
967
969
  const filteredPayload = Object.fromEntries(Object.entries(payload).filter(([_, value]) => value !== undefined));
968
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/stats`, {
970
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs/stats`, {
969
971
  method: "POST",
970
972
  headers: this.headers,
971
973
  body: JSON.stringify(filteredPayload),
@@ -981,7 +983,7 @@ class Client {
981
983
  share_token: shareId || uuid.v4(),
982
984
  };
983
985
  (0, _uuid_js_1.assertUuid)(runId);
984
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}/share`, {
986
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs/${runId}/share`, {
985
987
  method: "PUT",
986
988
  headers: this.headers,
987
989
  body: JSON.stringify(data),
@@ -996,7 +998,7 @@ class Client {
996
998
  }
997
999
  async unshareRun(runId) {
998
1000
  (0, _uuid_js_1.assertUuid)(runId);
999
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}/share`, {
1001
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs/${runId}/share`, {
1000
1002
  method: "DELETE",
1001
1003
  headers: this.headers,
1002
1004
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1006,7 +1008,7 @@ class Client {
1006
1008
  }
1007
1009
  async readRunSharedLink(runId) {
1008
1010
  (0, _uuid_js_1.assertUuid)(runId);
1009
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}/share`, {
1011
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/runs/${runId}/share`, {
1010
1012
  method: "GET",
1011
1013
  headers: this.headers,
1012
1014
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1028,7 +1030,7 @@ class Client {
1028
1030
  }
1029
1031
  }
1030
1032
  (0, _uuid_js_1.assertUuid)(shareToken);
1031
- const response = await this.caller.call(fetch, `${this.apiUrl}/public/${shareToken}/runs${queryParams}`, {
1033
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/public/${shareToken}/runs${queryParams}`, {
1032
1034
  method: "GET",
1033
1035
  headers: this.headers,
1034
1036
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1046,7 +1048,7 @@ class Client {
1046
1048
  datasetId = dataset.id;
1047
1049
  }
1048
1050
  (0, _uuid_js_1.assertUuid)(datasetId);
1049
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/share`, {
1051
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/datasets/${datasetId}/share`, {
1050
1052
  method: "GET",
1051
1053
  headers: this.headers,
1052
1054
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1068,7 +1070,7 @@ class Client {
1068
1070
  dataset_id: datasetId,
1069
1071
  };
1070
1072
  (0, _uuid_js_1.assertUuid)(datasetId);
1071
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/share`, {
1073
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/datasets/${datasetId}/share`, {
1072
1074
  method: "PUT",
1073
1075
  headers: this.headers,
1074
1076
  body: JSON.stringify(data),
@@ -1081,7 +1083,7 @@ class Client {
1081
1083
  }
1082
1084
  async unshareDataset(datasetId) {
1083
1085
  (0, _uuid_js_1.assertUuid)(datasetId);
1084
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/share`, {
1086
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/datasets/${datasetId}/share`, {
1085
1087
  method: "DELETE",
1086
1088
  headers: this.headers,
1087
1089
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1091,7 +1093,7 @@ class Client {
1091
1093
  }
1092
1094
  async readSharedDataset(shareToken) {
1093
1095
  (0, _uuid_js_1.assertUuid)(shareToken);
1094
- const response = await this.caller.call(fetch, `${this.apiUrl}/public/${shareToken}/datasets`, {
1096
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/public/${shareToken}/datasets`, {
1095
1097
  method: "GET",
1096
1098
  headers: this.headers,
1097
1099
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1122,7 +1124,7 @@ class Client {
1122
1124
  urlParams.append(key, value);
1123
1125
  }
1124
1126
  });
1125
- const response = await this.caller.call(fetch, `${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
1127
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
1126
1128
  method: "GET",
1127
1129
  headers: this.headers,
1128
1130
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1155,7 +1157,7 @@ class Client {
1155
1157
  if (referenceDatasetId !== null) {
1156
1158
  body["reference_dataset_id"] = referenceDatasetId;
1157
1159
  }
1158
- const response = await this.caller.call(fetch, endpoint, {
1160
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), endpoint, {
1159
1161
  method: "POST",
1160
1162
  headers: { ...this.headers, "Content-Type": "application/json" },
1161
1163
  body: JSON.stringify(body),
@@ -1178,7 +1180,7 @@ class Client {
1178
1180
  description,
1179
1181
  end_time: endTime ? new Date(endTime).toISOString() : null,
1180
1182
  };
1181
- const response = await this.caller.call(fetch, endpoint, {
1183
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), endpoint, {
1182
1184
  method: "PATCH",
1183
1185
  headers: { ...this.headers, "Content-Type": "application/json" },
1184
1186
  body: JSON.stringify(body),
@@ -1206,7 +1208,7 @@ class Client {
1206
1208
  else {
1207
1209
  throw new Error("Must provide projectName or projectId");
1208
1210
  }
1209
- const response = await this.caller.call(fetch, `${this.apiUrl}${path}?${params}`, {
1211
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}${path}?${params}`, {
1210
1212
  method: "GET",
1211
1213
  headers: this.headers,
1212
1214
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1336,7 +1338,7 @@ class Client {
1336
1338
  projectId_ = projectId;
1337
1339
  }
1338
1340
  (0, _uuid_js_1.assertUuid)(projectId_);
1339
- const response = await this.caller.call(fetch, `${this.apiUrl}/sessions/${projectId_}`, {
1341
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/sessions/${projectId_}`, {
1340
1342
  method: "DELETE",
1341
1343
  headers: this.headers,
1342
1344
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1363,7 +1365,7 @@ class Client {
1363
1365
  if (name) {
1364
1366
  formData.append("name", name);
1365
1367
  }
1366
- const response = await this.caller.call(fetch, url, {
1368
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), url, {
1367
1369
  method: "POST",
1368
1370
  headers: this.headers,
1369
1371
  body: formData,
@@ -1389,7 +1391,7 @@ class Client {
1389
1391
  if (outputsSchema) {
1390
1392
  body.outputs_schema_definition = outputsSchema;
1391
1393
  }
1392
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets`, {
1394
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/datasets`, {
1393
1395
  method: "POST",
1394
1396
  headers: { ...this.headers, "Content-Type": "application/json" },
1395
1397
  body: JSON.stringify(body),
@@ -1521,7 +1523,7 @@ class Client {
1521
1523
  }
1522
1524
  const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
1523
1525
  (0, _uuid_js_1.assertUuid)(_datasetId);
1524
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${_datasetId}`, {
1526
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/datasets/${_datasetId}`, {
1525
1527
  method: "PATCH",
1526
1528
  headers: { ...this.headers, "Content-Type": "application/json" },
1527
1529
  body: JSON.stringify(update),
@@ -1548,7 +1550,7 @@ class Client {
1548
1550
  else {
1549
1551
  throw new Error("Must provide datasetName or datasetId");
1550
1552
  }
1551
- const response = await this.caller.call(fetch, this.apiUrl + path, {
1553
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), this.apiUrl + path, {
1552
1554
  method: "DELETE",
1553
1555
  headers: this.headers,
1554
1556
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1573,7 +1575,7 @@ class Client {
1573
1575
  const data = {
1574
1576
  tag: tag,
1575
1577
  };
1576
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId_}/index`, {
1578
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/datasets/${datasetId_}/index`, {
1577
1579
  method: "POST",
1578
1580
  headers: { ...this.headers, "Content-Type": "application/json" },
1579
1581
  body: JSON.stringify(data),
@@ -1622,7 +1624,7 @@ class Client {
1622
1624
  data["filter"] = filter;
1623
1625
  }
1624
1626
  (0, _uuid_js_1.assertUuid)(datasetId);
1625
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/search`, {
1627
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/datasets/${datasetId}/search`, {
1626
1628
  method: "POST",
1627
1629
  headers: { ...this.headers, "Content-Type": "application/json" },
1628
1630
  body: JSON.stringify(data),
@@ -1633,7 +1635,7 @@ class Client {
1633
1635
  const result = await response.json();
1634
1636
  return result["examples"];
1635
1637
  }
1636
- async createExample(inputs, outputs, { datasetId, datasetName, createdAt, exampleId, metadata, split, }) {
1638
+ async createExample(inputs, outputs, { datasetId, datasetName, createdAt, exampleId, metadata, split, sourceRunId, }) {
1637
1639
  let datasetId_ = datasetId;
1638
1640
  if (datasetId_ === undefined && datasetName === undefined) {
1639
1641
  throw new Error("Must provide either datasetName or datasetId");
@@ -1654,8 +1656,9 @@ class Client {
1654
1656
  id: exampleId,
1655
1657
  metadata,
1656
1658
  split,
1659
+ source_run_id: sourceRunId,
1657
1660
  };
1658
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples`, {
1661
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/examples`, {
1659
1662
  method: "POST",
1660
1663
  headers: { ...this.headers, "Content-Type": "application/json" },
1661
1664
  body: JSON.stringify(data),
@@ -1690,7 +1693,7 @@ class Client {
1690
1693
  source_run_id: sourceRunIds ? sourceRunIds[idx] : undefined,
1691
1694
  };
1692
1695
  });
1693
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
1696
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/examples/bulk`, {
1694
1697
  method: "POST",
1695
1698
  headers: { ...this.headers, "Content-Type": "application/json" },
1696
1699
  body: JSON.stringify(formattedExamples),
@@ -1784,7 +1787,7 @@ class Client {
1784
1787
  async deleteExample(exampleId) {
1785
1788
  (0, _uuid_js_1.assertUuid)(exampleId);
1786
1789
  const path = `/examples/${exampleId}`;
1787
- const response = await this.caller.call(fetch, this.apiUrl + path, {
1790
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), this.apiUrl + path, {
1788
1791
  method: "DELETE",
1789
1792
  headers: this.headers,
1790
1793
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1795,7 +1798,7 @@ class Client {
1795
1798
  }
1796
1799
  async updateExample(exampleId, update) {
1797
1800
  (0, _uuid_js_1.assertUuid)(exampleId);
1798
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples/${exampleId}`, {
1801
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/examples/${exampleId}`, {
1799
1802
  method: "PATCH",
1800
1803
  headers: { ...this.headers, "Content-Type": "application/json" },
1801
1804
  body: JSON.stringify(update),
@@ -1807,7 +1810,7 @@ class Client {
1807
1810
  return result;
1808
1811
  }
1809
1812
  async updateExamples(update) {
1810
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
1813
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/examples/bulk`, {
1811
1814
  method: "PATCH",
1812
1815
  headers: { ...this.headers, "Content-Type": "application/json" },
1813
1816
  body: JSON.stringify(update),
@@ -1870,7 +1873,7 @@ class Client {
1870
1873
  }),
1871
1874
  remove,
1872
1875
  };
1873
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId_}/splits`, {
1876
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/datasets/${datasetId_}/splits`, {
1874
1877
  method: "PUT",
1875
1878
  headers: { ...this.headers, "Content-Type": "application/json" },
1876
1879
  body: JSON.stringify(data),
@@ -1936,7 +1939,7 @@ class Client {
1936
1939
  session_id: projectId,
1937
1940
  };
1938
1941
  const url = `${this.apiUrl}/feedback`;
1939
- const response = await this.caller.call(fetch, url, {
1942
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), url, {
1940
1943
  method: "POST",
1941
1944
  headers: { ...this.headers, "Content-Type": "application/json" },
1942
1945
  body: JSON.stringify(feedback),
@@ -1961,7 +1964,7 @@ class Client {
1961
1964
  feedbackUpdate["comment"] = comment;
1962
1965
  }
1963
1966
  (0, _uuid_js_1.assertUuid)(feedbackId);
1964
- const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/${feedbackId}`, {
1967
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/feedback/${feedbackId}`, {
1965
1968
  method: "PATCH",
1966
1969
  headers: { ...this.headers, "Content-Type": "application/json" },
1967
1970
  body: JSON.stringify(feedbackUpdate),
@@ -1979,7 +1982,7 @@ class Client {
1979
1982
  async deleteFeedback(feedbackId) {
1980
1983
  (0, _uuid_js_1.assertUuid)(feedbackId);
1981
1984
  const path = `/feedback/${feedbackId}`;
1982
- const response = await this.caller.call(fetch, this.apiUrl + path, {
1985
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), this.apiUrl + path, {
1983
1986
  method: "DELETE",
1984
1987
  headers: this.headers,
1985
1988
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2041,7 +2044,7 @@ class Client {
2041
2044
  hours: 3,
2042
2045
  };
2043
2046
  }
2044
- const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/tokens`, {
2047
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/feedback/tokens`, {
2045
2048
  method: "POST",
2046
2049
  headers: { ...this.headers, "Content-Type": "application/json" },
2047
2050
  body: JSON.stringify(body),
@@ -2074,7 +2077,7 @@ class Client {
2074
2077
  };
2075
2078
  if (metadata)
2076
2079
  body.extra["metadata"] = metadata;
2077
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/comparative`, {
2080
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/datasets/comparative`, {
2078
2081
  method: "POST",
2079
2082
  headers: { ...this.headers, "Content-Type": "application/json" },
2080
2083
  body: JSON.stringify(body),
@@ -2148,7 +2151,7 @@ class Client {
2148
2151
  Requested tenant: ${owner}`);
2149
2152
  }
2150
2153
  async _getLatestCommitHash(promptOwnerAndName) {
2151
- const res = await this.caller.call(fetch, `${this.apiUrl}/commits/${promptOwnerAndName}/?limit=${1}&offset=${0}`, {
2154
+ const res = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/commits/${promptOwnerAndName}/?limit=${1}&offset=${0}`, {
2152
2155
  method: "GET",
2153
2156
  headers: this.headers,
2154
2157
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2171,7 +2174,7 @@ class Client {
2171
2174
  }
2172
2175
  async _likeOrUnlikePrompt(promptIdentifier, like) {
2173
2176
  const [owner, promptName, _] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
2174
- const response = await this.caller.call(fetch, `${this.apiUrl}/likes/${owner}/${promptName}`, {
2177
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/likes/${owner}/${promptName}`, {
2175
2178
  method: "POST",
2176
2179
  body: JSON.stringify({ like: like }),
2177
2180
  headers: { ...this.headers, "Content-Type": "application/json" },
@@ -2233,7 +2236,7 @@ class Client {
2233
2236
  }
2234
2237
  async getPrompt(promptIdentifier) {
2235
2238
  const [owner, promptName, _] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
2236
- const response = await this.caller.call(fetch, `${this.apiUrl}/repos/${owner}/${promptName}`, {
2239
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/repos/${owner}/${promptName}`, {
2237
2240
  method: "GET",
2238
2241
  headers: this.headers,
2239
2242
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2270,7 +2273,7 @@ class Client {
2270
2273
  ...(options?.tags && { tags: options.tags }),
2271
2274
  is_public: !!options?.isPublic,
2272
2275
  };
2273
- const response = await this.caller.call(fetch, `${this.apiUrl}/repos/`, {
2276
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/repos/`, {
2274
2277
  method: "POST",
2275
2278
  headers: { ...this.headers, "Content-Type": "application/json" },
2276
2279
  body: JSON.stringify(data),
@@ -2293,7 +2296,7 @@ class Client {
2293
2296
  manifest: JSON.parse(JSON.stringify(object)),
2294
2297
  parent_commit: resolvedParentCommitHash,
2295
2298
  };
2296
- const response = await this.caller.call(fetch, `${this.apiUrl}/commits/${owner}/${promptName}`, {
2299
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/commits/${owner}/${promptName}`, {
2297
2300
  method: "POST",
2298
2301
  headers: { ...this.headers, "Content-Type": "application/json" },
2299
2302
  body: JSON.stringify(payload),
@@ -2327,7 +2330,7 @@ class Client {
2327
2330
  if (Object.keys(payload).length === 0) {
2328
2331
  throw new Error("No valid update options provided");
2329
2332
  }
2330
- const response = await this.caller.call(fetch, `${this.apiUrl}/repos/${owner}/${promptName}`, {
2333
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/repos/${owner}/${promptName}`, {
2331
2334
  method: "PATCH",
2332
2335
  body: JSON.stringify(payload),
2333
2336
  headers: {
@@ -2348,7 +2351,7 @@ class Client {
2348
2351
  if (!(await this._currentTenantIsOwner(owner))) {
2349
2352
  throw await this._ownerConflictError("delete a prompt", owner);
2350
2353
  }
2351
- const response = await this.caller.call(fetch, `${this.apiUrl}/repos/${owner}/${promptName}`, {
2354
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/repos/${owner}/${promptName}`, {
2352
2355
  method: "DELETE",
2353
2356
  headers: this.headers,
2354
2357
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2370,7 +2373,7 @@ class Client {
2370
2373
  passedCommitHash = latestCommitHash;
2371
2374
  }
2372
2375
  }
2373
- const response = await this.caller.call(fetch, `${this.apiUrl}/commits/${owner}/${promptName}/${passedCommitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
2376
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), `${this.apiUrl}/commits/${owner}/${promptName}/${passedCommitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
2374
2377
  method: "GET",
2375
2378
  headers: this.headers,
2376
2379
  signal: AbortSignal.timeout(this.timeout_ms),
package/dist/client.d.ts CHANGED
@@ -141,12 +141,20 @@ interface ProjectOptions {
141
141
  type RecordStringAny = Record<string, any>;
142
142
  export type FeedbackSourceType = "model" | "api" | "app";
143
143
  export type CreateExampleOptions = {
144
+ /** The ID of the dataset to create the example in. */
144
145
  datasetId?: string;
146
+ /** The name of the dataset to create the example in (if dataset ID is not provided). */
145
147
  datasetName?: string;
148
+ /** The creation date of the example. */
146
149
  createdAt?: Date;
150
+ /** A unique identifier for the example. */
147
151
  exampleId?: string;
152
+ /** Additional metadata associated with the example. */
148
153
  metadata?: KVMap;
154
+ /** The split(s) to assign the example to. */
149
155
  split?: string | string[];
156
+ /** The ID of the source run associated with this example. */
157
+ sourceRunId?: string;
150
158
  };
151
159
  export declare class Queue<T> {
152
160
  items: [T, () => void][];
@@ -476,7 +484,7 @@ export declare class Client {
476
484
  similarExamples(inputs: KVMap, datasetId: string, limit: number, { filter, }?: {
477
485
  filter?: string;
478
486
  }): Promise<ExampleSearch[]>;
479
- createExample(inputs: KVMap, outputs: KVMap, { datasetId, datasetName, createdAt, exampleId, metadata, split, }: CreateExampleOptions): Promise<Example>;
487
+ createExample(inputs: KVMap, outputs: KVMap, { datasetId, datasetName, createdAt, exampleId, metadata, split, sourceRunId, }: CreateExampleOptions): Promise<Example>;
480
488
  createExamples(props: {
481
489
  inputs: Array<KVMap>;
482
490
  outputs?: Array<KVMap>;
package/dist/client.js CHANGED
@@ -7,6 +7,8 @@ import { assertUuid } from "./utils/_uuid.js";
7
7
  import { warnOnce } from "./utils/warn.js";
8
8
  import { isVersionGreaterOrEqual, parsePromptIdentifier, } from "./utils/prompts.js";
9
9
  import { raiseForStatus } from "./utils/error.js";
10
+ import { stringifyForTracing } from "./utils/serde.js";
11
+ import { _getFetchImplementation } from "./singletons/fetch.js";
10
12
  async function mergeRuntimeEnvIntoRunCreates(runs) {
11
13
  const runtimeEnv = await getRuntimeEnvironment();
12
14
  const envVars = getLangChainEnvVarsMetadata();
@@ -347,7 +349,7 @@ export class Client {
347
349
  async _getResponse(path, queryParams) {
348
350
  const paramsString = queryParams?.toString() ?? "";
349
351
  const url = `${this.apiUrl}${path}?${paramsString}`;
350
- const response = await this.caller.call(fetch, url, {
352
+ const response = await this.caller.call(_getFetchImplementation(), url, {
351
353
  method: "GET",
352
354
  headers: this.headers,
353
355
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -367,7 +369,7 @@ export class Client {
367
369
  queryParams.set("offset", String(offset));
368
370
  queryParams.set("limit", String(limit));
369
371
  const url = `${this.apiUrl}${path}?${queryParams}`;
370
- const response = await this.caller.call(fetch, url, {
372
+ const response = await this.caller.call(_getFetchImplementation(), url, {
371
373
  method: "GET",
372
374
  headers: this.headers,
373
375
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -390,7 +392,7 @@ export class Client {
390
392
  async *_getCursorPaginatedList(path, body = null, requestMethod = "POST", dataKey = "runs") {
391
393
  const bodyParams = body ? { ...body } : {};
392
394
  while (true) {
393
- const response = await this.caller.call(fetch, `${this.apiUrl}${path}`, {
395
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}${path}`, {
394
396
  method: requestMethod,
395
397
  headers: { ...this.headers, "Content-Type": "application/json" },
396
398
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -490,7 +492,7 @@ export class Client {
490
492
  return itemPromise;
491
493
  }
492
494
  async _getServerInfo() {
493
- const response = await fetch(`${this.apiUrl}/info`, {
495
+ const response = await _getFetchImplementation()(`${this.apiUrl}/info`, {
494
496
  method: "GET",
495
497
  headers: { Accept: "application/json" },
496
498
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -538,10 +540,10 @@ export class Client {
538
540
  const mergedRunCreateParams = await mergeRuntimeEnvIntoRunCreates([
539
541
  runCreate,
540
542
  ]);
541
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs`, {
543
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/runs`, {
542
544
  method: "POST",
543
545
  headers,
544
- body: JSON.stringify(mergedRunCreateParams[0]),
546
+ body: stringifyForTracing(mergedRunCreateParams[0]),
545
547
  signal: AbortSignal.timeout(this.timeout_ms),
546
548
  ...this.fetchOptions,
547
549
  });
@@ -615,10 +617,10 @@ export class Client {
615
617
  const batchItems = rawBatch[key].reverse();
616
618
  let batchItem = batchItems.pop();
617
619
  while (batchItem !== undefined) {
618
- const stringifiedBatchItem = JSON.stringify(batchItem);
620
+ const stringifiedBatchItem = stringifyForTracing(batchItem);
619
621
  if (currentBatchSizeBytes > 0 &&
620
622
  currentBatchSizeBytes + stringifiedBatchItem.length > sizeLimitBytes) {
621
- await this._postBatchIngestRuns(JSON.stringify(batchChunks));
623
+ await this._postBatchIngestRuns(stringifyForTracing(batchChunks));
622
624
  currentBatchSizeBytes = 0;
623
625
  batchChunks.post = [];
624
626
  batchChunks.patch = [];
@@ -629,7 +631,7 @@ export class Client {
629
631
  }
630
632
  }
631
633
  if (batchChunks.post.length > 0 || batchChunks.patch.length > 0) {
632
- await this._postBatchIngestRuns(JSON.stringify(batchChunks));
634
+ await this._postBatchIngestRuns(stringifyForTracing(batchChunks));
633
635
  }
634
636
  }
635
637
  async _postBatchIngestRuns(body) {
@@ -638,7 +640,7 @@ export class Client {
638
640
  "Content-Type": "application/json",
639
641
  Accept: "application/json",
640
642
  };
641
- const response = await this.batchIngestCaller.call(fetch, `${this.apiUrl}/runs/batch`, {
643
+ const response = await this.batchIngestCaller.call(_getFetchImplementation(), `${this.apiUrl}/runs/batch`, {
642
644
  method: "POST",
643
645
  headers,
644
646
  body: body,
@@ -675,10 +677,10 @@ export class Client {
675
677
  return;
676
678
  }
677
679
  const headers = { ...this.headers, "Content-Type": "application/json" };
678
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}`, {
680
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/runs/${runId}`, {
679
681
  method: "PATCH",
680
682
  headers,
681
- body: JSON.stringify(run),
683
+ body: stringifyForTracing(run),
682
684
  signal: AbortSignal.timeout(this.timeout_ms),
683
685
  ...this.fetchOptions,
684
686
  });
@@ -938,7 +940,7 @@ export class Client {
938
940
  };
939
941
  // Remove undefined values from the payload
940
942
  const filteredPayload = Object.fromEntries(Object.entries(payload).filter(([_, value]) => value !== undefined));
941
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/stats`, {
943
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/runs/stats`, {
942
944
  method: "POST",
943
945
  headers: this.headers,
944
946
  body: JSON.stringify(filteredPayload),
@@ -954,7 +956,7 @@ export class Client {
954
956
  share_token: shareId || uuid.v4(),
955
957
  };
956
958
  assertUuid(runId);
957
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}/share`, {
959
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/runs/${runId}/share`, {
958
960
  method: "PUT",
959
961
  headers: this.headers,
960
962
  body: JSON.stringify(data),
@@ -969,7 +971,7 @@ export class Client {
969
971
  }
970
972
  async unshareRun(runId) {
971
973
  assertUuid(runId);
972
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}/share`, {
974
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/runs/${runId}/share`, {
973
975
  method: "DELETE",
974
976
  headers: this.headers,
975
977
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -979,7 +981,7 @@ export class Client {
979
981
  }
980
982
  async readRunSharedLink(runId) {
981
983
  assertUuid(runId);
982
- const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}/share`, {
984
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/runs/${runId}/share`, {
983
985
  method: "GET",
984
986
  headers: this.headers,
985
987
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1001,7 +1003,7 @@ export class Client {
1001
1003
  }
1002
1004
  }
1003
1005
  assertUuid(shareToken);
1004
- const response = await this.caller.call(fetch, `${this.apiUrl}/public/${shareToken}/runs${queryParams}`, {
1006
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/public/${shareToken}/runs${queryParams}`, {
1005
1007
  method: "GET",
1006
1008
  headers: this.headers,
1007
1009
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1019,7 +1021,7 @@ export class Client {
1019
1021
  datasetId = dataset.id;
1020
1022
  }
1021
1023
  assertUuid(datasetId);
1022
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/share`, {
1024
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets/${datasetId}/share`, {
1023
1025
  method: "GET",
1024
1026
  headers: this.headers,
1025
1027
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1041,7 +1043,7 @@ export class Client {
1041
1043
  dataset_id: datasetId,
1042
1044
  };
1043
1045
  assertUuid(datasetId);
1044
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/share`, {
1046
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets/${datasetId}/share`, {
1045
1047
  method: "PUT",
1046
1048
  headers: this.headers,
1047
1049
  body: JSON.stringify(data),
@@ -1054,7 +1056,7 @@ export class Client {
1054
1056
  }
1055
1057
  async unshareDataset(datasetId) {
1056
1058
  assertUuid(datasetId);
1057
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/share`, {
1059
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets/${datasetId}/share`, {
1058
1060
  method: "DELETE",
1059
1061
  headers: this.headers,
1060
1062
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1064,7 +1066,7 @@ export class Client {
1064
1066
  }
1065
1067
  async readSharedDataset(shareToken) {
1066
1068
  assertUuid(shareToken);
1067
- const response = await this.caller.call(fetch, `${this.apiUrl}/public/${shareToken}/datasets`, {
1069
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/public/${shareToken}/datasets`, {
1068
1070
  method: "GET",
1069
1071
  headers: this.headers,
1070
1072
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1095,7 +1097,7 @@ export class Client {
1095
1097
  urlParams.append(key, value);
1096
1098
  }
1097
1099
  });
1098
- const response = await this.caller.call(fetch, `${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
1100
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
1099
1101
  method: "GET",
1100
1102
  headers: this.headers,
1101
1103
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1128,7 +1130,7 @@ export class Client {
1128
1130
  if (referenceDatasetId !== null) {
1129
1131
  body["reference_dataset_id"] = referenceDatasetId;
1130
1132
  }
1131
- const response = await this.caller.call(fetch, endpoint, {
1133
+ const response = await this.caller.call(_getFetchImplementation(), endpoint, {
1132
1134
  method: "POST",
1133
1135
  headers: { ...this.headers, "Content-Type": "application/json" },
1134
1136
  body: JSON.stringify(body),
@@ -1151,7 +1153,7 @@ export class Client {
1151
1153
  description,
1152
1154
  end_time: endTime ? new Date(endTime).toISOString() : null,
1153
1155
  };
1154
- const response = await this.caller.call(fetch, endpoint, {
1156
+ const response = await this.caller.call(_getFetchImplementation(), endpoint, {
1155
1157
  method: "PATCH",
1156
1158
  headers: { ...this.headers, "Content-Type": "application/json" },
1157
1159
  body: JSON.stringify(body),
@@ -1179,7 +1181,7 @@ export class Client {
1179
1181
  else {
1180
1182
  throw new Error("Must provide projectName or projectId");
1181
1183
  }
1182
- const response = await this.caller.call(fetch, `${this.apiUrl}${path}?${params}`, {
1184
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}${path}?${params}`, {
1183
1185
  method: "GET",
1184
1186
  headers: this.headers,
1185
1187
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1309,7 +1311,7 @@ export class Client {
1309
1311
  projectId_ = projectId;
1310
1312
  }
1311
1313
  assertUuid(projectId_);
1312
- const response = await this.caller.call(fetch, `${this.apiUrl}/sessions/${projectId_}`, {
1314
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/sessions/${projectId_}`, {
1313
1315
  method: "DELETE",
1314
1316
  headers: this.headers,
1315
1317
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1336,7 +1338,7 @@ export class Client {
1336
1338
  if (name) {
1337
1339
  formData.append("name", name);
1338
1340
  }
1339
- const response = await this.caller.call(fetch, url, {
1341
+ const response = await this.caller.call(_getFetchImplementation(), url, {
1340
1342
  method: "POST",
1341
1343
  headers: this.headers,
1342
1344
  body: formData,
@@ -1362,7 +1364,7 @@ export class Client {
1362
1364
  if (outputsSchema) {
1363
1365
  body.outputs_schema_definition = outputsSchema;
1364
1366
  }
1365
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets`, {
1367
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets`, {
1366
1368
  method: "POST",
1367
1369
  headers: { ...this.headers, "Content-Type": "application/json" },
1368
1370
  body: JSON.stringify(body),
@@ -1494,7 +1496,7 @@ export class Client {
1494
1496
  }
1495
1497
  const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
1496
1498
  assertUuid(_datasetId);
1497
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${_datasetId}`, {
1499
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets/${_datasetId}`, {
1498
1500
  method: "PATCH",
1499
1501
  headers: { ...this.headers, "Content-Type": "application/json" },
1500
1502
  body: JSON.stringify(update),
@@ -1521,7 +1523,7 @@ export class Client {
1521
1523
  else {
1522
1524
  throw new Error("Must provide datasetName or datasetId");
1523
1525
  }
1524
- const response = await this.caller.call(fetch, this.apiUrl + path, {
1526
+ const response = await this.caller.call(_getFetchImplementation(), this.apiUrl + path, {
1525
1527
  method: "DELETE",
1526
1528
  headers: this.headers,
1527
1529
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1546,7 +1548,7 @@ export class Client {
1546
1548
  const data = {
1547
1549
  tag: tag,
1548
1550
  };
1549
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId_}/index`, {
1551
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets/${datasetId_}/index`, {
1550
1552
  method: "POST",
1551
1553
  headers: { ...this.headers, "Content-Type": "application/json" },
1552
1554
  body: JSON.stringify(data),
@@ -1595,7 +1597,7 @@ export class Client {
1595
1597
  data["filter"] = filter;
1596
1598
  }
1597
1599
  assertUuid(datasetId);
1598
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/search`, {
1600
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets/${datasetId}/search`, {
1599
1601
  method: "POST",
1600
1602
  headers: { ...this.headers, "Content-Type": "application/json" },
1601
1603
  body: JSON.stringify(data),
@@ -1606,7 +1608,7 @@ export class Client {
1606
1608
  const result = await response.json();
1607
1609
  return result["examples"];
1608
1610
  }
1609
- async createExample(inputs, outputs, { datasetId, datasetName, createdAt, exampleId, metadata, split, }) {
1611
+ async createExample(inputs, outputs, { datasetId, datasetName, createdAt, exampleId, metadata, split, sourceRunId, }) {
1610
1612
  let datasetId_ = datasetId;
1611
1613
  if (datasetId_ === undefined && datasetName === undefined) {
1612
1614
  throw new Error("Must provide either datasetName or datasetId");
@@ -1627,8 +1629,9 @@ export class Client {
1627
1629
  id: exampleId,
1628
1630
  metadata,
1629
1631
  split,
1632
+ source_run_id: sourceRunId,
1630
1633
  };
1631
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples`, {
1634
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/examples`, {
1632
1635
  method: "POST",
1633
1636
  headers: { ...this.headers, "Content-Type": "application/json" },
1634
1637
  body: JSON.stringify(data),
@@ -1663,7 +1666,7 @@ export class Client {
1663
1666
  source_run_id: sourceRunIds ? sourceRunIds[idx] : undefined,
1664
1667
  };
1665
1668
  });
1666
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
1669
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/examples/bulk`, {
1667
1670
  method: "POST",
1668
1671
  headers: { ...this.headers, "Content-Type": "application/json" },
1669
1672
  body: JSON.stringify(formattedExamples),
@@ -1757,7 +1760,7 @@ export class Client {
1757
1760
  async deleteExample(exampleId) {
1758
1761
  assertUuid(exampleId);
1759
1762
  const path = `/examples/${exampleId}`;
1760
- const response = await this.caller.call(fetch, this.apiUrl + path, {
1763
+ const response = await this.caller.call(_getFetchImplementation(), this.apiUrl + path, {
1761
1764
  method: "DELETE",
1762
1765
  headers: this.headers,
1763
1766
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1768,7 +1771,7 @@ export class Client {
1768
1771
  }
1769
1772
  async updateExample(exampleId, update) {
1770
1773
  assertUuid(exampleId);
1771
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples/${exampleId}`, {
1774
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/examples/${exampleId}`, {
1772
1775
  method: "PATCH",
1773
1776
  headers: { ...this.headers, "Content-Type": "application/json" },
1774
1777
  body: JSON.stringify(update),
@@ -1780,7 +1783,7 @@ export class Client {
1780
1783
  return result;
1781
1784
  }
1782
1785
  async updateExamples(update) {
1783
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
1786
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/examples/bulk`, {
1784
1787
  method: "PATCH",
1785
1788
  headers: { ...this.headers, "Content-Type": "application/json" },
1786
1789
  body: JSON.stringify(update),
@@ -1843,7 +1846,7 @@ export class Client {
1843
1846
  }),
1844
1847
  remove,
1845
1848
  };
1846
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId_}/splits`, {
1849
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets/${datasetId_}/splits`, {
1847
1850
  method: "PUT",
1848
1851
  headers: { ...this.headers, "Content-Type": "application/json" },
1849
1852
  body: JSON.stringify(data),
@@ -1909,7 +1912,7 @@ export class Client {
1909
1912
  session_id: projectId,
1910
1913
  };
1911
1914
  const url = `${this.apiUrl}/feedback`;
1912
- const response = await this.caller.call(fetch, url, {
1915
+ const response = await this.caller.call(_getFetchImplementation(), url, {
1913
1916
  method: "POST",
1914
1917
  headers: { ...this.headers, "Content-Type": "application/json" },
1915
1918
  body: JSON.stringify(feedback),
@@ -1934,7 +1937,7 @@ export class Client {
1934
1937
  feedbackUpdate["comment"] = comment;
1935
1938
  }
1936
1939
  assertUuid(feedbackId);
1937
- const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/${feedbackId}`, {
1940
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/feedback/${feedbackId}`, {
1938
1941
  method: "PATCH",
1939
1942
  headers: { ...this.headers, "Content-Type": "application/json" },
1940
1943
  body: JSON.stringify(feedbackUpdate),
@@ -1952,7 +1955,7 @@ export class Client {
1952
1955
  async deleteFeedback(feedbackId) {
1953
1956
  assertUuid(feedbackId);
1954
1957
  const path = `/feedback/${feedbackId}`;
1955
- const response = await this.caller.call(fetch, this.apiUrl + path, {
1958
+ const response = await this.caller.call(_getFetchImplementation(), this.apiUrl + path, {
1956
1959
  method: "DELETE",
1957
1960
  headers: this.headers,
1958
1961
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2014,7 +2017,7 @@ export class Client {
2014
2017
  hours: 3,
2015
2018
  };
2016
2019
  }
2017
- const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/tokens`, {
2020
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/feedback/tokens`, {
2018
2021
  method: "POST",
2019
2022
  headers: { ...this.headers, "Content-Type": "application/json" },
2020
2023
  body: JSON.stringify(body),
@@ -2047,7 +2050,7 @@ export class Client {
2047
2050
  };
2048
2051
  if (metadata)
2049
2052
  body.extra["metadata"] = metadata;
2050
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/comparative`, {
2053
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets/comparative`, {
2051
2054
  method: "POST",
2052
2055
  headers: { ...this.headers, "Content-Type": "application/json" },
2053
2056
  body: JSON.stringify(body),
@@ -2121,7 +2124,7 @@ export class Client {
2121
2124
  Requested tenant: ${owner}`);
2122
2125
  }
2123
2126
  async _getLatestCommitHash(promptOwnerAndName) {
2124
- const res = await this.caller.call(fetch, `${this.apiUrl}/commits/${promptOwnerAndName}/?limit=${1}&offset=${0}`, {
2127
+ const res = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/commits/${promptOwnerAndName}/?limit=${1}&offset=${0}`, {
2125
2128
  method: "GET",
2126
2129
  headers: this.headers,
2127
2130
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2144,7 +2147,7 @@ export class Client {
2144
2147
  }
2145
2148
  async _likeOrUnlikePrompt(promptIdentifier, like) {
2146
2149
  const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);
2147
- const response = await this.caller.call(fetch, `${this.apiUrl}/likes/${owner}/${promptName}`, {
2150
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/likes/${owner}/${promptName}`, {
2148
2151
  method: "POST",
2149
2152
  body: JSON.stringify({ like: like }),
2150
2153
  headers: { ...this.headers, "Content-Type": "application/json" },
@@ -2206,7 +2209,7 @@ export class Client {
2206
2209
  }
2207
2210
  async getPrompt(promptIdentifier) {
2208
2211
  const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);
2209
- const response = await this.caller.call(fetch, `${this.apiUrl}/repos/${owner}/${promptName}`, {
2212
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/repos/${owner}/${promptName}`, {
2210
2213
  method: "GET",
2211
2214
  headers: this.headers,
2212
2215
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2243,7 +2246,7 @@ export class Client {
2243
2246
  ...(options?.tags && { tags: options.tags }),
2244
2247
  is_public: !!options?.isPublic,
2245
2248
  };
2246
- const response = await this.caller.call(fetch, `${this.apiUrl}/repos/`, {
2249
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/repos/`, {
2247
2250
  method: "POST",
2248
2251
  headers: { ...this.headers, "Content-Type": "application/json" },
2249
2252
  body: JSON.stringify(data),
@@ -2266,7 +2269,7 @@ export class Client {
2266
2269
  manifest: JSON.parse(JSON.stringify(object)),
2267
2270
  parent_commit: resolvedParentCommitHash,
2268
2271
  };
2269
- const response = await this.caller.call(fetch, `${this.apiUrl}/commits/${owner}/${promptName}`, {
2272
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/commits/${owner}/${promptName}`, {
2270
2273
  method: "POST",
2271
2274
  headers: { ...this.headers, "Content-Type": "application/json" },
2272
2275
  body: JSON.stringify(payload),
@@ -2300,7 +2303,7 @@ export class Client {
2300
2303
  if (Object.keys(payload).length === 0) {
2301
2304
  throw new Error("No valid update options provided");
2302
2305
  }
2303
- const response = await this.caller.call(fetch, `${this.apiUrl}/repos/${owner}/${promptName}`, {
2306
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/repos/${owner}/${promptName}`, {
2304
2307
  method: "PATCH",
2305
2308
  body: JSON.stringify(payload),
2306
2309
  headers: {
@@ -2321,7 +2324,7 @@ export class Client {
2321
2324
  if (!(await this._currentTenantIsOwner(owner))) {
2322
2325
  throw await this._ownerConflictError("delete a prompt", owner);
2323
2326
  }
2324
- const response = await this.caller.call(fetch, `${this.apiUrl}/repos/${owner}/${promptName}`, {
2327
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/repos/${owner}/${promptName}`, {
2325
2328
  method: "DELETE",
2326
2329
  headers: this.headers,
2327
2330
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2343,7 +2346,7 @@ export class Client {
2343
2346
  passedCommitHash = latestCommitHash;
2344
2347
  }
2345
2348
  }
2346
- const response = await this.caller.call(fetch, `${this.apiUrl}/commits/${owner}/${promptName}/${passedCommitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
2349
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/commits/${owner}/${promptName}/${passedCommitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
2347
2350
  method: "GET",
2348
2351
  headers: this.headers,
2349
2352
  signal: AbortSignal.timeout(this.timeout_ms),
package/dist/index.cjs CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.__version__ = exports.RunTree = exports.Client = void 0;
3
+ exports.__version__ = exports.overrideFetchImplementation = exports.RunTree = exports.Client = void 0;
4
4
  var client_js_1 = require("./client.cjs");
5
5
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_js_1.Client; } });
6
6
  var run_trees_js_1 = require("./run_trees.cjs");
7
7
  Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () { return run_trees_js_1.RunTree; } });
8
+ var fetch_js_1 = require("./singletons/fetch.cjs");
9
+ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
8
10
  // Update using yarn bump-version
9
- exports.__version__ = "0.1.51";
11
+ exports.__version__ = "0.1.53";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { Client, type ClientConfig } from "./client.js";
2
2
  export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, } from "./schemas.js";
3
3
  export { RunTree, type RunTreeConfig } from "./run_trees.js";
4
- export declare const __version__ = "0.1.51";
4
+ export { overrideFetchImplementation } from "./singletons/fetch.js";
5
+ export declare const __version__ = "0.1.53";
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { Client } from "./client.js";
2
2
  export { RunTree } from "./run_trees.js";
3
+ export { overrideFetchImplementation } from "./singletons/fetch.js";
3
4
  // Update using yarn bump-version
4
- export const __version__ = "0.1.51";
5
+ export const __version__ = "0.1.53";
package/dist/schemas.d.ts CHANGED
@@ -30,6 +30,7 @@ export interface BaseExample {
30
30
  inputs: KVMap;
31
31
  outputs?: KVMap;
32
32
  metadata?: KVMap;
33
+ source_run_id?: string;
33
34
  }
34
35
  /**
35
36
  * A run can represent either a trace (root run)
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._getFetchImplementation = exports.overrideFetchImplementation = void 0;
4
+ // Wrap the default fetch call due to issues with illegal invocations
5
+ // in some environments:
6
+ // https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err
7
+ // @ts-expect-error Broad typing to support a range of fetch implementations
8
+ const DEFAULT_FETCH_IMPLEMENTATION = (...args) => fetch(...args);
9
+ const LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for("ls:fetch_implementation");
10
+ /**
11
+ * Overrides the fetch implementation used for LangSmith calls.
12
+ * You should use this if you need to use an implementation of fetch
13
+ * other than the default global (e.g. for dealing with proxies).
14
+ * @param fetch The new fetch functino to use.
15
+ */
16
+ const overrideFetchImplementation = (fetch) => {
17
+ globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;
18
+ };
19
+ exports.overrideFetchImplementation = overrideFetchImplementation;
20
+ /**
21
+ * @internal
22
+ */
23
+ const _getFetchImplementation = () => {
24
+ return (globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??
25
+ DEFAULT_FETCH_IMPLEMENTATION);
26
+ };
27
+ exports._getFetchImplementation = _getFetchImplementation;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Overrides the fetch implementation used for LangSmith calls.
3
+ * You should use this if you need to use an implementation of fetch
4
+ * other than the default global (e.g. for dealing with proxies).
5
+ * @param fetch The new fetch functino to use.
6
+ */
7
+ export declare const overrideFetchImplementation: (fetch: (...args: any[]) => any) => void;
8
+ /**
9
+ * @internal
10
+ */
11
+ export declare const _getFetchImplementation: () => (...args: any[]) => any;
@@ -0,0 +1,22 @@
1
+ // Wrap the default fetch call due to issues with illegal invocations
2
+ // in some environments:
3
+ // https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err
4
+ // @ts-expect-error Broad typing to support a range of fetch implementations
5
+ const DEFAULT_FETCH_IMPLEMENTATION = (...args) => fetch(...args);
6
+ const LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for("ls:fetch_implementation");
7
+ /**
8
+ * Overrides the fetch implementation used for LangSmith calls.
9
+ * You should use this if you need to use an implementation of fetch
10
+ * other than the default global (e.g. for dealing with proxies).
11
+ * @param fetch The new fetch functino to use.
12
+ */
13
+ export const overrideFetchImplementation = (fetch) => {
14
+ globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;
15
+ };
16
+ /**
17
+ * @internal
18
+ */
19
+ export const _getFetchImplementation = () => {
20
+ return (globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??
21
+ DEFAULT_FETCH_IMPLEMENTATION);
22
+ };
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.AsyncCaller = void 0;
7
7
  const p_retry_1 = __importDefault(require("p-retry"));
8
8
  const p_queue_1 = __importDefault(require("p-queue"));
9
+ const fetch_js_1 = require("../singletons/fetch.cjs");
9
10
  const STATUS_NO_RETRY = [
10
11
  400, // Bad Request
11
12
  401, // Unauthorized
@@ -132,7 +133,7 @@ class AsyncCaller {
132
133
  return this.call(callable, ...args);
133
134
  }
134
135
  fetch(...args) {
135
- return this.call(() => fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))));
136
+ return this.call(() => (0, fetch_js_1._getFetchImplementation)()(...args).then((res) => res.ok ? res : Promise.reject(res)));
136
137
  }
137
138
  }
138
139
  exports.AsyncCaller = AsyncCaller;
@@ -1,5 +1,6 @@
1
1
  import pRetry from "p-retry";
2
2
  import PQueueMod from "p-queue";
3
+ import { _getFetchImplementation } from "../singletons/fetch.js";
3
4
  const STATUS_NO_RETRY = [
4
5
  400, // Bad Request
5
6
  401, // Unauthorized
@@ -126,6 +127,6 @@ export class AsyncCaller {
126
127
  return this.call(callable, ...args);
127
128
  }
128
129
  fetch(...args) {
129
- return this.call(() => fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))));
130
+ return this.call(() => _getFetchImplementation()(...args).then((res) => res.ok ? res : Promise.reject(res)));
130
131
  }
131
132
  }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stringifyForTracing = exports.CIRCULAR_VALUE_REPLACEMENT_STRING = void 0;
4
+ exports.CIRCULAR_VALUE_REPLACEMENT_STRING = "[Circular]";
5
+ /**
6
+ * JSON.stringify version that handles circular references by replacing them
7
+ * with an object marking them as such ({ result: "[Circular]" }).
8
+ */
9
+ const stringifyForTracing = (value) => {
10
+ const seen = new WeakSet();
11
+ const serializer = (_, value) => {
12
+ if (typeof value === "object" && value !== null) {
13
+ if (seen.has(value)) {
14
+ return {
15
+ result: exports.CIRCULAR_VALUE_REPLACEMENT_STRING,
16
+ };
17
+ }
18
+ seen.add(value);
19
+ }
20
+ return value;
21
+ };
22
+ return JSON.stringify(value, serializer);
23
+ };
24
+ exports.stringifyForTracing = stringifyForTracing;
@@ -0,0 +1,6 @@
1
+ export declare const CIRCULAR_VALUE_REPLACEMENT_STRING = "[Circular]";
2
+ /**
3
+ * JSON.stringify version that handles circular references by replacing them
4
+ * with an object marking them as such ({ result: "[Circular]" }).
5
+ */
6
+ export declare const stringifyForTracing: (value: any) => string;
@@ -0,0 +1,20 @@
1
+ export const CIRCULAR_VALUE_REPLACEMENT_STRING = "[Circular]";
2
+ /**
3
+ * JSON.stringify version that handles circular references by replacing them
4
+ * with an object marking them as such ({ result: "[Circular]" }).
5
+ */
6
+ export const stringifyForTracing = (value) => {
7
+ const seen = new WeakSet();
8
+ const serializer = (_, value) => {
9
+ if (typeof value === "object" && value !== null) {
10
+ if (seen.has(value)) {
11
+ return {
12
+ result: CIRCULAR_VALUE_REPLACEMENT_STRING,
13
+ };
14
+ }
15
+ seen.add(value);
16
+ }
17
+ return value;
18
+ };
19
+ return JSON.stringify(value, serializer);
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.1.51",
3
+ "version": "0.1.53",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [