langsmith 0.3.62 → 0.3.64

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
@@ -202,10 +202,13 @@ class AutoBatchQueue {
202
202
  }
203
203
  }
204
204
  exports.AutoBatchQueue = AutoBatchQueue;
205
- exports.DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 32 * 1024 * 1024;
205
+ exports.DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
206
206
  const SERVER_INFO_REQUEST_TIMEOUT_MS = 10000;
207
207
  const DEFAULT_API_URL = "https://api.smith.langchain.com";
208
208
  class Client {
209
+ get _fetch() {
210
+ return this.fetchImplementation || (0, fetch_js_1._getFetchImplementation)(this.debug);
211
+ }
209
212
  constructor(config = {}) {
210
213
  Object.defineProperty(this, "apiKey", {
211
214
  enumerable: true,
@@ -352,6 +355,12 @@ class Client {
352
355
  writable: true,
353
356
  value: void 0
354
357
  });
358
+ Object.defineProperty(this, "fetchImplementation", {
359
+ enumerable: true,
360
+ configurable: true,
361
+ writable: true,
362
+ value: void 0
363
+ });
355
364
  Object.defineProperty(this, "multipartStreamingDisabled", {
356
365
  enumerable: true,
357
366
  configurable: true,
@@ -378,6 +387,7 @@ class Client {
378
387
  this.timeout_ms = config.timeout_ms ?? 90_000;
379
388
  this.caller = new async_caller_js_1.AsyncCaller({
380
389
  ...(config.callerOptions ?? {}),
390
+ maxRetries: 4,
381
391
  debug: config.debug ?? this.debug,
382
392
  });
383
393
  this.traceBatchConcurrency =
@@ -386,6 +396,7 @@ class Client {
386
396
  throw new Error("Trace batch concurrency must be positive.");
387
397
  }
388
398
  this.debug = config.debug ?? this.debug;
399
+ this.fetchImplementation = config.fetchImplementation;
389
400
  this.batchIngestCaller = new async_caller_js_1.AsyncCaller({
390
401
  maxRetries: 2,
391
402
  maxConcurrency: this.traceBatchConcurrency,
@@ -505,13 +516,16 @@ class Client {
505
516
  async _getResponse(path, queryParams) {
506
517
  const paramsString = queryParams?.toString() ?? "";
507
518
  const url = `${this.apiUrl}${path}?${paramsString}`;
508
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), url, {
509
- method: "GET",
510
- headers: this.headers,
511
- signal: AbortSignal.timeout(this.timeout_ms),
512
- ...this.fetchOptions,
519
+ const response = await this.caller.call(async () => {
520
+ const res = await this._fetch(url, {
521
+ method: "GET",
522
+ headers: this.headers,
523
+ signal: AbortSignal.timeout(this.timeout_ms),
524
+ ...this.fetchOptions,
525
+ });
526
+ await (0, error_js_1.raiseForStatus)(res, `Failed to fetch ${path}`);
527
+ return res;
513
528
  });
514
- await (0, error_js_1.raiseForStatus)(response, `Failed to fetch ${path}`);
515
529
  return response;
516
530
  }
517
531
  async _get(path, queryParams) {
@@ -525,13 +539,16 @@ class Client {
525
539
  queryParams.set("offset", String(offset));
526
540
  queryParams.set("limit", String(limit));
527
541
  const url = `${this.apiUrl}${path}?${queryParams}`;
528
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), url, {
529
- method: "GET",
530
- headers: this.headers,
531
- signal: AbortSignal.timeout(this.timeout_ms),
532
- ...this.fetchOptions,
542
+ const response = await this.caller.call(async () => {
543
+ const res = await this._fetch(url, {
544
+ method: "GET",
545
+ headers: this.headers,
546
+ signal: AbortSignal.timeout(this.timeout_ms),
547
+ ...this.fetchOptions,
548
+ });
549
+ await (0, error_js_1.raiseForStatus)(res, `Failed to fetch ${path}`);
550
+ return res;
533
551
  });
534
- await (0, error_js_1.raiseForStatus)(response, `Failed to fetch ${path}`);
535
552
  const items = transform
536
553
  ? transform(await response.json())
537
554
  : await response.json();
@@ -548,12 +565,17 @@ class Client {
548
565
  async *_getCursorPaginatedList(path, body = null, requestMethod = "POST", dataKey = "runs") {
549
566
  const bodyParams = body ? { ...body } : {};
550
567
  while (true) {
551
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}${path}`, {
552
- method: requestMethod,
553
- headers: { ...this.headers, "Content-Type": "application/json" },
554
- signal: AbortSignal.timeout(this.timeout_ms),
555
- ...this.fetchOptions,
556
- body: JSON.stringify(bodyParams),
568
+ const body = JSON.stringify(bodyParams);
569
+ const response = await this.caller.call(async () => {
570
+ const res = await this._fetch(`${this.apiUrl}${path}`, {
571
+ method: requestMethod,
572
+ headers: { ...this.headers, "Content-Type": "application/json" },
573
+ signal: AbortSignal.timeout(this.timeout_ms),
574
+ ...this.fetchOptions,
575
+ body,
576
+ });
577
+ await (0, error_js_1.raiseForStatus)(res, `Failed to fetch ${path}`);
578
+ return res;
557
579
  });
558
580
  const responseBody = await response.json();
559
581
  if (!responseBody) {
@@ -747,7 +769,7 @@ class Client {
747
769
  }
748
770
  async _getServerInfo() {
749
771
  const response = await this.caller.call(async () => {
750
- const res = await (0, fetch_js_1._getFetchImplementation)(this.debug)(`${this.apiUrl}/info`, {
772
+ const res = await this._fetch(`${this.apiUrl}/info`, {
751
773
  method: "GET",
752
774
  headers: { Accept: "application/json" },
753
775
  signal: AbortSignal.timeout(SERVER_INFO_REQUEST_TIMEOUT_MS),
@@ -772,7 +794,7 @@ class Client {
772
794
  this._serverInfo = await this._getServerInfo();
773
795
  }
774
796
  catch (e) {
775
- console.warn(`[WARNING]: LangSmith failed to fetch info on supported operations with status code ${e.status}. Falling back to batch operations and default limits.`);
797
+ console.warn(`[LANGSMITH]: Failed to fetch info on supported operations. Falling back to batch operations and default limits. Info: ${e.status ?? "Unspecified status code"} ${e.message}`);
776
798
  }
777
799
  }
778
800
  return this._serverInfo ?? {};
@@ -841,14 +863,18 @@ class Client {
841
863
  if (options?.apiKey !== undefined) {
842
864
  headers["x-api-key"] = options.apiKey;
843
865
  }
844
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${options?.apiUrl ?? this.apiUrl}/runs`, {
845
- method: "POST",
846
- headers,
847
- body: (0, index_js_2.serialize)(mergedRunCreateParam, `Creating run with id: ${mergedRunCreateParam.id}`),
848
- signal: AbortSignal.timeout(this.timeout_ms),
849
- ...this.fetchOptions,
866
+ const body = (0, index_js_2.serialize)(mergedRunCreateParam, `Creating run with id: ${mergedRunCreateParam.id}`);
867
+ await this.caller.call(async () => {
868
+ const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs`, {
869
+ method: "POST",
870
+ headers,
871
+ signal: AbortSignal.timeout(this.timeout_ms),
872
+ ...this.fetchOptions,
873
+ body,
874
+ });
875
+ await (0, error_js_1.raiseForStatus)(res, "create run", true);
876
+ return res;
850
877
  });
851
- await (0, error_js_1.raiseForStatus)(response, "create run", true);
852
878
  }
853
879
  /**
854
880
  * Batch ingest/upsert multiple runs in the Langsmith system.
@@ -921,14 +947,17 @@ class Client {
921
947
  if (options?.apiKey !== undefined) {
922
948
  headers["x-api-key"] = options.apiKey;
923
949
  }
924
- const response = await this.batchIngestCaller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${options?.apiUrl ?? this.apiUrl}/runs/batch`, {
925
- method: "POST",
926
- headers,
927
- body: body,
928
- signal: AbortSignal.timeout(this.timeout_ms),
929
- ...this.fetchOptions,
950
+ await this.batchIngestCaller.call(async () => {
951
+ const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/batch`, {
952
+ method: "POST",
953
+ headers,
954
+ signal: AbortSignal.timeout(this.timeout_ms),
955
+ ...this.fetchOptions,
956
+ body,
957
+ });
958
+ await (0, error_js_1.raiseForStatus)(res, "batch create run", true);
959
+ return res;
930
960
  });
931
- await (0, error_js_1.raiseForStatus)(response, "batch create run", true);
932
961
  }
933
962
  /**
934
963
  * Batch ingest/upsert multiple runs in the Langsmith system.
@@ -1132,40 +1161,47 @@ class Client {
1132
1161
  const isNodeFetch = (0, fetch_js_1._globalFetchImplementationIsNodeFetch)();
1133
1162
  const buildBuffered = () => this._createNodeFetchBody(parts, boundary);
1134
1163
  const buildStream = () => this._createMultipartStream(parts, boundary);
1135
- const send = async (body) => {
1136
- const headers = {
1137
- ...this.headers,
1138
- "Content-Type": `multipart/form-data; boundary=${boundary}`,
1139
- };
1140
- if (options?.apiKey !== undefined) {
1141
- headers["x-api-key"] = options.apiKey;
1142
- }
1143
- let transformedBody = body;
1144
- if (options?.useGzip &&
1145
- typeof body === "object" &&
1146
- "pipeThrough" in body) {
1147
- transformedBody = body.pipeThrough(new CompressionStream("gzip"));
1148
- headers["Content-Encoding"] = "gzip";
1149
- }
1150
- return this.batchIngestCaller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${options?.apiUrl ?? this.apiUrl}/runs/multipart`, {
1151
- method: "POST",
1152
- headers,
1153
- body: transformedBody,
1154
- duplex: "half",
1155
- signal: AbortSignal.timeout(this.timeout_ms),
1156
- ...this.fetchOptions,
1164
+ const sendWithRetry = async (bodyFactory) => {
1165
+ return this.batchIngestCaller.call(async () => {
1166
+ const body = await bodyFactory();
1167
+ const headers = {
1168
+ ...this.headers,
1169
+ "Content-Type": `multipart/form-data; boundary=${boundary}`,
1170
+ };
1171
+ if (options?.apiKey !== undefined) {
1172
+ headers["x-api-key"] = options.apiKey;
1173
+ }
1174
+ let transformedBody = body;
1175
+ if (options?.useGzip &&
1176
+ typeof body === "object" &&
1177
+ "pipeThrough" in body) {
1178
+ transformedBody = body.pipeThrough(new CompressionStream("gzip"));
1179
+ headers["Content-Encoding"] = "gzip";
1180
+ }
1181
+ const response = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/multipart`, {
1182
+ method: "POST",
1183
+ headers,
1184
+ body: transformedBody,
1185
+ duplex: "half",
1186
+ signal: AbortSignal.timeout(this.timeout_ms),
1187
+ ...this.fetchOptions,
1188
+ });
1189
+ await (0, error_js_1.raiseForStatus)(response, `Failed to send multipart request`, true);
1190
+ return response;
1157
1191
  });
1158
1192
  };
1159
1193
  try {
1160
1194
  let res;
1161
1195
  let streamedAttempt = false;
1162
- // attempt stream only if not disabled and not using node-fetch
1163
- if (!isNodeFetch && !this.multipartStreamingDisabled) {
1196
+ // attempt stream only if not disabled and not using node-fetch or Bun
1197
+ if (!isNodeFetch &&
1198
+ !this.multipartStreamingDisabled &&
1199
+ (0, env_js_1.getEnv)() !== "bun") {
1164
1200
  streamedAttempt = true;
1165
- res = await send(await buildStream());
1201
+ res = await sendWithRetry(buildStream);
1166
1202
  }
1167
1203
  else {
1168
- res = await send(await buildBuffered());
1204
+ res = await sendWithRetry(buildBuffered);
1169
1205
  }
1170
1206
  // if stream fails, fallback to buffered body
1171
1207
  if ((!this.multipartStreamingDisabled || streamedAttempt) &&
@@ -1177,10 +1213,8 @@ class Client {
1177
1213
  // Disable streaming for future requests
1178
1214
  this.multipartStreamingDisabled = true;
1179
1215
  // retry with fully-buffered body
1180
- res = await send(await buildBuffered());
1216
+ res = await sendWithRetry(buildBuffered);
1181
1217
  }
1182
- // raise if still failing
1183
- await (0, error_js_1.raiseForStatus)(res, "ingest multipart runs", true);
1184
1218
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1185
1219
  }
1186
1220
  catch (e) {
@@ -1237,14 +1271,18 @@ class Client {
1237
1271
  if (options?.apiKey !== undefined) {
1238
1272
  headers["x-api-key"] = options.apiKey;
1239
1273
  }
1240
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${options?.apiUrl ?? this.apiUrl}/runs/${runId}`, {
1241
- method: "PATCH",
1242
- headers,
1243
- body: (0, index_js_2.serialize)(run, `Serializing payload to update run with id: ${runId}`),
1244
- signal: AbortSignal.timeout(this.timeout_ms),
1245
- ...this.fetchOptions,
1274
+ const body = (0, index_js_2.serialize)(run, `Serializing payload to update run with id: ${runId}`);
1275
+ await this.caller.call(async () => {
1276
+ const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/${runId}`, {
1277
+ method: "PATCH",
1278
+ headers,
1279
+ signal: AbortSignal.timeout(this.timeout_ms),
1280
+ ...this.fetchOptions,
1281
+ body,
1282
+ });
1283
+ await (0, error_js_1.raiseForStatus)(res, "update run", true);
1284
+ return res;
1246
1285
  });
1247
- await (0, error_js_1.raiseForStatus)(response, "update run", true);
1248
1286
  }
1249
1287
  async readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
1250
1288
  (0, _uuid_js_1.assertUuid)(runId);
@@ -1502,14 +1540,18 @@ class Client {
1502
1540
  };
1503
1541
  // Remove undefined values from the payload
1504
1542
  const filteredPayload = Object.fromEntries(Object.entries(currentBody).filter(([_, value]) => value !== undefined));
1505
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(), url, {
1506
- method: "POST",
1507
- headers: { ...this.headers, "Content-Type": "application/json" },
1508
- body: JSON.stringify(filteredPayload),
1509
- signal: AbortSignal.timeout(this.timeout_ms),
1510
- ...this.fetchOptions,
1543
+ const body = JSON.stringify(filteredPayload);
1544
+ const response = await this.caller.call(async () => {
1545
+ const res = await this._fetch(url, {
1546
+ method: "POST",
1547
+ headers: { ...this.headers, "Content-Type": "application/json" },
1548
+ signal: AbortSignal.timeout(this.timeout_ms),
1549
+ ...this.fetchOptions,
1550
+ body,
1551
+ });
1552
+ await (0, error_js_1.raiseForStatus)(res, `Failed to fetch ${path}`);
1553
+ return res;
1511
1554
  });
1512
- await (0, error_js_1.raiseForStatus)(response, `Failed to fetch ${path}`);
1513
1555
  const items = await response.json();
1514
1556
  const { groups, total } = items;
1515
1557
  if (groups.length === 0) {
@@ -1551,12 +1593,17 @@ class Client {
1551
1593
  };
1552
1594
  // Remove undefined values from the payload
1553
1595
  const filteredPayload = Object.fromEntries(Object.entries(payload).filter(([_, value]) => value !== undefined));
1554
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/runs/stats`, {
1555
- method: "POST",
1556
- headers: this.headers,
1557
- body: JSON.stringify(filteredPayload),
1558
- signal: AbortSignal.timeout(this.timeout_ms),
1559
- ...this.fetchOptions,
1596
+ const body = JSON.stringify(filteredPayload);
1597
+ const response = await this.caller.call(async () => {
1598
+ const res = await this._fetch(`${this.apiUrl}/runs/stats`, {
1599
+ method: "POST",
1600
+ headers: this.headers,
1601
+ signal: AbortSignal.timeout(this.timeout_ms),
1602
+ ...this.fetchOptions,
1603
+ body,
1604
+ });
1605
+ await (0, error_js_1.raiseForStatus)(res, "get run stats");
1606
+ return res;
1560
1607
  });
1561
1608
  const result = await response.json();
1562
1609
  return result;
@@ -1567,12 +1614,17 @@ class Client {
1567
1614
  share_token: shareId || uuid.v4(),
1568
1615
  };
1569
1616
  (0, _uuid_js_1.assertUuid)(runId);
1570
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/runs/${runId}/share`, {
1571
- method: "PUT",
1572
- headers: this.headers,
1573
- body: JSON.stringify(data),
1574
- signal: AbortSignal.timeout(this.timeout_ms),
1575
- ...this.fetchOptions,
1617
+ const body = JSON.stringify(data);
1618
+ const response = await this.caller.call(async () => {
1619
+ const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
1620
+ method: "PUT",
1621
+ headers: this.headers,
1622
+ signal: AbortSignal.timeout(this.timeout_ms),
1623
+ ...this.fetchOptions,
1624
+ body,
1625
+ });
1626
+ await (0, error_js_1.raiseForStatus)(res, "share run");
1627
+ return res;
1576
1628
  });
1577
1629
  const result = await response.json();
1578
1630
  if (result === null || !("share_token" in result)) {
@@ -1582,21 +1634,28 @@ class Client {
1582
1634
  }
1583
1635
  async unshareRun(runId) {
1584
1636
  (0, _uuid_js_1.assertUuid)(runId);
1585
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/runs/${runId}/share`, {
1586
- method: "DELETE",
1587
- headers: this.headers,
1588
- signal: AbortSignal.timeout(this.timeout_ms),
1589
- ...this.fetchOptions,
1637
+ await this.caller.call(async () => {
1638
+ const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
1639
+ method: "DELETE",
1640
+ headers: this.headers,
1641
+ signal: AbortSignal.timeout(this.timeout_ms),
1642
+ ...this.fetchOptions,
1643
+ });
1644
+ await (0, error_js_1.raiseForStatus)(res, "unshare run", true);
1645
+ return res;
1590
1646
  });
1591
- await (0, error_js_1.raiseForStatus)(response, "unshare run", true);
1592
1647
  }
1593
1648
  async readRunSharedLink(runId) {
1594
1649
  (0, _uuid_js_1.assertUuid)(runId);
1595
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/runs/${runId}/share`, {
1596
- method: "GET",
1597
- headers: this.headers,
1598
- signal: AbortSignal.timeout(this.timeout_ms),
1599
- ...this.fetchOptions,
1650
+ const response = await this.caller.call(async () => {
1651
+ const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
1652
+ method: "GET",
1653
+ headers: this.headers,
1654
+ signal: AbortSignal.timeout(this.timeout_ms),
1655
+ ...this.fetchOptions,
1656
+ });
1657
+ await (0, error_js_1.raiseForStatus)(res, "read run shared link");
1658
+ return res;
1600
1659
  });
1601
1660
  const result = await response.json();
1602
1661
  if (result === null || !("share_token" in result)) {
@@ -1614,11 +1673,15 @@ class Client {
1614
1673
  }
1615
1674
  }
1616
1675
  (0, _uuid_js_1.assertUuid)(shareToken);
1617
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/public/${shareToken}/runs${queryParams}`, {
1618
- method: "GET",
1619
- headers: this.headers,
1620
- signal: AbortSignal.timeout(this.timeout_ms),
1621
- ...this.fetchOptions,
1676
+ const response = await this.caller.call(async () => {
1677
+ const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/runs${queryParams}`, {
1678
+ method: "GET",
1679
+ headers: this.headers,
1680
+ signal: AbortSignal.timeout(this.timeout_ms),
1681
+ ...this.fetchOptions,
1682
+ });
1683
+ await (0, error_js_1.raiseForStatus)(res, "list shared runs");
1684
+ return res;
1622
1685
  });
1623
1686
  const runs = await response.json();
1624
1687
  return runs;
@@ -1632,11 +1695,15 @@ class Client {
1632
1695
  datasetId = dataset.id;
1633
1696
  }
1634
1697
  (0, _uuid_js_1.assertUuid)(datasetId);
1635
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/${datasetId}/share`, {
1636
- method: "GET",
1637
- headers: this.headers,
1638
- signal: AbortSignal.timeout(this.timeout_ms),
1639
- ...this.fetchOptions,
1698
+ const response = await this.caller.call(async () => {
1699
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
1700
+ method: "GET",
1701
+ headers: this.headers,
1702
+ signal: AbortSignal.timeout(this.timeout_ms),
1703
+ ...this.fetchOptions,
1704
+ });
1705
+ await (0, error_js_1.raiseForStatus)(res, "read dataset shared schema");
1706
+ return res;
1640
1707
  });
1641
1708
  const shareSchema = await response.json();
1642
1709
  shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
@@ -1654,12 +1721,17 @@ class Client {
1654
1721
  dataset_id: datasetId,
1655
1722
  };
1656
1723
  (0, _uuid_js_1.assertUuid)(datasetId);
1657
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/${datasetId}/share`, {
1658
- method: "PUT",
1659
- headers: this.headers,
1660
- body: JSON.stringify(data),
1661
- signal: AbortSignal.timeout(this.timeout_ms),
1662
- ...this.fetchOptions,
1724
+ const body = JSON.stringify(data);
1725
+ const response = await this.caller.call(async () => {
1726
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
1727
+ method: "PUT",
1728
+ headers: this.headers,
1729
+ signal: AbortSignal.timeout(this.timeout_ms),
1730
+ ...this.fetchOptions,
1731
+ body,
1732
+ });
1733
+ await (0, error_js_1.raiseForStatus)(res, "share dataset");
1734
+ return res;
1663
1735
  });
1664
1736
  const shareSchema = await response.json();
1665
1737
  shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
@@ -1667,21 +1739,28 @@ class Client {
1667
1739
  }
1668
1740
  async unshareDataset(datasetId) {
1669
1741
  (0, _uuid_js_1.assertUuid)(datasetId);
1670
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/${datasetId}/share`, {
1671
- method: "DELETE",
1672
- headers: this.headers,
1673
- signal: AbortSignal.timeout(this.timeout_ms),
1674
- ...this.fetchOptions,
1742
+ await this.caller.call(async () => {
1743
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
1744
+ method: "DELETE",
1745
+ headers: this.headers,
1746
+ signal: AbortSignal.timeout(this.timeout_ms),
1747
+ ...this.fetchOptions,
1748
+ });
1749
+ await (0, error_js_1.raiseForStatus)(res, "unshare dataset", true);
1750
+ return res;
1675
1751
  });
1676
- await (0, error_js_1.raiseForStatus)(response, "unshare dataset", true);
1677
1752
  }
1678
1753
  async readSharedDataset(shareToken) {
1679
1754
  (0, _uuid_js_1.assertUuid)(shareToken);
1680
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/public/${shareToken}/datasets`, {
1681
- method: "GET",
1682
- headers: this.headers,
1683
- signal: AbortSignal.timeout(this.timeout_ms),
1684
- ...this.fetchOptions,
1755
+ const response = await this.caller.call(async () => {
1756
+ const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/datasets`, {
1757
+ method: "GET",
1758
+ headers: this.headers,
1759
+ signal: AbortSignal.timeout(this.timeout_ms),
1760
+ ...this.fetchOptions,
1761
+ });
1762
+ await (0, error_js_1.raiseForStatus)(res, "read shared dataset");
1763
+ return res;
1685
1764
  });
1686
1765
  const dataset = await response.json();
1687
1766
  return dataset;
@@ -1708,11 +1787,15 @@ class Client {
1708
1787
  urlParams.append(key, value);
1709
1788
  }
1710
1789
  });
1711
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
1712
- method: "GET",
1713
- headers: this.headers,
1714
- signal: AbortSignal.timeout(this.timeout_ms),
1715
- ...this.fetchOptions,
1790
+ const response = await this.caller.call(async () => {
1791
+ const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
1792
+ method: "GET",
1793
+ headers: this.headers,
1794
+ signal: AbortSignal.timeout(this.timeout_ms),
1795
+ ...this.fetchOptions,
1796
+ });
1797
+ await (0, error_js_1.raiseForStatus)(res, "list shared examples");
1798
+ return res;
1716
1799
  });
1717
1800
  const result = await response.json();
1718
1801
  if (!response.ok) {
@@ -1743,14 +1826,18 @@ class Client {
1743
1826
  if (referenceDatasetId !== null) {
1744
1827
  body["reference_dataset_id"] = referenceDatasetId;
1745
1828
  }
1746
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), endpoint, {
1747
- method: "POST",
1748
- headers: { ...this.headers, "Content-Type": "application/json" },
1749
- body: JSON.stringify(body),
1750
- signal: AbortSignal.timeout(this.timeout_ms),
1751
- ...this.fetchOptions,
1829
+ const serializedBody = JSON.stringify(body);
1830
+ const response = await this.caller.call(async () => {
1831
+ const res = await this._fetch(endpoint, {
1832
+ method: "POST",
1833
+ headers: { ...this.headers, "Content-Type": "application/json" },
1834
+ signal: AbortSignal.timeout(this.timeout_ms),
1835
+ ...this.fetchOptions,
1836
+ body: serializedBody,
1837
+ });
1838
+ await (0, error_js_1.raiseForStatus)(res, "create project");
1839
+ return res;
1752
1840
  });
1753
- await (0, error_js_1.raiseForStatus)(response, "create project");
1754
1841
  const result = await response.json();
1755
1842
  return result;
1756
1843
  }
@@ -1760,20 +1847,23 @@ class Client {
1760
1847
  if (metadata) {
1761
1848
  extra = { ...(extra || {}), metadata };
1762
1849
  }
1763
- const body = {
1850
+ const body = JSON.stringify({
1764
1851
  name,
1765
1852
  extra,
1766
1853
  description,
1767
1854
  end_time: endTime ? new Date(endTime).toISOString() : null,
1768
- };
1769
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), endpoint, {
1770
- method: "PATCH",
1771
- headers: { ...this.headers, "Content-Type": "application/json" },
1772
- body: JSON.stringify(body),
1773
- signal: AbortSignal.timeout(this.timeout_ms),
1774
- ...this.fetchOptions,
1775
- });
1776
- await (0, error_js_1.raiseForStatus)(response, "update project");
1855
+ });
1856
+ const response = await this.caller.call(async () => {
1857
+ const res = await this._fetch(endpoint, {
1858
+ method: "PATCH",
1859
+ headers: { ...this.headers, "Content-Type": "application/json" },
1860
+ signal: AbortSignal.timeout(this.timeout_ms),
1861
+ ...this.fetchOptions,
1862
+ body,
1863
+ });
1864
+ await (0, error_js_1.raiseForStatus)(res, "update project");
1865
+ return res;
1866
+ });
1777
1867
  const result = await response.json();
1778
1868
  return result;
1779
1869
  }
@@ -1794,11 +1884,15 @@ class Client {
1794
1884
  else {
1795
1885
  throw new Error("Must provide projectName or projectId");
1796
1886
  }
1797
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}${path}?${params}`, {
1798
- method: "GET",
1799
- headers: this.headers,
1800
- signal: AbortSignal.timeout(this.timeout_ms),
1801
- ...this.fetchOptions,
1887
+ const response = await this.caller.call(async () => {
1888
+ const res = await this._fetch(`${this.apiUrl}${path}?${params}`, {
1889
+ method: "GET",
1890
+ headers: this.headers,
1891
+ signal: AbortSignal.timeout(this.timeout_ms),
1892
+ ...this.fetchOptions,
1893
+ });
1894
+ await (0, error_js_1.raiseForStatus)(res, "has project");
1895
+ return res;
1802
1896
  });
1803
1897
  // consume the response body to release the connection
1804
1898
  // https://undici.nodejs.org/#/?id=garbage-collection
@@ -1924,13 +2018,16 @@ class Client {
1924
2018
  projectId_ = projectId;
1925
2019
  }
1926
2020
  (0, _uuid_js_1.assertUuid)(projectId_);
1927
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/sessions/${projectId_}`, {
1928
- method: "DELETE",
1929
- headers: this.headers,
1930
- signal: AbortSignal.timeout(this.timeout_ms),
1931
- ...this.fetchOptions,
2021
+ await this.caller.call(async () => {
2022
+ const res = await this._fetch(`${this.apiUrl}/sessions/${projectId_}`, {
2023
+ method: "DELETE",
2024
+ headers: this.headers,
2025
+ signal: AbortSignal.timeout(this.timeout_ms),
2026
+ ...this.fetchOptions,
2027
+ });
2028
+ await (0, error_js_1.raiseForStatus)(res, `delete session ${projectId_} (${projectName})`, true);
2029
+ return res;
1932
2030
  });
1933
- await (0, error_js_1.raiseForStatus)(response, `delete session ${projectId_} (${projectName})`, true);
1934
2031
  }
1935
2032
  async uploadCsv({ csvFile, fileName, inputKeys, outputKeys, description, dataType, name, }) {
1936
2033
  const url = `${this.apiUrl}/datasets/upload`;
@@ -1951,14 +2048,17 @@ class Client {
1951
2048
  if (name) {
1952
2049
  formData.append("name", name);
1953
2050
  }
1954
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), url, {
1955
- method: "POST",
1956
- headers: this.headers,
1957
- body: formData,
1958
- signal: AbortSignal.timeout(this.timeout_ms),
1959
- ...this.fetchOptions,
2051
+ const response = await this.caller.call(async () => {
2052
+ const res = await this._fetch(url, {
2053
+ method: "POST",
2054
+ headers: this.headers,
2055
+ signal: AbortSignal.timeout(this.timeout_ms),
2056
+ ...this.fetchOptions,
2057
+ body: formData,
2058
+ });
2059
+ await (0, error_js_1.raiseForStatus)(res, "upload CSV");
2060
+ return res;
1960
2061
  });
1961
- await (0, error_js_1.raiseForStatus)(response, "upload CSV");
1962
2062
  const result = await response.json();
1963
2063
  return result;
1964
2064
  }
@@ -1977,14 +2077,18 @@ class Client {
1977
2077
  if (outputsSchema) {
1978
2078
  body.outputs_schema_definition = outputsSchema;
1979
2079
  }
1980
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets`, {
1981
- method: "POST",
1982
- headers: { ...this.headers, "Content-Type": "application/json" },
1983
- body: JSON.stringify(body),
1984
- signal: AbortSignal.timeout(this.timeout_ms),
1985
- ...this.fetchOptions,
2080
+ const serializedBody = JSON.stringify(body);
2081
+ const response = await this.caller.call(async () => {
2082
+ const res = await this._fetch(`${this.apiUrl}/datasets`, {
2083
+ method: "POST",
2084
+ headers: { ...this.headers, "Content-Type": "application/json" },
2085
+ signal: AbortSignal.timeout(this.timeout_ms),
2086
+ ...this.fetchOptions,
2087
+ body: serializedBody,
2088
+ });
2089
+ await (0, error_js_1.raiseForStatus)(res, "create dataset");
2090
+ return res;
1986
2091
  });
1987
- await (0, error_js_1.raiseForStatus)(response, "create dataset");
1988
2092
  const result = await response.json();
1989
2093
  return result;
1990
2094
  }
@@ -2109,14 +2213,18 @@ class Client {
2109
2213
  }
2110
2214
  const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
2111
2215
  (0, _uuid_js_1.assertUuid)(_datasetId);
2112
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/${_datasetId}`, {
2113
- method: "PATCH",
2114
- headers: { ...this.headers, "Content-Type": "application/json" },
2115
- body: JSON.stringify(update),
2116
- signal: AbortSignal.timeout(this.timeout_ms),
2117
- ...this.fetchOptions,
2118
- });
2119
- await (0, error_js_1.raiseForStatus)(response, "update dataset");
2216
+ const body = JSON.stringify(update);
2217
+ const response = await this.caller.call(async () => {
2218
+ const res = await this._fetch(`${this.apiUrl}/datasets/${_datasetId}`, {
2219
+ method: "PATCH",
2220
+ headers: { ...this.headers, "Content-Type": "application/json" },
2221
+ signal: AbortSignal.timeout(this.timeout_ms),
2222
+ ...this.fetchOptions,
2223
+ body,
2224
+ });
2225
+ await (0, error_js_1.raiseForStatus)(res, "update dataset");
2226
+ return res;
2227
+ });
2120
2228
  return (await response.json());
2121
2229
  }
2122
2230
  /**
@@ -2141,17 +2249,21 @@ class Client {
2141
2249
  }
2142
2250
  const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
2143
2251
  (0, _uuid_js_1.assertUuid)(_datasetId);
2144
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/${_datasetId}/tags`, {
2145
- method: "PUT",
2146
- headers: { ...this.headers, "Content-Type": "application/json" },
2147
- body: JSON.stringify({
2148
- as_of: typeof asOf === "string" ? asOf : asOf.toISOString(),
2149
- tag,
2150
- }),
2151
- signal: AbortSignal.timeout(this.timeout_ms),
2152
- ...this.fetchOptions,
2252
+ const body = JSON.stringify({
2253
+ as_of: typeof asOf === "string" ? asOf : asOf.toISOString(),
2254
+ tag,
2255
+ });
2256
+ await this.caller.call(async () => {
2257
+ const res = await this._fetch(`${this.apiUrl}/datasets/${_datasetId}/tags`, {
2258
+ method: "PUT",
2259
+ headers: { ...this.headers, "Content-Type": "application/json" },
2260
+ signal: AbortSignal.timeout(this.timeout_ms),
2261
+ ...this.fetchOptions,
2262
+ body,
2263
+ });
2264
+ await (0, error_js_1.raiseForStatus)(res, "update dataset tags", true);
2265
+ return res;
2153
2266
  });
2154
- await (0, error_js_1.raiseForStatus)(response, "update dataset tags");
2155
2267
  }
2156
2268
  async deleteDataset({ datasetId, datasetName, }) {
2157
2269
  let path = "/datasets";
@@ -2170,14 +2282,16 @@ class Client {
2170
2282
  else {
2171
2283
  throw new Error("Must provide datasetName or datasetId");
2172
2284
  }
2173
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), this.apiUrl + path, {
2174
- method: "DELETE",
2175
- headers: this.headers,
2176
- signal: AbortSignal.timeout(this.timeout_ms),
2177
- ...this.fetchOptions,
2285
+ await this.caller.call(async () => {
2286
+ const res = await this._fetch(this.apiUrl + path, {
2287
+ method: "DELETE",
2288
+ headers: this.headers,
2289
+ signal: AbortSignal.timeout(this.timeout_ms),
2290
+ ...this.fetchOptions,
2291
+ });
2292
+ await (0, error_js_1.raiseForStatus)(res, `delete ${path}`, true);
2293
+ return res;
2178
2294
  });
2179
- await (0, error_js_1.raiseForStatus)(response, `delete ${path}`);
2180
- await response.json();
2181
2295
  }
2182
2296
  async indexDataset({ datasetId, datasetName, tag, }) {
2183
2297
  let datasetId_ = datasetId;
@@ -2195,14 +2309,18 @@ class Client {
2195
2309
  const data = {
2196
2310
  tag: tag,
2197
2311
  };
2198
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/${datasetId_}/index`, {
2199
- method: "POST",
2200
- headers: { ...this.headers, "Content-Type": "application/json" },
2201
- body: JSON.stringify(data),
2202
- signal: AbortSignal.timeout(this.timeout_ms),
2203
- ...this.fetchOptions,
2204
- });
2205
- await (0, error_js_1.raiseForStatus)(response, "index dataset");
2312
+ const body = JSON.stringify(data);
2313
+ const response = await this.caller.call(async () => {
2314
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId_}/index`, {
2315
+ method: "POST",
2316
+ headers: { ...this.headers, "Content-Type": "application/json" },
2317
+ signal: AbortSignal.timeout(this.timeout_ms),
2318
+ ...this.fetchOptions,
2319
+ body,
2320
+ });
2321
+ await (0, error_js_1.raiseForStatus)(res, "index dataset");
2322
+ return res;
2323
+ });
2206
2324
  await response.json();
2207
2325
  }
2208
2326
  /**
@@ -2244,14 +2362,18 @@ class Client {
2244
2362
  data["filter"] = filter;
2245
2363
  }
2246
2364
  (0, _uuid_js_1.assertUuid)(datasetId);
2247
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/${datasetId}/search`, {
2248
- method: "POST",
2249
- headers: { ...this.headers, "Content-Type": "application/json" },
2250
- body: JSON.stringify(data),
2251
- signal: AbortSignal.timeout(this.timeout_ms),
2252
- ...this.fetchOptions,
2253
- });
2254
- await (0, error_js_1.raiseForStatus)(response, "fetch similar examples");
2365
+ const body = JSON.stringify(data);
2366
+ const response = await this.caller.call(async () => {
2367
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/search`, {
2368
+ headers: { ...this.headers, "Content-Type": "application/json" },
2369
+ signal: AbortSignal.timeout(this.timeout_ms),
2370
+ ...this.fetchOptions,
2371
+ method: "POST",
2372
+ body,
2373
+ });
2374
+ await (0, error_js_1.raiseForStatus)(res, "fetch similar examples");
2375
+ return res;
2376
+ });
2255
2377
  const result = await response.json();
2256
2378
  return result["examples"];
2257
2379
  }
@@ -2463,14 +2585,16 @@ class Client {
2463
2585
  async deleteExample(exampleId) {
2464
2586
  (0, _uuid_js_1.assertUuid)(exampleId);
2465
2587
  const path = `/examples/${exampleId}`;
2466
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), this.apiUrl + path, {
2467
- method: "DELETE",
2468
- headers: this.headers,
2469
- signal: AbortSignal.timeout(this.timeout_ms),
2470
- ...this.fetchOptions,
2588
+ await this.caller.call(async () => {
2589
+ const res = await this._fetch(this.apiUrl + path, {
2590
+ method: "DELETE",
2591
+ headers: this.headers,
2592
+ signal: AbortSignal.timeout(this.timeout_ms),
2593
+ ...this.fetchOptions,
2594
+ });
2595
+ await (0, error_js_1.raiseForStatus)(res, `delete ${path}`, true);
2596
+ return res;
2471
2597
  });
2472
- await (0, error_js_1.raiseForStatus)(response, `delete ${path}`);
2473
- await response.json();
2474
2598
  }
2475
2599
  async updateExample(exampleIdOrUpdate, update) {
2476
2600
  let exampleId;
@@ -2542,13 +2666,16 @@ class Client {
2542
2666
  if (tag !== undefined) {
2543
2667
  params.append("tag", tag);
2544
2668
  }
2545
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/${resolvedDatasetId}/version?${params.toString()}`, {
2546
- method: "GET",
2547
- headers: { ...this.headers },
2548
- signal: AbortSignal.timeout(this.timeout_ms),
2549
- ...this.fetchOptions,
2669
+ const response = await this.caller.call(async () => {
2670
+ const res = await this._fetch(`${this.apiUrl}/datasets/${resolvedDatasetId}/version?${params.toString()}`, {
2671
+ method: "GET",
2672
+ headers: { ...this.headers },
2673
+ signal: AbortSignal.timeout(this.timeout_ms),
2674
+ ...this.fetchOptions,
2675
+ });
2676
+ await (0, error_js_1.raiseForStatus)(res, "read dataset version");
2677
+ return res;
2550
2678
  });
2551
- await (0, error_js_1.raiseForStatus)(response, "read dataset version");
2552
2679
  return await response.json();
2553
2680
  }
2554
2681
  async listDatasetSplits({ datasetId, datasetName, asOf, }) {
@@ -2603,14 +2730,18 @@ class Client {
2603
2730
  }),
2604
2731
  remove,
2605
2732
  };
2606
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/${datasetId_}/splits`, {
2607
- method: "PUT",
2608
- headers: { ...this.headers, "Content-Type": "application/json" },
2609
- body: JSON.stringify(data),
2610
- signal: AbortSignal.timeout(this.timeout_ms),
2611
- ...this.fetchOptions,
2733
+ const body = JSON.stringify(data);
2734
+ await this.caller.call(async () => {
2735
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId_}/splits`, {
2736
+ method: "PUT",
2737
+ headers: { ...this.headers, "Content-Type": "application/json" },
2738
+ signal: AbortSignal.timeout(this.timeout_ms),
2739
+ ...this.fetchOptions,
2740
+ body,
2741
+ });
2742
+ await (0, error_js_1.raiseForStatus)(res, "update dataset splits", true);
2743
+ return res;
2612
2744
  });
2613
- await (0, error_js_1.raiseForStatus)(response, "update dataset splits", true);
2614
2745
  }
2615
2746
  /**
2616
2747
  * @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
@@ -2668,15 +2799,19 @@ class Client {
2668
2799
  feedbackConfig,
2669
2800
  session_id: projectId,
2670
2801
  };
2802
+ const body = JSON.stringify(feedback);
2671
2803
  const url = `${this.apiUrl}/feedback`;
2672
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), url, {
2673
- method: "POST",
2674
- headers: { ...this.headers, "Content-Type": "application/json" },
2675
- body: JSON.stringify(feedback),
2676
- signal: AbortSignal.timeout(this.timeout_ms),
2677
- ...this.fetchOptions,
2678
- });
2679
- await (0, error_js_1.raiseForStatus)(response, "create feedback", true);
2804
+ await this.caller.call(async () => {
2805
+ const res = await this._fetch(url, {
2806
+ method: "POST",
2807
+ headers: { ...this.headers, "Content-Type": "application/json" },
2808
+ signal: AbortSignal.timeout(this.timeout_ms),
2809
+ ...this.fetchOptions,
2810
+ body,
2811
+ });
2812
+ await (0, error_js_1.raiseForStatus)(res, "create feedback", true);
2813
+ return res;
2814
+ });
2680
2815
  return feedback;
2681
2816
  }
2682
2817
  async updateFeedback(feedbackId, { score, value, correction, comment, }) {
@@ -2694,14 +2829,18 @@ class Client {
2694
2829
  feedbackUpdate["comment"] = comment;
2695
2830
  }
2696
2831
  (0, _uuid_js_1.assertUuid)(feedbackId);
2697
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/feedback/${feedbackId}`, {
2698
- method: "PATCH",
2699
- headers: { ...this.headers, "Content-Type": "application/json" },
2700
- body: JSON.stringify(feedbackUpdate),
2701
- signal: AbortSignal.timeout(this.timeout_ms),
2702
- ...this.fetchOptions,
2832
+ const body = JSON.stringify(feedbackUpdate);
2833
+ await this.caller.call(async () => {
2834
+ const res = await this._fetch(`${this.apiUrl}/feedback/${feedbackId}`, {
2835
+ method: "PATCH",
2836
+ headers: { ...this.headers, "Content-Type": "application/json" },
2837
+ signal: AbortSignal.timeout(this.timeout_ms),
2838
+ ...this.fetchOptions,
2839
+ body,
2840
+ });
2841
+ await (0, error_js_1.raiseForStatus)(res, "update feedback", true);
2842
+ return res;
2703
2843
  });
2704
- await (0, error_js_1.raiseForStatus)(response, "update feedback", true);
2705
2844
  }
2706
2845
  async readFeedback(feedbackId) {
2707
2846
  (0, _uuid_js_1.assertUuid)(feedbackId);
@@ -2712,14 +2851,16 @@ class Client {
2712
2851
  async deleteFeedback(feedbackId) {
2713
2852
  (0, _uuid_js_1.assertUuid)(feedbackId);
2714
2853
  const path = `/feedback/${feedbackId}`;
2715
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), this.apiUrl + path, {
2716
- method: "DELETE",
2717
- headers: this.headers,
2718
- signal: AbortSignal.timeout(this.timeout_ms),
2719
- ...this.fetchOptions,
2854
+ await this.caller.call(async () => {
2855
+ const res = await this._fetch(this.apiUrl + path, {
2856
+ method: "DELETE",
2857
+ headers: this.headers,
2858
+ signal: AbortSignal.timeout(this.timeout_ms),
2859
+ ...this.fetchOptions,
2860
+ });
2861
+ await (0, error_js_1.raiseForStatus)(res, `delete ${path}`, true);
2862
+ return res;
2720
2863
  });
2721
- await (0, error_js_1.raiseForStatus)(response, `delete ${path}`);
2722
- await response.json();
2723
2864
  }
2724
2865
  async *listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, } = {}) {
2725
2866
  const queryParams = new URLSearchParams();
@@ -2774,15 +2915,19 @@ class Client {
2774
2915
  hours: 3,
2775
2916
  };
2776
2917
  }
2777
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/feedback/tokens`, {
2778
- method: "POST",
2779
- headers: { ...this.headers, "Content-Type": "application/json" },
2780
- body: JSON.stringify(body),
2781
- signal: AbortSignal.timeout(this.timeout_ms),
2782
- ...this.fetchOptions,
2918
+ const serializedBody = JSON.stringify(body);
2919
+ const response = await this.caller.call(async () => {
2920
+ const res = await this._fetch(`${this.apiUrl}/feedback/tokens`, {
2921
+ method: "POST",
2922
+ headers: { ...this.headers, "Content-Type": "application/json" },
2923
+ signal: AbortSignal.timeout(this.timeout_ms),
2924
+ ...this.fetchOptions,
2925
+ body: serializedBody,
2926
+ });
2927
+ await (0, error_js_1.raiseForStatus)(res, "create presigned feedback token");
2928
+ return res;
2783
2929
  });
2784
- const result = await response.json();
2785
- return result;
2930
+ return await response.json();
2786
2931
  }
2787
2932
  async createComparativeExperiment({ name, experimentIds, referenceDatasetId, createdAt, description, metadata, id, }) {
2788
2933
  if (experimentIds.length === 0) {
@@ -2807,14 +2952,19 @@ class Client {
2807
2952
  };
2808
2953
  if (metadata)
2809
2954
  body.extra["metadata"] = metadata;
2810
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/datasets/comparative`, {
2811
- method: "POST",
2812
- headers: { ...this.headers, "Content-Type": "application/json" },
2813
- body: JSON.stringify(body),
2814
- signal: AbortSignal.timeout(this.timeout_ms),
2815
- ...this.fetchOptions,
2955
+ const serializedBody = JSON.stringify(body);
2956
+ const response = await this.caller.call(async () => {
2957
+ const res = await this._fetch(`${this.apiUrl}/datasets/comparative`, {
2958
+ method: "POST",
2959
+ headers: { ...this.headers, "Content-Type": "application/json" },
2960
+ signal: AbortSignal.timeout(this.timeout_ms),
2961
+ ...this.fetchOptions,
2962
+ body: serializedBody,
2963
+ });
2964
+ await (0, error_js_1.raiseForStatus)(res, "create comparative experiment");
2965
+ return res;
2816
2966
  });
2817
- return await response.json();
2967
+ return response.json();
2818
2968
  }
2819
2969
  /**
2820
2970
  * Retrieves a list of presigned feedback tokens for a given run ID.
@@ -2923,16 +3073,19 @@ class Client {
2923
3073
  id: queueId || uuid.v4(),
2924
3074
  rubric_instructions: rubricInstructions,
2925
3075
  };
2926
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/annotation-queues`, {
2927
- method: "POST",
2928
- headers: { ...this.headers, "Content-Type": "application/json" },
2929
- body: JSON.stringify(Object.fromEntries(Object.entries(body).filter(([_, v]) => v !== undefined))),
2930
- signal: AbortSignal.timeout(this.timeout_ms),
2931
- ...this.fetchOptions,
3076
+ const serializedBody = JSON.stringify(Object.fromEntries(Object.entries(body).filter(([_, v]) => v !== undefined)));
3077
+ const response = await this.caller.call(async () => {
3078
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues`, {
3079
+ method: "POST",
3080
+ headers: { ...this.headers, "Content-Type": "application/json" },
3081
+ signal: AbortSignal.timeout(this.timeout_ms),
3082
+ ...this.fetchOptions,
3083
+ body: serializedBody,
3084
+ });
3085
+ await (0, error_js_1.raiseForStatus)(res, "create annotation queue");
3086
+ return res;
2932
3087
  });
2933
- await (0, error_js_1.raiseForStatus)(response, "create annotation queue");
2934
- const data = await response.json();
2935
- return data;
3088
+ return response.json();
2936
3089
  }
2937
3090
  /**
2938
3091
  * Read an annotation queue with the specified queue ID.
@@ -2940,15 +3093,17 @@ class Client {
2940
3093
  * @returns The AnnotationQueueWithDetails object
2941
3094
  */
2942
3095
  async readAnnotationQueue(queueId) {
2943
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}`, {
2944
- method: "GET",
2945
- headers: this.headers,
2946
- signal: AbortSignal.timeout(this.timeout_ms),
2947
- ...this.fetchOptions,
3096
+ const response = await this.caller.call(async () => {
3097
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}`, {
3098
+ method: "GET",
3099
+ headers: this.headers,
3100
+ signal: AbortSignal.timeout(this.timeout_ms),
3101
+ ...this.fetchOptions,
3102
+ });
3103
+ await (0, error_js_1.raiseForStatus)(res, "read annotation queue");
3104
+ return res;
2948
3105
  });
2949
- await (0, error_js_1.raiseForStatus)(response, "read annotation queue");
2950
- const data = await response.json();
2951
- return data;
3106
+ return response.json();
2952
3107
  }
2953
3108
  /**
2954
3109
  * Update an annotation queue with the specified queue ID.
@@ -2959,31 +3114,38 @@ class Client {
2959
3114
  */
2960
3115
  async updateAnnotationQueue(queueId, options) {
2961
3116
  const { name, description, rubricInstructions } = options;
2962
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}`, {
2963
- method: "PATCH",
2964
- headers: { ...this.headers, "Content-Type": "application/json" },
2965
- body: JSON.stringify({
2966
- name,
2967
- description,
2968
- rubric_instructions: rubricInstructions,
2969
- }),
2970
- signal: AbortSignal.timeout(this.timeout_ms),
2971
- ...this.fetchOptions,
3117
+ const body = JSON.stringify({
3118
+ name,
3119
+ description,
3120
+ rubric_instructions: rubricInstructions,
3121
+ });
3122
+ await this.caller.call(async () => {
3123
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}`, {
3124
+ method: "PATCH",
3125
+ headers: { ...this.headers, "Content-Type": "application/json" },
3126
+ signal: AbortSignal.timeout(this.timeout_ms),
3127
+ ...this.fetchOptions,
3128
+ body,
3129
+ });
3130
+ await (0, error_js_1.raiseForStatus)(res, "update annotation queue", true);
3131
+ return res;
2972
3132
  });
2973
- await (0, error_js_1.raiseForStatus)(response, "update annotation queue");
2974
3133
  }
2975
3134
  /**
2976
3135
  * Delete an annotation queue with the specified queue ID.
2977
3136
  * @param queueId - The ID of the annotation queue to delete
2978
3137
  */
2979
3138
  async deleteAnnotationQueue(queueId) {
2980
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}`, {
2981
- method: "DELETE",
2982
- headers: { ...this.headers, Accept: "application/json" },
2983
- signal: AbortSignal.timeout(this.timeout_ms),
2984
- ...this.fetchOptions,
3139
+ await this.caller.call(async () => {
3140
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}`, {
3141
+ method: "DELETE",
3142
+ headers: { ...this.headers, Accept: "application/json" },
3143
+ signal: AbortSignal.timeout(this.timeout_ms),
3144
+ ...this.fetchOptions,
3145
+ });
3146
+ await (0, error_js_1.raiseForStatus)(res, "delete annotation queue", true);
3147
+ return res;
2985
3148
  });
2986
- await (0, error_js_1.raiseForStatus)(response, "delete annotation queue");
2987
3149
  }
2988
3150
  /**
2989
3151
  * Add runs to an annotation queue with the specified queue ID.
@@ -2991,14 +3153,18 @@ class Client {
2991
3153
  * @param runIds - The IDs of the runs to be added to the annotation queue
2992
3154
  */
2993
3155
  async addRunsToAnnotationQueue(queueId, runIds) {
2994
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/runs`, {
2995
- method: "POST",
2996
- headers: { ...this.headers, "Content-Type": "application/json" },
2997
- body: JSON.stringify(runIds.map((id, i) => (0, _uuid_js_1.assertUuid)(id, `runIds[${i}]`).toString())),
2998
- signal: AbortSignal.timeout(this.timeout_ms),
2999
- ...this.fetchOptions,
3156
+ const body = JSON.stringify(runIds.map((id, i) => (0, _uuid_js_1.assertUuid)(id, `runIds[${i}]`).toString()));
3157
+ await this.caller.call(async () => {
3158
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/runs`, {
3159
+ method: "POST",
3160
+ headers: { ...this.headers, "Content-Type": "application/json" },
3161
+ signal: AbortSignal.timeout(this.timeout_ms),
3162
+ ...this.fetchOptions,
3163
+ body,
3164
+ });
3165
+ await (0, error_js_1.raiseForStatus)(res, "add runs to annotation queue", true);
3166
+ return res;
3000
3167
  });
3001
- await (0, error_js_1.raiseForStatus)(response, "add runs to annotation queue");
3002
3168
  }
3003
3169
  /**
3004
3170
  * Get a run from an annotation queue at the specified index.
@@ -3009,14 +3175,17 @@ class Client {
3009
3175
  */
3010
3176
  async getRunFromAnnotationQueue(queueId, index) {
3011
3177
  const baseUrl = `/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/run`;
3012
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}${baseUrl}/${index}`, {
3013
- method: "GET",
3014
- headers: this.headers,
3015
- signal: AbortSignal.timeout(this.timeout_ms),
3016
- ...this.fetchOptions,
3178
+ const response = await this.caller.call(async () => {
3179
+ const res = await this._fetch(`${this.apiUrl}${baseUrl}/${index}`, {
3180
+ method: "GET",
3181
+ headers: this.headers,
3182
+ signal: AbortSignal.timeout(this.timeout_ms),
3183
+ ...this.fetchOptions,
3184
+ });
3185
+ await (0, error_js_1.raiseForStatus)(res, "get run from annotation queue");
3186
+ return res;
3017
3187
  });
3018
- await (0, error_js_1.raiseForStatus)(response, "get run from annotation queue");
3019
- return await response.json();
3188
+ return response.json();
3020
3189
  }
3021
3190
  /**
3022
3191
  * Delete a run from an an annotation queue.
@@ -3024,27 +3193,33 @@ class Client {
3024
3193
  * @param queueRunId - The ID of the run to delete from the annotation queue
3025
3194
  */
3026
3195
  async deleteRunFromAnnotationQueue(queueId, queueRunId) {
3027
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/runs/${(0, _uuid_js_1.assertUuid)(queueRunId, "queueRunId")}`, {
3028
- method: "DELETE",
3029
- headers: { ...this.headers, Accept: "application/json" },
3030
- signal: AbortSignal.timeout(this.timeout_ms),
3031
- ...this.fetchOptions,
3196
+ await this.caller.call(async () => {
3197
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/runs/${(0, _uuid_js_1.assertUuid)(queueRunId, "queueRunId")}`, {
3198
+ method: "DELETE",
3199
+ headers: { ...this.headers, Accept: "application/json" },
3200
+ signal: AbortSignal.timeout(this.timeout_ms),
3201
+ ...this.fetchOptions,
3202
+ });
3203
+ await (0, error_js_1.raiseForStatus)(res, "delete run from annotation queue", true);
3204
+ return res;
3032
3205
  });
3033
- await (0, error_js_1.raiseForStatus)(response, "delete run from annotation queue");
3034
3206
  }
3035
3207
  /**
3036
3208
  * Get the size of an annotation queue.
3037
3209
  * @param queueId - The ID of the annotation queue
3038
3210
  */
3039
3211
  async getSizeFromAnnotationQueue(queueId) {
3040
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/size`, {
3041
- method: "GET",
3042
- headers: this.headers,
3043
- signal: AbortSignal.timeout(this.timeout_ms),
3044
- ...this.fetchOptions,
3212
+ const response = await this.caller.call(async () => {
3213
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/size`, {
3214
+ method: "GET",
3215
+ headers: this.headers,
3216
+ signal: AbortSignal.timeout(this.timeout_ms),
3217
+ ...this.fetchOptions,
3218
+ });
3219
+ await (0, error_js_1.raiseForStatus)(res, "get size from annotation queue");
3220
+ return res;
3045
3221
  });
3046
- await (0, error_js_1.raiseForStatus)(response, "get size from annotation queue");
3047
- return await response.json();
3222
+ return response.json();
3048
3223
  }
3049
3224
  async _currentTenantIsOwner(owner) {
3050
3225
  const settings = await this._getSettings();
@@ -3057,22 +3232,17 @@ class Client {
3057
3232
  Requested tenant: ${owner}`);
3058
3233
  }
3059
3234
  async _getLatestCommitHash(promptOwnerAndName) {
3060
- const res = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/commits/${promptOwnerAndName}/?limit=${1}&offset=${0}`, {
3061
- method: "GET",
3062
- headers: this.headers,
3063
- signal: AbortSignal.timeout(this.timeout_ms),
3064
- ...this.fetchOptions,
3065
- });
3066
- const json = await res.json();
3067
- if (!res.ok) {
3068
- const detail = typeof json.detail === "string"
3069
- ? json.detail
3070
- : JSON.stringify(json.detail);
3071
- const error = new Error(`Error ${res.status}: ${res.statusText}\n${detail}`);
3072
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3073
- error.statusCode = res.status;
3074
- throw error;
3075
- }
3235
+ const response = await this.caller.call(async () => {
3236
+ const res = await this._fetch(`${this.apiUrl}/commits/${promptOwnerAndName}/?limit=${1}&offset=${0}`, {
3237
+ method: "GET",
3238
+ headers: this.headers,
3239
+ signal: AbortSignal.timeout(this.timeout_ms),
3240
+ ...this.fetchOptions,
3241
+ });
3242
+ await (0, error_js_1.raiseForStatus)(res, "get latest commit hash");
3243
+ return res;
3244
+ });
3245
+ const json = await response.json();
3076
3246
  if (json.commits.length === 0) {
3077
3247
  return undefined;
3078
3248
  }
@@ -3080,15 +3250,19 @@ class Client {
3080
3250
  }
3081
3251
  async _likeOrUnlikePrompt(promptIdentifier, like) {
3082
3252
  const [owner, promptName, _] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
3083
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/likes/${owner}/${promptName}`, {
3084
- method: "POST",
3085
- body: JSON.stringify({ like: like }),
3086
- headers: { ...this.headers, "Content-Type": "application/json" },
3087
- signal: AbortSignal.timeout(this.timeout_ms),
3088
- ...this.fetchOptions,
3089
- });
3090
- await (0, error_js_1.raiseForStatus)(response, `${like ? "like" : "unlike"} prompt`);
3091
- return await response.json();
3253
+ const body = JSON.stringify({ like: like });
3254
+ const response = await this.caller.call(async () => {
3255
+ const res = await this._fetch(`${this.apiUrl}/likes/${owner}/${promptName}`, {
3256
+ method: "POST",
3257
+ headers: { ...this.headers, "Content-Type": "application/json" },
3258
+ signal: AbortSignal.timeout(this.timeout_ms),
3259
+ ...this.fetchOptions,
3260
+ body,
3261
+ });
3262
+ await (0, error_js_1.raiseForStatus)(res, `${like ? "like" : "unlike"} prompt`);
3263
+ return res;
3264
+ });
3265
+ return response.json();
3092
3266
  }
3093
3267
  async _getPromptUrl(promptIdentifier) {
3094
3268
  const [owner, promptName, commitHash] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
@@ -3142,18 +3316,21 @@ class Client {
3142
3316
  }
3143
3317
  async getPrompt(promptIdentifier) {
3144
3318
  const [owner, promptName, _] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
3145
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/repos/${owner}/${promptName}`, {
3146
- method: "GET",
3147
- headers: this.headers,
3148
- signal: AbortSignal.timeout(this.timeout_ms),
3149
- ...this.fetchOptions,
3319
+ const response = await this.caller.call(async () => {
3320
+ const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
3321
+ method: "GET",
3322
+ headers: this.headers,
3323
+ signal: AbortSignal.timeout(this.timeout_ms),
3324
+ ...this.fetchOptions,
3325
+ });
3326
+ if (res?.status === 404) {
3327
+ return null;
3328
+ }
3329
+ await (0, error_js_1.raiseForStatus)(res, "get prompt");
3330
+ return res;
3150
3331
  });
3151
- if (response.status === 404) {
3152
- return null;
3153
- }
3154
- await (0, error_js_1.raiseForStatus)(response, "get prompt");
3155
- const result = await response.json();
3156
- if (result.repo) {
3332
+ const result = await response?.json();
3333
+ if (result?.repo) {
3157
3334
  return result.repo;
3158
3335
  }
3159
3336
  else {
@@ -3179,14 +3356,18 @@ class Client {
3179
3356
  ...(options?.tags && { tags: options.tags }),
3180
3357
  is_public: !!options?.isPublic,
3181
3358
  };
3182
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/repos/`, {
3183
- method: "POST",
3184
- headers: { ...this.headers, "Content-Type": "application/json" },
3185
- body: JSON.stringify(data),
3186
- signal: AbortSignal.timeout(this.timeout_ms),
3187
- ...this.fetchOptions,
3188
- });
3189
- await (0, error_js_1.raiseForStatus)(response, "create prompt");
3359
+ const body = JSON.stringify(data);
3360
+ const response = await this.caller.call(async () => {
3361
+ const res = await this._fetch(`${this.apiUrl}/repos/`, {
3362
+ method: "POST",
3363
+ headers: { ...this.headers, "Content-Type": "application/json" },
3364
+ signal: AbortSignal.timeout(this.timeout_ms),
3365
+ ...this.fetchOptions,
3366
+ body,
3367
+ });
3368
+ await (0, error_js_1.raiseForStatus)(res, "create prompt");
3369
+ return res;
3370
+ });
3190
3371
  const { repo } = await response.json();
3191
3372
  return repo;
3192
3373
  }
@@ -3202,14 +3383,18 @@ class Client {
3202
3383
  manifest: JSON.parse(JSON.stringify(object)),
3203
3384
  parent_commit: resolvedParentCommitHash,
3204
3385
  };
3205
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/commits/${owner}/${promptName}`, {
3206
- method: "POST",
3207
- headers: { ...this.headers, "Content-Type": "application/json" },
3208
- body: JSON.stringify(payload),
3209
- signal: AbortSignal.timeout(this.timeout_ms),
3210
- ...this.fetchOptions,
3211
- });
3212
- await (0, error_js_1.raiseForStatus)(response, "create commit");
3386
+ const body = JSON.stringify(payload);
3387
+ const response = await this.caller.call(async () => {
3388
+ const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}`, {
3389
+ method: "POST",
3390
+ headers: { ...this.headers, "Content-Type": "application/json" },
3391
+ signal: AbortSignal.timeout(this.timeout_ms),
3392
+ ...this.fetchOptions,
3393
+ body,
3394
+ });
3395
+ await (0, error_js_1.raiseForStatus)(res, "create commit");
3396
+ return res;
3397
+ });
3213
3398
  const result = await response.json();
3214
3399
  return this._getPromptUrl(`${owner}/${promptName}${result.commit_hash ? `:${result.commit_hash}` : ""}`);
3215
3400
  }
@@ -3282,13 +3467,18 @@ class Client {
3282
3467
  }
3283
3468
  }
3284
3469
  const datasetIdToUse = datasetId ?? updates[0]?.dataset_id;
3285
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetIdToUse}/examples`)}`, {
3286
- method: "PATCH",
3287
- headers: this.headers,
3288
- body: formData,
3470
+ const response = await this.caller.call(async () => {
3471
+ const res = await this._fetch(`${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetIdToUse}/examples`)}`, {
3472
+ method: "PATCH",
3473
+ headers: this.headers,
3474
+ signal: AbortSignal.timeout(this.timeout_ms),
3475
+ ...this.fetchOptions,
3476
+ body: formData,
3477
+ });
3478
+ await (0, error_js_1.raiseForStatus)(res, "update examples");
3479
+ return res;
3289
3480
  });
3290
- const result = await response.json();
3291
- return result;
3481
+ return response.json();
3292
3482
  }
3293
3483
  /**
3294
3484
  * Upload examples with attachments using multipart form data.
@@ -3360,14 +3550,18 @@ class Client {
3360
3550
  }
3361
3551
  }
3362
3552
  }
3363
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetId}/examples`)}`, {
3364
- method: "POST",
3365
- headers: this.headers,
3366
- body: formData,
3553
+ const response = await this.caller.call(async () => {
3554
+ const res = await this._fetch(`${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetId}/examples`)}`, {
3555
+ method: "POST",
3556
+ headers: this.headers,
3557
+ signal: AbortSignal.timeout(this.timeout_ms),
3558
+ ...this.fetchOptions,
3559
+ body: formData,
3560
+ });
3561
+ await (0, error_js_1.raiseForStatus)(res, "upload examples");
3562
+ return res;
3367
3563
  });
3368
- await (0, error_js_1.raiseForStatus)(response, "upload examples");
3369
- const result = await response.json();
3370
- return result;
3564
+ return response.json();
3371
3565
  }
3372
3566
  async updatePrompt(promptIdentifier, options) {
3373
3567
  if (!(await this.promptExists(promptIdentifier))) {
@@ -3392,17 +3586,21 @@ class Client {
3392
3586
  if (Object.keys(payload).length === 0) {
3393
3587
  throw new Error("No valid update options provided");
3394
3588
  }
3395
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/repos/${owner}/${promptName}`, {
3396
- method: "PATCH",
3397
- body: JSON.stringify(payload),
3398
- headers: {
3399
- ...this.headers,
3400
- "Content-Type": "application/json",
3401
- },
3402
- signal: AbortSignal.timeout(this.timeout_ms),
3403
- ...this.fetchOptions,
3589
+ const body = JSON.stringify(payload);
3590
+ const response = await this.caller.call(async () => {
3591
+ const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
3592
+ method: "PATCH",
3593
+ headers: {
3594
+ ...this.headers,
3595
+ "Content-Type": "application/json",
3596
+ },
3597
+ signal: AbortSignal.timeout(this.timeout_ms),
3598
+ ...this.fetchOptions,
3599
+ body,
3600
+ });
3601
+ await (0, error_js_1.raiseForStatus)(res, "update prompt");
3602
+ return res;
3404
3603
  });
3405
- await (0, error_js_1.raiseForStatus)(response, "update prompt");
3406
3604
  return response.json();
3407
3605
  }
3408
3606
  async deletePrompt(promptIdentifier) {
@@ -3413,23 +3611,30 @@ class Client {
3413
3611
  if (!(await this._currentTenantIsOwner(owner))) {
3414
3612
  throw await this._ownerConflictError("delete a prompt", owner);
3415
3613
  }
3416
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/repos/${owner}/${promptName}`, {
3417
- method: "DELETE",
3418
- headers: this.headers,
3419
- signal: AbortSignal.timeout(this.timeout_ms),
3420
- ...this.fetchOptions,
3614
+ const response = await this.caller.call(async () => {
3615
+ const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
3616
+ method: "DELETE",
3617
+ headers: this.headers,
3618
+ signal: AbortSignal.timeout(this.timeout_ms),
3619
+ ...this.fetchOptions,
3620
+ });
3621
+ await (0, error_js_1.raiseForStatus)(res, "delete prompt");
3622
+ return res;
3421
3623
  });
3422
- return await response.json();
3624
+ return response.json();
3423
3625
  }
3424
3626
  async pullPromptCommit(promptIdentifier, options) {
3425
3627
  const [owner, promptName, commitHash] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
3426
- const response = await this.caller.call((0, fetch_js_1._getFetchImplementation)(this.debug), `${this.apiUrl}/commits/${owner}/${promptName}/${commitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
3427
- method: "GET",
3428
- headers: this.headers,
3429
- signal: AbortSignal.timeout(this.timeout_ms),
3430
- ...this.fetchOptions,
3628
+ const response = await this.caller.call(async () => {
3629
+ const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}/${commitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
3630
+ method: "GET",
3631
+ headers: this.headers,
3632
+ signal: AbortSignal.timeout(this.timeout_ms),
3633
+ ...this.fetchOptions,
3634
+ });
3635
+ await (0, error_js_1.raiseForStatus)(res, "pull prompt commit");
3636
+ return res;
3431
3637
  });
3432
- await (0, error_js_1.raiseForStatus)(response, "pull prompt commit");
3433
3638
  const result = await response.json();
3434
3639
  return {
3435
3640
  owner,