langsmith 0.1.52 → 0.1.54

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),
@@ -1656,7 +1658,7 @@ class Client {
1656
1658
  split,
1657
1659
  source_run_id: sourceRunId,
1658
1660
  };
1659
- 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`, {
1660
1662
  method: "POST",
1661
1663
  headers: { ...this.headers, "Content-Type": "application/json" },
1662
1664
  body: JSON.stringify(data),
@@ -1691,7 +1693,7 @@ class Client {
1691
1693
  source_run_id: sourceRunIds ? sourceRunIds[idx] : undefined,
1692
1694
  };
1693
1695
  });
1694
- 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`, {
1695
1697
  method: "POST",
1696
1698
  headers: { ...this.headers, "Content-Type": "application/json" },
1697
1699
  body: JSON.stringify(formattedExamples),
@@ -1785,7 +1787,7 @@ class Client {
1785
1787
  async deleteExample(exampleId) {
1786
1788
  (0, _uuid_js_1.assertUuid)(exampleId);
1787
1789
  const path = `/examples/${exampleId}`;
1788
- 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, {
1789
1791
  method: "DELETE",
1790
1792
  headers: this.headers,
1791
1793
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1796,7 +1798,7 @@ class Client {
1796
1798
  }
1797
1799
  async updateExample(exampleId, update) {
1798
1800
  (0, _uuid_js_1.assertUuid)(exampleId);
1799
- 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}`, {
1800
1802
  method: "PATCH",
1801
1803
  headers: { ...this.headers, "Content-Type": "application/json" },
1802
1804
  body: JSON.stringify(update),
@@ -1808,7 +1810,7 @@ class Client {
1808
1810
  return result;
1809
1811
  }
1810
1812
  async updateExamples(update) {
1811
- 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`, {
1812
1814
  method: "PATCH",
1813
1815
  headers: { ...this.headers, "Content-Type": "application/json" },
1814
1816
  body: JSON.stringify(update),
@@ -1871,7 +1873,7 @@ class Client {
1871
1873
  }),
1872
1874
  remove,
1873
1875
  };
1874
- 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`, {
1875
1877
  method: "PUT",
1876
1878
  headers: { ...this.headers, "Content-Type": "application/json" },
1877
1879
  body: JSON.stringify(data),
@@ -1937,7 +1939,7 @@ class Client {
1937
1939
  session_id: projectId,
1938
1940
  };
1939
1941
  const url = `${this.apiUrl}/feedback`;
1940
- const response = await this.caller.call(fetch, url, {
1942
+ const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), url, {
1941
1943
  method: "POST",
1942
1944
  headers: { ...this.headers, "Content-Type": "application/json" },
1943
1945
  body: JSON.stringify(feedback),
@@ -1962,7 +1964,7 @@ class Client {
1962
1964
  feedbackUpdate["comment"] = comment;
1963
1965
  }
1964
1966
  (0, _uuid_js_1.assertUuid)(feedbackId);
1965
- 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}`, {
1966
1968
  method: "PATCH",
1967
1969
  headers: { ...this.headers, "Content-Type": "application/json" },
1968
1970
  body: JSON.stringify(feedbackUpdate),
@@ -1980,7 +1982,7 @@ class Client {
1980
1982
  async deleteFeedback(feedbackId) {
1981
1983
  (0, _uuid_js_1.assertUuid)(feedbackId);
1982
1984
  const path = `/feedback/${feedbackId}`;
1983
- 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, {
1984
1986
  method: "DELETE",
1985
1987
  headers: this.headers,
1986
1988
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2042,7 +2044,7 @@ class Client {
2042
2044
  hours: 3,
2043
2045
  };
2044
2046
  }
2045
- 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`, {
2046
2048
  method: "POST",
2047
2049
  headers: { ...this.headers, "Content-Type": "application/json" },
2048
2050
  body: JSON.stringify(body),
@@ -2075,7 +2077,7 @@ class Client {
2075
2077
  };
2076
2078
  if (metadata)
2077
2079
  body.extra["metadata"] = metadata;
2078
- 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`, {
2079
2081
  method: "POST",
2080
2082
  headers: { ...this.headers, "Content-Type": "application/json" },
2081
2083
  body: JSON.stringify(body),
@@ -2149,7 +2151,7 @@ class Client {
2149
2151
  Requested tenant: ${owner}`);
2150
2152
  }
2151
2153
  async _getLatestCommitHash(promptOwnerAndName) {
2152
- 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}`, {
2153
2155
  method: "GET",
2154
2156
  headers: this.headers,
2155
2157
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2172,7 +2174,7 @@ class Client {
2172
2174
  }
2173
2175
  async _likeOrUnlikePrompt(promptIdentifier, like) {
2174
2176
  const [owner, promptName, _] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
2175
- 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}`, {
2176
2178
  method: "POST",
2177
2179
  body: JSON.stringify({ like: like }),
2178
2180
  headers: { ...this.headers, "Content-Type": "application/json" },
@@ -2234,7 +2236,7 @@ class Client {
2234
2236
  }
2235
2237
  async getPrompt(promptIdentifier) {
2236
2238
  const [owner, promptName, _] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
2237
- 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}`, {
2238
2240
  method: "GET",
2239
2241
  headers: this.headers,
2240
2242
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2271,7 +2273,7 @@ class Client {
2271
2273
  ...(options?.tags && { tags: options.tags }),
2272
2274
  is_public: !!options?.isPublic,
2273
2275
  };
2274
- 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/`, {
2275
2277
  method: "POST",
2276
2278
  headers: { ...this.headers, "Content-Type": "application/json" },
2277
2279
  body: JSON.stringify(data),
@@ -2294,7 +2296,7 @@ class Client {
2294
2296
  manifest: JSON.parse(JSON.stringify(object)),
2295
2297
  parent_commit: resolvedParentCommitHash,
2296
2298
  };
2297
- 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}`, {
2298
2300
  method: "POST",
2299
2301
  headers: { ...this.headers, "Content-Type": "application/json" },
2300
2302
  body: JSON.stringify(payload),
@@ -2328,7 +2330,7 @@ class Client {
2328
2330
  if (Object.keys(payload).length === 0) {
2329
2331
  throw new Error("No valid update options provided");
2330
2332
  }
2331
- 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}`, {
2332
2334
  method: "PATCH",
2333
2335
  body: JSON.stringify(payload),
2334
2336
  headers: {
@@ -2349,7 +2351,7 @@ class Client {
2349
2351
  if (!(await this._currentTenantIsOwner(owner))) {
2350
2352
  throw await this._ownerConflictError("delete a prompt", owner);
2351
2353
  }
2352
- 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}`, {
2353
2355
  method: "DELETE",
2354
2356
  headers: this.headers,
2355
2357
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2371,7 +2373,7 @@ class Client {
2371
2373
  passedCommitHash = latestCommitHash;
2372
2374
  }
2373
2375
  }
2374
- 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" : ""}`, {
2375
2377
  method: "GET",
2376
2378
  headers: this.headers,
2377
2379
  signal: AbortSignal.timeout(this.timeout_ms),
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),
@@ -1629,7 +1631,7 @@ export class Client {
1629
1631
  split,
1630
1632
  source_run_id: sourceRunId,
1631
1633
  };
1632
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples`, {
1634
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/examples`, {
1633
1635
  method: "POST",
1634
1636
  headers: { ...this.headers, "Content-Type": "application/json" },
1635
1637
  body: JSON.stringify(data),
@@ -1664,7 +1666,7 @@ export class Client {
1664
1666
  source_run_id: sourceRunIds ? sourceRunIds[idx] : undefined,
1665
1667
  };
1666
1668
  });
1667
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
1669
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/examples/bulk`, {
1668
1670
  method: "POST",
1669
1671
  headers: { ...this.headers, "Content-Type": "application/json" },
1670
1672
  body: JSON.stringify(formattedExamples),
@@ -1758,7 +1760,7 @@ export class Client {
1758
1760
  async deleteExample(exampleId) {
1759
1761
  assertUuid(exampleId);
1760
1762
  const path = `/examples/${exampleId}`;
1761
- const response = await this.caller.call(fetch, this.apiUrl + path, {
1763
+ const response = await this.caller.call(_getFetchImplementation(), this.apiUrl + path, {
1762
1764
  method: "DELETE",
1763
1765
  headers: this.headers,
1764
1766
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -1769,7 +1771,7 @@ export class Client {
1769
1771
  }
1770
1772
  async updateExample(exampleId, update) {
1771
1773
  assertUuid(exampleId);
1772
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples/${exampleId}`, {
1774
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/examples/${exampleId}`, {
1773
1775
  method: "PATCH",
1774
1776
  headers: { ...this.headers, "Content-Type": "application/json" },
1775
1777
  body: JSON.stringify(update),
@@ -1781,7 +1783,7 @@ export class Client {
1781
1783
  return result;
1782
1784
  }
1783
1785
  async updateExamples(update) {
1784
- const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, {
1786
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/examples/bulk`, {
1785
1787
  method: "PATCH",
1786
1788
  headers: { ...this.headers, "Content-Type": "application/json" },
1787
1789
  body: JSON.stringify(update),
@@ -1844,7 +1846,7 @@ export class Client {
1844
1846
  }),
1845
1847
  remove,
1846
1848
  };
1847
- 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`, {
1848
1850
  method: "PUT",
1849
1851
  headers: { ...this.headers, "Content-Type": "application/json" },
1850
1852
  body: JSON.stringify(data),
@@ -1910,7 +1912,7 @@ export class Client {
1910
1912
  session_id: projectId,
1911
1913
  };
1912
1914
  const url = `${this.apiUrl}/feedback`;
1913
- const response = await this.caller.call(fetch, url, {
1915
+ const response = await this.caller.call(_getFetchImplementation(), url, {
1914
1916
  method: "POST",
1915
1917
  headers: { ...this.headers, "Content-Type": "application/json" },
1916
1918
  body: JSON.stringify(feedback),
@@ -1935,7 +1937,7 @@ export class Client {
1935
1937
  feedbackUpdate["comment"] = comment;
1936
1938
  }
1937
1939
  assertUuid(feedbackId);
1938
- const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/${feedbackId}`, {
1940
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/feedback/${feedbackId}`, {
1939
1941
  method: "PATCH",
1940
1942
  headers: { ...this.headers, "Content-Type": "application/json" },
1941
1943
  body: JSON.stringify(feedbackUpdate),
@@ -1953,7 +1955,7 @@ export class Client {
1953
1955
  async deleteFeedback(feedbackId) {
1954
1956
  assertUuid(feedbackId);
1955
1957
  const path = `/feedback/${feedbackId}`;
1956
- const response = await this.caller.call(fetch, this.apiUrl + path, {
1958
+ const response = await this.caller.call(_getFetchImplementation(), this.apiUrl + path, {
1957
1959
  method: "DELETE",
1958
1960
  headers: this.headers,
1959
1961
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2015,7 +2017,7 @@ export class Client {
2015
2017
  hours: 3,
2016
2018
  };
2017
2019
  }
2018
- const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/tokens`, {
2020
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/feedback/tokens`, {
2019
2021
  method: "POST",
2020
2022
  headers: { ...this.headers, "Content-Type": "application/json" },
2021
2023
  body: JSON.stringify(body),
@@ -2048,7 +2050,7 @@ export class Client {
2048
2050
  };
2049
2051
  if (metadata)
2050
2052
  body.extra["metadata"] = metadata;
2051
- const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/comparative`, {
2053
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/datasets/comparative`, {
2052
2054
  method: "POST",
2053
2055
  headers: { ...this.headers, "Content-Type": "application/json" },
2054
2056
  body: JSON.stringify(body),
@@ -2122,7 +2124,7 @@ export class Client {
2122
2124
  Requested tenant: ${owner}`);
2123
2125
  }
2124
2126
  async _getLatestCommitHash(promptOwnerAndName) {
2125
- 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}`, {
2126
2128
  method: "GET",
2127
2129
  headers: this.headers,
2128
2130
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2145,7 +2147,7 @@ export class Client {
2145
2147
  }
2146
2148
  async _likeOrUnlikePrompt(promptIdentifier, like) {
2147
2149
  const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);
2148
- 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}`, {
2149
2151
  method: "POST",
2150
2152
  body: JSON.stringify({ like: like }),
2151
2153
  headers: { ...this.headers, "Content-Type": "application/json" },
@@ -2207,7 +2209,7 @@ export class Client {
2207
2209
  }
2208
2210
  async getPrompt(promptIdentifier) {
2209
2211
  const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);
2210
- 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}`, {
2211
2213
  method: "GET",
2212
2214
  headers: this.headers,
2213
2215
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2244,7 +2246,7 @@ export class Client {
2244
2246
  ...(options?.tags && { tags: options.tags }),
2245
2247
  is_public: !!options?.isPublic,
2246
2248
  };
2247
- const response = await this.caller.call(fetch, `${this.apiUrl}/repos/`, {
2249
+ const response = await this.caller.call(_getFetchImplementation(), `${this.apiUrl}/repos/`, {
2248
2250
  method: "POST",
2249
2251
  headers: { ...this.headers, "Content-Type": "application/json" },
2250
2252
  body: JSON.stringify(data),
@@ -2267,7 +2269,7 @@ export class Client {
2267
2269
  manifest: JSON.parse(JSON.stringify(object)),
2268
2270
  parent_commit: resolvedParentCommitHash,
2269
2271
  };
2270
- 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}`, {
2271
2273
  method: "POST",
2272
2274
  headers: { ...this.headers, "Content-Type": "application/json" },
2273
2275
  body: JSON.stringify(payload),
@@ -2301,7 +2303,7 @@ export class Client {
2301
2303
  if (Object.keys(payload).length === 0) {
2302
2304
  throw new Error("No valid update options provided");
2303
2305
  }
2304
- 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}`, {
2305
2307
  method: "PATCH",
2306
2308
  body: JSON.stringify(payload),
2307
2309
  headers: {
@@ -2322,7 +2324,7 @@ export class Client {
2322
2324
  if (!(await this._currentTenantIsOwner(owner))) {
2323
2325
  throw await this._ownerConflictError("delete a prompt", owner);
2324
2326
  }
2325
- 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}`, {
2326
2328
  method: "DELETE",
2327
2329
  headers: this.headers,
2328
2330
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -2344,7 +2346,7 @@ export class Client {
2344
2346
  passedCommitHash = latestCommitHash;
2345
2347
  }
2346
2348
  }
2347
- 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" : ""}`, {
2348
2350
  method: "GET",
2349
2351
  headers: this.headers,
2350
2352
  signal: AbortSignal.timeout(this.timeout_ms),
@@ -263,22 +263,11 @@ class _ExperimentManager {
263
263
  async _getProject(firstExample) {
264
264
  let project;
265
265
  if (!this._experiment) {
266
- try {
267
- const projectMetadata = await this._getExperimentMetadata();
268
- project = await this._createProject(firstExample, projectMetadata);
269
- this._experiment = project;
270
- }
271
- catch (e) {
272
- if (String(e).includes("already exists")) {
273
- throw e;
274
- }
275
- throw new Error(`Experiment ${this._experimentName} already exists. Please use a different name.`);
276
- }
277
- }
278
- else {
279
- project = this._experiment;
266
+ const projectMetadata = await this._getExperimentMetadata();
267
+ project = await this._createProject(firstExample, projectMetadata);
268
+ this._experiment = project;
280
269
  }
281
- return project;
270
+ return this._experiment;
282
271
  }
283
272
  async _printExperimentStart() {
284
273
  console.log(`Starting evaluation of experiment: ${this.experimentName}`);
@@ -259,22 +259,11 @@ export class _ExperimentManager {
259
259
  async _getProject(firstExample) {
260
260
  let project;
261
261
  if (!this._experiment) {
262
- try {
263
- const projectMetadata = await this._getExperimentMetadata();
264
- project = await this._createProject(firstExample, projectMetadata);
265
- this._experiment = project;
266
- }
267
- catch (e) {
268
- if (String(e).includes("already exists")) {
269
- throw e;
270
- }
271
- throw new Error(`Experiment ${this._experimentName} already exists. Please use a different name.`);
272
- }
273
- }
274
- else {
275
- project = this._experiment;
262
+ const projectMetadata = await this._getExperimentMetadata();
263
+ project = await this._createProject(firstExample, projectMetadata);
264
+ this._experiment = project;
276
265
  }
277
- return project;
266
+ return this._experiment;
278
267
  }
279
268
  async _printExperimentStart() {
280
269
  console.log(`Starting evaluation of experiment: ${this.experimentName}`);
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.52";
11
+ exports.__version__ = "0.1.54";
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.52";
4
+ export { overrideFetchImplementation } from "./singletons/fetch.js";
5
+ export declare const __version__ = "0.1.54";
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.52";
5
+ export const __version__ = "0.1.54";
@@ -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.52",
3
+ "version": "0.1.54",
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": [