langsmith 0.3.62 → 0.3.63

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,28 +1161,33 @@ 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 {
@@ -1162,10 +1196,10 @@ class Client {
1162
1196
  // attempt stream only if not disabled and not using node-fetch
1163
1197
  if (!isNodeFetch && !this.multipartStreamingDisabled) {
1164
1198
  streamedAttempt = true;
1165
- res = await send(await buildStream());
1199
+ res = await sendWithRetry(buildStream);
1166
1200
  }
1167
1201
  else {
1168
- res = await send(await buildBuffered());
1202
+ res = await sendWithRetry(buildBuffered);
1169
1203
  }
1170
1204
  // if stream fails, fallback to buffered body
1171
1205
  if ((!this.multipartStreamingDisabled || streamedAttempt) &&
@@ -1177,10 +1211,8 @@ class Client {
1177
1211
  // Disable streaming for future requests
1178
1212
  this.multipartStreamingDisabled = true;
1179
1213
  // retry with fully-buffered body
1180
- res = await send(await buildBuffered());
1214
+ res = await sendWithRetry(buildBuffered);
1181
1215
  }
1182
- // raise if still failing
1183
- await (0, error_js_1.raiseForStatus)(res, "ingest multipart runs", true);
1184
1216
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1185
1217
  }
1186
1218
  catch (e) {
@@ -1237,14 +1269,18 @@ class Client {
1237
1269
  if (options?.apiKey !== undefined) {
1238
1270
  headers["x-api-key"] = options.apiKey;
1239
1271
  }
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,
1272
+ const body = (0, index_js_2.serialize)(run, `Serializing payload to update run with id: ${runId}`);
1273
+ await this.caller.call(async () => {
1274
+ const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/${runId}`, {
1275
+ method: "PATCH",
1276
+ headers,
1277
+ signal: AbortSignal.timeout(this.timeout_ms),
1278
+ ...this.fetchOptions,
1279
+ body,
1280
+ });
1281
+ await (0, error_js_1.raiseForStatus)(res, "update run", true);
1282
+ return res;
1246
1283
  });
1247
- await (0, error_js_1.raiseForStatus)(response, "update run", true);
1248
1284
  }
1249
1285
  async readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
1250
1286
  (0, _uuid_js_1.assertUuid)(runId);
@@ -1502,14 +1538,18 @@ class Client {
1502
1538
  };
1503
1539
  // Remove undefined values from the payload
1504
1540
  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,
1541
+ const body = JSON.stringify(filteredPayload);
1542
+ const response = await this.caller.call(async () => {
1543
+ const res = await this._fetch(url, {
1544
+ method: "POST",
1545
+ headers: { ...this.headers, "Content-Type": "application/json" },
1546
+ signal: AbortSignal.timeout(this.timeout_ms),
1547
+ ...this.fetchOptions,
1548
+ body,
1549
+ });
1550
+ await (0, error_js_1.raiseForStatus)(res, `Failed to fetch ${path}`);
1551
+ return res;
1511
1552
  });
1512
- await (0, error_js_1.raiseForStatus)(response, `Failed to fetch ${path}`);
1513
1553
  const items = await response.json();
1514
1554
  const { groups, total } = items;
1515
1555
  if (groups.length === 0) {
@@ -1551,12 +1591,17 @@ class Client {
1551
1591
  };
1552
1592
  // Remove undefined values from the payload
1553
1593
  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,
1594
+ const body = JSON.stringify(filteredPayload);
1595
+ const response = await this.caller.call(async () => {
1596
+ const res = await this._fetch(`${this.apiUrl}/runs/stats`, {
1597
+ method: "POST",
1598
+ headers: this.headers,
1599
+ signal: AbortSignal.timeout(this.timeout_ms),
1600
+ ...this.fetchOptions,
1601
+ body,
1602
+ });
1603
+ await (0, error_js_1.raiseForStatus)(res, "get run stats");
1604
+ return res;
1560
1605
  });
1561
1606
  const result = await response.json();
1562
1607
  return result;
@@ -1567,12 +1612,17 @@ class Client {
1567
1612
  share_token: shareId || uuid.v4(),
1568
1613
  };
1569
1614
  (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,
1615
+ const body = JSON.stringify(data);
1616
+ const response = await this.caller.call(async () => {
1617
+ const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
1618
+ method: "PUT",
1619
+ headers: this.headers,
1620
+ signal: AbortSignal.timeout(this.timeout_ms),
1621
+ ...this.fetchOptions,
1622
+ body,
1623
+ });
1624
+ await (0, error_js_1.raiseForStatus)(res, "share run");
1625
+ return res;
1576
1626
  });
1577
1627
  const result = await response.json();
1578
1628
  if (result === null || !("share_token" in result)) {
@@ -1582,21 +1632,28 @@ class Client {
1582
1632
  }
1583
1633
  async unshareRun(runId) {
1584
1634
  (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,
1635
+ await this.caller.call(async () => {
1636
+ const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
1637
+ method: "DELETE",
1638
+ headers: this.headers,
1639
+ signal: AbortSignal.timeout(this.timeout_ms),
1640
+ ...this.fetchOptions,
1641
+ });
1642
+ await (0, error_js_1.raiseForStatus)(res, "unshare run", true);
1643
+ return res;
1590
1644
  });
1591
- await (0, error_js_1.raiseForStatus)(response, "unshare run", true);
1592
1645
  }
1593
1646
  async readRunSharedLink(runId) {
1594
1647
  (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,
1648
+ const response = await this.caller.call(async () => {
1649
+ const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
1650
+ method: "GET",
1651
+ headers: this.headers,
1652
+ signal: AbortSignal.timeout(this.timeout_ms),
1653
+ ...this.fetchOptions,
1654
+ });
1655
+ await (0, error_js_1.raiseForStatus)(res, "read run shared link");
1656
+ return res;
1600
1657
  });
1601
1658
  const result = await response.json();
1602
1659
  if (result === null || !("share_token" in result)) {
@@ -1614,11 +1671,15 @@ class Client {
1614
1671
  }
1615
1672
  }
1616
1673
  (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,
1674
+ const response = await this.caller.call(async () => {
1675
+ const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/runs${queryParams}`, {
1676
+ method: "GET",
1677
+ headers: this.headers,
1678
+ signal: AbortSignal.timeout(this.timeout_ms),
1679
+ ...this.fetchOptions,
1680
+ });
1681
+ await (0, error_js_1.raiseForStatus)(res, "list shared runs");
1682
+ return res;
1622
1683
  });
1623
1684
  const runs = await response.json();
1624
1685
  return runs;
@@ -1632,11 +1693,15 @@ class Client {
1632
1693
  datasetId = dataset.id;
1633
1694
  }
1634
1695
  (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,
1696
+ const response = await this.caller.call(async () => {
1697
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
1698
+ method: "GET",
1699
+ headers: this.headers,
1700
+ signal: AbortSignal.timeout(this.timeout_ms),
1701
+ ...this.fetchOptions,
1702
+ });
1703
+ await (0, error_js_1.raiseForStatus)(res, "read dataset shared schema");
1704
+ return res;
1640
1705
  });
1641
1706
  const shareSchema = await response.json();
1642
1707
  shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
@@ -1654,12 +1719,17 @@ class Client {
1654
1719
  dataset_id: datasetId,
1655
1720
  };
1656
1721
  (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,
1722
+ const body = JSON.stringify(data);
1723
+ const response = await this.caller.call(async () => {
1724
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
1725
+ method: "PUT",
1726
+ headers: this.headers,
1727
+ signal: AbortSignal.timeout(this.timeout_ms),
1728
+ ...this.fetchOptions,
1729
+ body,
1730
+ });
1731
+ await (0, error_js_1.raiseForStatus)(res, "share dataset");
1732
+ return res;
1663
1733
  });
1664
1734
  const shareSchema = await response.json();
1665
1735
  shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
@@ -1667,21 +1737,28 @@ class Client {
1667
1737
  }
1668
1738
  async unshareDataset(datasetId) {
1669
1739
  (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,
1740
+ await this.caller.call(async () => {
1741
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
1742
+ method: "DELETE",
1743
+ headers: this.headers,
1744
+ signal: AbortSignal.timeout(this.timeout_ms),
1745
+ ...this.fetchOptions,
1746
+ });
1747
+ await (0, error_js_1.raiseForStatus)(res, "unshare dataset", true);
1748
+ return res;
1675
1749
  });
1676
- await (0, error_js_1.raiseForStatus)(response, "unshare dataset", true);
1677
1750
  }
1678
1751
  async readSharedDataset(shareToken) {
1679
1752
  (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,
1753
+ const response = await this.caller.call(async () => {
1754
+ const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/datasets`, {
1755
+ method: "GET",
1756
+ headers: this.headers,
1757
+ signal: AbortSignal.timeout(this.timeout_ms),
1758
+ ...this.fetchOptions,
1759
+ });
1760
+ await (0, error_js_1.raiseForStatus)(res, "read shared dataset");
1761
+ return res;
1685
1762
  });
1686
1763
  const dataset = await response.json();
1687
1764
  return dataset;
@@ -1708,11 +1785,15 @@ class Client {
1708
1785
  urlParams.append(key, value);
1709
1786
  }
1710
1787
  });
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,
1788
+ const response = await this.caller.call(async () => {
1789
+ const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
1790
+ method: "GET",
1791
+ headers: this.headers,
1792
+ signal: AbortSignal.timeout(this.timeout_ms),
1793
+ ...this.fetchOptions,
1794
+ });
1795
+ await (0, error_js_1.raiseForStatus)(res, "list shared examples");
1796
+ return res;
1716
1797
  });
1717
1798
  const result = await response.json();
1718
1799
  if (!response.ok) {
@@ -1743,14 +1824,18 @@ class Client {
1743
1824
  if (referenceDatasetId !== null) {
1744
1825
  body["reference_dataset_id"] = referenceDatasetId;
1745
1826
  }
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,
1827
+ const serializedBody = JSON.stringify(body);
1828
+ const response = await this.caller.call(async () => {
1829
+ const res = await this._fetch(endpoint, {
1830
+ method: "POST",
1831
+ headers: { ...this.headers, "Content-Type": "application/json" },
1832
+ signal: AbortSignal.timeout(this.timeout_ms),
1833
+ ...this.fetchOptions,
1834
+ body: serializedBody,
1835
+ });
1836
+ await (0, error_js_1.raiseForStatus)(res, "create project");
1837
+ return res;
1752
1838
  });
1753
- await (0, error_js_1.raiseForStatus)(response, "create project");
1754
1839
  const result = await response.json();
1755
1840
  return result;
1756
1841
  }
@@ -1760,20 +1845,23 @@ class Client {
1760
1845
  if (metadata) {
1761
1846
  extra = { ...(extra || {}), metadata };
1762
1847
  }
1763
- const body = {
1848
+ const body = JSON.stringify({
1764
1849
  name,
1765
1850
  extra,
1766
1851
  description,
1767
1852
  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");
1853
+ });
1854
+ const response = await this.caller.call(async () => {
1855
+ const res = await this._fetch(endpoint, {
1856
+ method: "PATCH",
1857
+ headers: { ...this.headers, "Content-Type": "application/json" },
1858
+ signal: AbortSignal.timeout(this.timeout_ms),
1859
+ ...this.fetchOptions,
1860
+ body,
1861
+ });
1862
+ await (0, error_js_1.raiseForStatus)(res, "update project");
1863
+ return res;
1864
+ });
1777
1865
  const result = await response.json();
1778
1866
  return result;
1779
1867
  }
@@ -1794,11 +1882,15 @@ class Client {
1794
1882
  else {
1795
1883
  throw new Error("Must provide projectName or projectId");
1796
1884
  }
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,
1885
+ const response = await this.caller.call(async () => {
1886
+ const res = await this._fetch(`${this.apiUrl}${path}?${params}`, {
1887
+ method: "GET",
1888
+ headers: this.headers,
1889
+ signal: AbortSignal.timeout(this.timeout_ms),
1890
+ ...this.fetchOptions,
1891
+ });
1892
+ await (0, error_js_1.raiseForStatus)(res, "has project");
1893
+ return res;
1802
1894
  });
1803
1895
  // consume the response body to release the connection
1804
1896
  // https://undici.nodejs.org/#/?id=garbage-collection
@@ -1924,13 +2016,16 @@ class Client {
1924
2016
  projectId_ = projectId;
1925
2017
  }
1926
2018
  (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,
2019
+ await this.caller.call(async () => {
2020
+ const res = await this._fetch(`${this.apiUrl}/sessions/${projectId_}`, {
2021
+ method: "DELETE",
2022
+ headers: this.headers,
2023
+ signal: AbortSignal.timeout(this.timeout_ms),
2024
+ ...this.fetchOptions,
2025
+ });
2026
+ await (0, error_js_1.raiseForStatus)(res, `delete session ${projectId_} (${projectName})`, true);
2027
+ return res;
1932
2028
  });
1933
- await (0, error_js_1.raiseForStatus)(response, `delete session ${projectId_} (${projectName})`, true);
1934
2029
  }
1935
2030
  async uploadCsv({ csvFile, fileName, inputKeys, outputKeys, description, dataType, name, }) {
1936
2031
  const url = `${this.apiUrl}/datasets/upload`;
@@ -1951,14 +2046,17 @@ class Client {
1951
2046
  if (name) {
1952
2047
  formData.append("name", name);
1953
2048
  }
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,
2049
+ const response = await this.caller.call(async () => {
2050
+ const res = await this._fetch(url, {
2051
+ method: "POST",
2052
+ headers: this.headers,
2053
+ signal: AbortSignal.timeout(this.timeout_ms),
2054
+ ...this.fetchOptions,
2055
+ body: formData,
2056
+ });
2057
+ await (0, error_js_1.raiseForStatus)(res, "upload CSV");
2058
+ return res;
1960
2059
  });
1961
- await (0, error_js_1.raiseForStatus)(response, "upload CSV");
1962
2060
  const result = await response.json();
1963
2061
  return result;
1964
2062
  }
@@ -1977,14 +2075,18 @@ class Client {
1977
2075
  if (outputsSchema) {
1978
2076
  body.outputs_schema_definition = outputsSchema;
1979
2077
  }
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,
2078
+ const serializedBody = JSON.stringify(body);
2079
+ const response = await this.caller.call(async () => {
2080
+ const res = await this._fetch(`${this.apiUrl}/datasets`, {
2081
+ method: "POST",
2082
+ headers: { ...this.headers, "Content-Type": "application/json" },
2083
+ signal: AbortSignal.timeout(this.timeout_ms),
2084
+ ...this.fetchOptions,
2085
+ body: serializedBody,
2086
+ });
2087
+ await (0, error_js_1.raiseForStatus)(res, "create dataset");
2088
+ return res;
1986
2089
  });
1987
- await (0, error_js_1.raiseForStatus)(response, "create dataset");
1988
2090
  const result = await response.json();
1989
2091
  return result;
1990
2092
  }
@@ -2109,14 +2211,18 @@ class Client {
2109
2211
  }
2110
2212
  const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
2111
2213
  (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");
2214
+ const body = JSON.stringify(update);
2215
+ const response = await this.caller.call(async () => {
2216
+ const res = await this._fetch(`${this.apiUrl}/datasets/${_datasetId}`, {
2217
+ method: "PATCH",
2218
+ headers: { ...this.headers, "Content-Type": "application/json" },
2219
+ signal: AbortSignal.timeout(this.timeout_ms),
2220
+ ...this.fetchOptions,
2221
+ body,
2222
+ });
2223
+ await (0, error_js_1.raiseForStatus)(res, "update dataset");
2224
+ return res;
2225
+ });
2120
2226
  return (await response.json());
2121
2227
  }
2122
2228
  /**
@@ -2141,17 +2247,21 @@ class Client {
2141
2247
  }
2142
2248
  const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
2143
2249
  (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,
2250
+ const body = JSON.stringify({
2251
+ as_of: typeof asOf === "string" ? asOf : asOf.toISOString(),
2252
+ tag,
2253
+ });
2254
+ await this.caller.call(async () => {
2255
+ const res = await this._fetch(`${this.apiUrl}/datasets/${_datasetId}/tags`, {
2256
+ method: "PUT",
2257
+ headers: { ...this.headers, "Content-Type": "application/json" },
2258
+ signal: AbortSignal.timeout(this.timeout_ms),
2259
+ ...this.fetchOptions,
2260
+ body,
2261
+ });
2262
+ await (0, error_js_1.raiseForStatus)(res, "update dataset tags", true);
2263
+ return res;
2153
2264
  });
2154
- await (0, error_js_1.raiseForStatus)(response, "update dataset tags");
2155
2265
  }
2156
2266
  async deleteDataset({ datasetId, datasetName, }) {
2157
2267
  let path = "/datasets";
@@ -2170,14 +2280,16 @@ class Client {
2170
2280
  else {
2171
2281
  throw new Error("Must provide datasetName or datasetId");
2172
2282
  }
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,
2283
+ await this.caller.call(async () => {
2284
+ const res = await this._fetch(this.apiUrl + path, {
2285
+ method: "DELETE",
2286
+ headers: this.headers,
2287
+ signal: AbortSignal.timeout(this.timeout_ms),
2288
+ ...this.fetchOptions,
2289
+ });
2290
+ await (0, error_js_1.raiseForStatus)(res, `delete ${path}`, true);
2291
+ return res;
2178
2292
  });
2179
- await (0, error_js_1.raiseForStatus)(response, `delete ${path}`);
2180
- await response.json();
2181
2293
  }
2182
2294
  async indexDataset({ datasetId, datasetName, tag, }) {
2183
2295
  let datasetId_ = datasetId;
@@ -2195,14 +2307,18 @@ class Client {
2195
2307
  const data = {
2196
2308
  tag: tag,
2197
2309
  };
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");
2310
+ const body = JSON.stringify(data);
2311
+ const response = await this.caller.call(async () => {
2312
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId_}/index`, {
2313
+ method: "POST",
2314
+ headers: { ...this.headers, "Content-Type": "application/json" },
2315
+ signal: AbortSignal.timeout(this.timeout_ms),
2316
+ ...this.fetchOptions,
2317
+ body,
2318
+ });
2319
+ await (0, error_js_1.raiseForStatus)(res, "index dataset");
2320
+ return res;
2321
+ });
2206
2322
  await response.json();
2207
2323
  }
2208
2324
  /**
@@ -2244,14 +2360,18 @@ class Client {
2244
2360
  data["filter"] = filter;
2245
2361
  }
2246
2362
  (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");
2363
+ const body = JSON.stringify(data);
2364
+ const response = await this.caller.call(async () => {
2365
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/search`, {
2366
+ headers: { ...this.headers, "Content-Type": "application/json" },
2367
+ signal: AbortSignal.timeout(this.timeout_ms),
2368
+ ...this.fetchOptions,
2369
+ method: "POST",
2370
+ body,
2371
+ });
2372
+ await (0, error_js_1.raiseForStatus)(res, "fetch similar examples");
2373
+ return res;
2374
+ });
2255
2375
  const result = await response.json();
2256
2376
  return result["examples"];
2257
2377
  }
@@ -2463,14 +2583,16 @@ class Client {
2463
2583
  async deleteExample(exampleId) {
2464
2584
  (0, _uuid_js_1.assertUuid)(exampleId);
2465
2585
  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,
2586
+ await this.caller.call(async () => {
2587
+ const res = await this._fetch(this.apiUrl + path, {
2588
+ method: "DELETE",
2589
+ headers: this.headers,
2590
+ signal: AbortSignal.timeout(this.timeout_ms),
2591
+ ...this.fetchOptions,
2592
+ });
2593
+ await (0, error_js_1.raiseForStatus)(res, `delete ${path}`, true);
2594
+ return res;
2471
2595
  });
2472
- await (0, error_js_1.raiseForStatus)(response, `delete ${path}`);
2473
- await response.json();
2474
2596
  }
2475
2597
  async updateExample(exampleIdOrUpdate, update) {
2476
2598
  let exampleId;
@@ -2542,13 +2664,16 @@ class Client {
2542
2664
  if (tag !== undefined) {
2543
2665
  params.append("tag", tag);
2544
2666
  }
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,
2667
+ const response = await this.caller.call(async () => {
2668
+ const res = await this._fetch(`${this.apiUrl}/datasets/${resolvedDatasetId}/version?${params.toString()}`, {
2669
+ method: "GET",
2670
+ headers: { ...this.headers },
2671
+ signal: AbortSignal.timeout(this.timeout_ms),
2672
+ ...this.fetchOptions,
2673
+ });
2674
+ await (0, error_js_1.raiseForStatus)(res, "read dataset version");
2675
+ return res;
2550
2676
  });
2551
- await (0, error_js_1.raiseForStatus)(response, "read dataset version");
2552
2677
  return await response.json();
2553
2678
  }
2554
2679
  async listDatasetSplits({ datasetId, datasetName, asOf, }) {
@@ -2603,14 +2728,18 @@ class Client {
2603
2728
  }),
2604
2729
  remove,
2605
2730
  };
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,
2731
+ const body = JSON.stringify(data);
2732
+ await this.caller.call(async () => {
2733
+ const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId_}/splits`, {
2734
+ method: "PUT",
2735
+ headers: { ...this.headers, "Content-Type": "application/json" },
2736
+ signal: AbortSignal.timeout(this.timeout_ms),
2737
+ ...this.fetchOptions,
2738
+ body,
2739
+ });
2740
+ await (0, error_js_1.raiseForStatus)(res, "update dataset splits", true);
2741
+ return res;
2612
2742
  });
2613
- await (0, error_js_1.raiseForStatus)(response, "update dataset splits", true);
2614
2743
  }
2615
2744
  /**
2616
2745
  * @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
@@ -2668,15 +2797,19 @@ class Client {
2668
2797
  feedbackConfig,
2669
2798
  session_id: projectId,
2670
2799
  };
2800
+ const body = JSON.stringify(feedback);
2671
2801
  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);
2802
+ await this.caller.call(async () => {
2803
+ const res = await this._fetch(url, {
2804
+ method: "POST",
2805
+ headers: { ...this.headers, "Content-Type": "application/json" },
2806
+ signal: AbortSignal.timeout(this.timeout_ms),
2807
+ ...this.fetchOptions,
2808
+ body,
2809
+ });
2810
+ await (0, error_js_1.raiseForStatus)(res, "create feedback", true);
2811
+ return res;
2812
+ });
2680
2813
  return feedback;
2681
2814
  }
2682
2815
  async updateFeedback(feedbackId, { score, value, correction, comment, }) {
@@ -2694,14 +2827,18 @@ class Client {
2694
2827
  feedbackUpdate["comment"] = comment;
2695
2828
  }
2696
2829
  (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,
2830
+ const body = JSON.stringify(feedbackUpdate);
2831
+ await this.caller.call(async () => {
2832
+ const res = await this._fetch(`${this.apiUrl}/feedback/${feedbackId}`, {
2833
+ method: "PATCH",
2834
+ headers: { ...this.headers, "Content-Type": "application/json" },
2835
+ signal: AbortSignal.timeout(this.timeout_ms),
2836
+ ...this.fetchOptions,
2837
+ body,
2838
+ });
2839
+ await (0, error_js_1.raiseForStatus)(res, "update feedback", true);
2840
+ return res;
2703
2841
  });
2704
- await (0, error_js_1.raiseForStatus)(response, "update feedback", true);
2705
2842
  }
2706
2843
  async readFeedback(feedbackId) {
2707
2844
  (0, _uuid_js_1.assertUuid)(feedbackId);
@@ -2712,14 +2849,16 @@ class Client {
2712
2849
  async deleteFeedback(feedbackId) {
2713
2850
  (0, _uuid_js_1.assertUuid)(feedbackId);
2714
2851
  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,
2852
+ await this.caller.call(async () => {
2853
+ const res = await this._fetch(this.apiUrl + path, {
2854
+ method: "DELETE",
2855
+ headers: this.headers,
2856
+ signal: AbortSignal.timeout(this.timeout_ms),
2857
+ ...this.fetchOptions,
2858
+ });
2859
+ await (0, error_js_1.raiseForStatus)(res, `delete ${path}`, true);
2860
+ return res;
2720
2861
  });
2721
- await (0, error_js_1.raiseForStatus)(response, `delete ${path}`);
2722
- await response.json();
2723
2862
  }
2724
2863
  async *listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, } = {}) {
2725
2864
  const queryParams = new URLSearchParams();
@@ -2774,15 +2913,19 @@ class Client {
2774
2913
  hours: 3,
2775
2914
  };
2776
2915
  }
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,
2916
+ const serializedBody = JSON.stringify(body);
2917
+ const response = await this.caller.call(async () => {
2918
+ const res = await this._fetch(`${this.apiUrl}/feedback/tokens`, {
2919
+ method: "POST",
2920
+ headers: { ...this.headers, "Content-Type": "application/json" },
2921
+ signal: AbortSignal.timeout(this.timeout_ms),
2922
+ ...this.fetchOptions,
2923
+ body: serializedBody,
2924
+ });
2925
+ await (0, error_js_1.raiseForStatus)(res, "create presigned feedback token");
2926
+ return res;
2783
2927
  });
2784
- const result = await response.json();
2785
- return result;
2928
+ return await response.json();
2786
2929
  }
2787
2930
  async createComparativeExperiment({ name, experimentIds, referenceDatasetId, createdAt, description, metadata, id, }) {
2788
2931
  if (experimentIds.length === 0) {
@@ -2807,14 +2950,19 @@ class Client {
2807
2950
  };
2808
2951
  if (metadata)
2809
2952
  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,
2953
+ const serializedBody = JSON.stringify(body);
2954
+ const response = await this.caller.call(async () => {
2955
+ const res = await this._fetch(`${this.apiUrl}/datasets/comparative`, {
2956
+ method: "POST",
2957
+ headers: { ...this.headers, "Content-Type": "application/json" },
2958
+ signal: AbortSignal.timeout(this.timeout_ms),
2959
+ ...this.fetchOptions,
2960
+ body: serializedBody,
2961
+ });
2962
+ await (0, error_js_1.raiseForStatus)(res, "create comparative experiment");
2963
+ return res;
2816
2964
  });
2817
- return await response.json();
2965
+ return response.json();
2818
2966
  }
2819
2967
  /**
2820
2968
  * Retrieves a list of presigned feedback tokens for a given run ID.
@@ -2923,16 +3071,19 @@ class Client {
2923
3071
  id: queueId || uuid.v4(),
2924
3072
  rubric_instructions: rubricInstructions,
2925
3073
  };
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,
3074
+ const serializedBody = JSON.stringify(Object.fromEntries(Object.entries(body).filter(([_, v]) => v !== undefined)));
3075
+ const response = await this.caller.call(async () => {
3076
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues`, {
3077
+ method: "POST",
3078
+ headers: { ...this.headers, "Content-Type": "application/json" },
3079
+ signal: AbortSignal.timeout(this.timeout_ms),
3080
+ ...this.fetchOptions,
3081
+ body: serializedBody,
3082
+ });
3083
+ await (0, error_js_1.raiseForStatus)(res, "create annotation queue");
3084
+ return res;
2932
3085
  });
2933
- await (0, error_js_1.raiseForStatus)(response, "create annotation queue");
2934
- const data = await response.json();
2935
- return data;
3086
+ return response.json();
2936
3087
  }
2937
3088
  /**
2938
3089
  * Read an annotation queue with the specified queue ID.
@@ -2940,15 +3091,17 @@ class Client {
2940
3091
  * @returns The AnnotationQueueWithDetails object
2941
3092
  */
2942
3093
  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,
3094
+ const response = await this.caller.call(async () => {
3095
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}`, {
3096
+ method: "GET",
3097
+ headers: this.headers,
3098
+ signal: AbortSignal.timeout(this.timeout_ms),
3099
+ ...this.fetchOptions,
3100
+ });
3101
+ await (0, error_js_1.raiseForStatus)(res, "read annotation queue");
3102
+ return res;
2948
3103
  });
2949
- await (0, error_js_1.raiseForStatus)(response, "read annotation queue");
2950
- const data = await response.json();
2951
- return data;
3104
+ return response.json();
2952
3105
  }
2953
3106
  /**
2954
3107
  * Update an annotation queue with the specified queue ID.
@@ -2959,31 +3112,38 @@ class Client {
2959
3112
  */
2960
3113
  async updateAnnotationQueue(queueId, options) {
2961
3114
  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,
3115
+ const body = JSON.stringify({
3116
+ name,
3117
+ description,
3118
+ rubric_instructions: rubricInstructions,
3119
+ });
3120
+ await this.caller.call(async () => {
3121
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}`, {
3122
+ method: "PATCH",
3123
+ headers: { ...this.headers, "Content-Type": "application/json" },
3124
+ signal: AbortSignal.timeout(this.timeout_ms),
3125
+ ...this.fetchOptions,
3126
+ body,
3127
+ });
3128
+ await (0, error_js_1.raiseForStatus)(res, "update annotation queue", true);
3129
+ return res;
2972
3130
  });
2973
- await (0, error_js_1.raiseForStatus)(response, "update annotation queue");
2974
3131
  }
2975
3132
  /**
2976
3133
  * Delete an annotation queue with the specified queue ID.
2977
3134
  * @param queueId - The ID of the annotation queue to delete
2978
3135
  */
2979
3136
  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,
3137
+ await this.caller.call(async () => {
3138
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}`, {
3139
+ method: "DELETE",
3140
+ headers: { ...this.headers, Accept: "application/json" },
3141
+ signal: AbortSignal.timeout(this.timeout_ms),
3142
+ ...this.fetchOptions,
3143
+ });
3144
+ await (0, error_js_1.raiseForStatus)(res, "delete annotation queue", true);
3145
+ return res;
2985
3146
  });
2986
- await (0, error_js_1.raiseForStatus)(response, "delete annotation queue");
2987
3147
  }
2988
3148
  /**
2989
3149
  * Add runs to an annotation queue with the specified queue ID.
@@ -2991,14 +3151,18 @@ class Client {
2991
3151
  * @param runIds - The IDs of the runs to be added to the annotation queue
2992
3152
  */
2993
3153
  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,
3154
+ const body = JSON.stringify(runIds.map((id, i) => (0, _uuid_js_1.assertUuid)(id, `runIds[${i}]`).toString()));
3155
+ await this.caller.call(async () => {
3156
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/runs`, {
3157
+ method: "POST",
3158
+ headers: { ...this.headers, "Content-Type": "application/json" },
3159
+ signal: AbortSignal.timeout(this.timeout_ms),
3160
+ ...this.fetchOptions,
3161
+ body,
3162
+ });
3163
+ await (0, error_js_1.raiseForStatus)(res, "add runs to annotation queue", true);
3164
+ return res;
3000
3165
  });
3001
- await (0, error_js_1.raiseForStatus)(response, "add runs to annotation queue");
3002
3166
  }
3003
3167
  /**
3004
3168
  * Get a run from an annotation queue at the specified index.
@@ -3009,14 +3173,17 @@ class Client {
3009
3173
  */
3010
3174
  async getRunFromAnnotationQueue(queueId, index) {
3011
3175
  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,
3176
+ const response = await this.caller.call(async () => {
3177
+ const res = await this._fetch(`${this.apiUrl}${baseUrl}/${index}`, {
3178
+ method: "GET",
3179
+ headers: this.headers,
3180
+ signal: AbortSignal.timeout(this.timeout_ms),
3181
+ ...this.fetchOptions,
3182
+ });
3183
+ await (0, error_js_1.raiseForStatus)(res, "get run from annotation queue");
3184
+ return res;
3017
3185
  });
3018
- await (0, error_js_1.raiseForStatus)(response, "get run from annotation queue");
3019
- return await response.json();
3186
+ return response.json();
3020
3187
  }
3021
3188
  /**
3022
3189
  * Delete a run from an an annotation queue.
@@ -3024,27 +3191,33 @@ class Client {
3024
3191
  * @param queueRunId - The ID of the run to delete from the annotation queue
3025
3192
  */
3026
3193
  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,
3194
+ await this.caller.call(async () => {
3195
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/runs/${(0, _uuid_js_1.assertUuid)(queueRunId, "queueRunId")}`, {
3196
+ method: "DELETE",
3197
+ headers: { ...this.headers, Accept: "application/json" },
3198
+ signal: AbortSignal.timeout(this.timeout_ms),
3199
+ ...this.fetchOptions,
3200
+ });
3201
+ await (0, error_js_1.raiseForStatus)(res, "delete run from annotation queue", true);
3202
+ return res;
3032
3203
  });
3033
- await (0, error_js_1.raiseForStatus)(response, "delete run from annotation queue");
3034
3204
  }
3035
3205
  /**
3036
3206
  * Get the size of an annotation queue.
3037
3207
  * @param queueId - The ID of the annotation queue
3038
3208
  */
3039
3209
  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,
3210
+ const response = await this.caller.call(async () => {
3211
+ const res = await this._fetch(`${this.apiUrl}/annotation-queues/${(0, _uuid_js_1.assertUuid)(queueId, "queueId")}/size`, {
3212
+ method: "GET",
3213
+ headers: this.headers,
3214
+ signal: AbortSignal.timeout(this.timeout_ms),
3215
+ ...this.fetchOptions,
3216
+ });
3217
+ await (0, error_js_1.raiseForStatus)(res, "get size from annotation queue");
3218
+ return res;
3045
3219
  });
3046
- await (0, error_js_1.raiseForStatus)(response, "get size from annotation queue");
3047
- return await response.json();
3220
+ return response.json();
3048
3221
  }
3049
3222
  async _currentTenantIsOwner(owner) {
3050
3223
  const settings = await this._getSettings();
@@ -3057,22 +3230,17 @@ class Client {
3057
3230
  Requested tenant: ${owner}`);
3058
3231
  }
3059
3232
  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
- }
3233
+ const response = await this.caller.call(async () => {
3234
+ const res = await this._fetch(`${this.apiUrl}/commits/${promptOwnerAndName}/?limit=${1}&offset=${0}`, {
3235
+ method: "GET",
3236
+ headers: this.headers,
3237
+ signal: AbortSignal.timeout(this.timeout_ms),
3238
+ ...this.fetchOptions,
3239
+ });
3240
+ await (0, error_js_1.raiseForStatus)(res, "get latest commit hash");
3241
+ return res;
3242
+ });
3243
+ const json = await response.json();
3076
3244
  if (json.commits.length === 0) {
3077
3245
  return undefined;
3078
3246
  }
@@ -3080,15 +3248,19 @@ class Client {
3080
3248
  }
3081
3249
  async _likeOrUnlikePrompt(promptIdentifier, like) {
3082
3250
  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();
3251
+ const body = JSON.stringify({ like: like });
3252
+ const response = await this.caller.call(async () => {
3253
+ const res = await this._fetch(`${this.apiUrl}/likes/${owner}/${promptName}`, {
3254
+ method: "POST",
3255
+ headers: { ...this.headers, "Content-Type": "application/json" },
3256
+ signal: AbortSignal.timeout(this.timeout_ms),
3257
+ ...this.fetchOptions,
3258
+ body,
3259
+ });
3260
+ await (0, error_js_1.raiseForStatus)(res, `${like ? "like" : "unlike"} prompt`);
3261
+ return res;
3262
+ });
3263
+ return response.json();
3092
3264
  }
3093
3265
  async _getPromptUrl(promptIdentifier) {
3094
3266
  const [owner, promptName, commitHash] = (0, prompts_js_1.parsePromptIdentifier)(promptIdentifier);
@@ -3142,18 +3314,21 @@ class Client {
3142
3314
  }
3143
3315
  async getPrompt(promptIdentifier) {
3144
3316
  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,
3317
+ const response = await this.caller.call(async () => {
3318
+ const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
3319
+ method: "GET",
3320
+ headers: this.headers,
3321
+ signal: AbortSignal.timeout(this.timeout_ms),
3322
+ ...this.fetchOptions,
3323
+ });
3324
+ if (res?.status === 404) {
3325
+ return null;
3326
+ }
3327
+ await (0, error_js_1.raiseForStatus)(res, "get prompt");
3328
+ return res;
3150
3329
  });
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) {
3330
+ const result = await response?.json();
3331
+ if (result?.repo) {
3157
3332
  return result.repo;
3158
3333
  }
3159
3334
  else {
@@ -3179,14 +3354,18 @@ class Client {
3179
3354
  ...(options?.tags && { tags: options.tags }),
3180
3355
  is_public: !!options?.isPublic,
3181
3356
  };
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");
3357
+ const body = JSON.stringify(data);
3358
+ const response = await this.caller.call(async () => {
3359
+ const res = await this._fetch(`${this.apiUrl}/repos/`, {
3360
+ method: "POST",
3361
+ headers: { ...this.headers, "Content-Type": "application/json" },
3362
+ signal: AbortSignal.timeout(this.timeout_ms),
3363
+ ...this.fetchOptions,
3364
+ body,
3365
+ });
3366
+ await (0, error_js_1.raiseForStatus)(res, "create prompt");
3367
+ return res;
3368
+ });
3190
3369
  const { repo } = await response.json();
3191
3370
  return repo;
3192
3371
  }
@@ -3202,14 +3381,18 @@ class Client {
3202
3381
  manifest: JSON.parse(JSON.stringify(object)),
3203
3382
  parent_commit: resolvedParentCommitHash,
3204
3383
  };
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");
3384
+ const body = JSON.stringify(payload);
3385
+ const response = await this.caller.call(async () => {
3386
+ const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}`, {
3387
+ method: "POST",
3388
+ headers: { ...this.headers, "Content-Type": "application/json" },
3389
+ signal: AbortSignal.timeout(this.timeout_ms),
3390
+ ...this.fetchOptions,
3391
+ body,
3392
+ });
3393
+ await (0, error_js_1.raiseForStatus)(res, "create commit");
3394
+ return res;
3395
+ });
3213
3396
  const result = await response.json();
3214
3397
  return this._getPromptUrl(`${owner}/${promptName}${result.commit_hash ? `:${result.commit_hash}` : ""}`);
3215
3398
  }
@@ -3282,13 +3465,18 @@ class Client {
3282
3465
  }
3283
3466
  }
3284
3467
  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,
3468
+ const response = await this.caller.call(async () => {
3469
+ const res = await this._fetch(`${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetIdToUse}/examples`)}`, {
3470
+ method: "PATCH",
3471
+ headers: this.headers,
3472
+ signal: AbortSignal.timeout(this.timeout_ms),
3473
+ ...this.fetchOptions,
3474
+ body: formData,
3475
+ });
3476
+ await (0, error_js_1.raiseForStatus)(res, "update examples");
3477
+ return res;
3289
3478
  });
3290
- const result = await response.json();
3291
- return result;
3479
+ return response.json();
3292
3480
  }
3293
3481
  /**
3294
3482
  * Upload examples with attachments using multipart form data.
@@ -3360,14 +3548,18 @@ class Client {
3360
3548
  }
3361
3549
  }
3362
3550
  }
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,
3551
+ const response = await this.caller.call(async () => {
3552
+ const res = await this._fetch(`${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetId}/examples`)}`, {
3553
+ method: "POST",
3554
+ headers: this.headers,
3555
+ signal: AbortSignal.timeout(this.timeout_ms),
3556
+ ...this.fetchOptions,
3557
+ body: formData,
3558
+ });
3559
+ await (0, error_js_1.raiseForStatus)(res, "upload examples");
3560
+ return res;
3367
3561
  });
3368
- await (0, error_js_1.raiseForStatus)(response, "upload examples");
3369
- const result = await response.json();
3370
- return result;
3562
+ return response.json();
3371
3563
  }
3372
3564
  async updatePrompt(promptIdentifier, options) {
3373
3565
  if (!(await this.promptExists(promptIdentifier))) {
@@ -3392,17 +3584,21 @@ class Client {
3392
3584
  if (Object.keys(payload).length === 0) {
3393
3585
  throw new Error("No valid update options provided");
3394
3586
  }
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,
3587
+ const body = JSON.stringify(payload);
3588
+ const response = await this.caller.call(async () => {
3589
+ const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
3590
+ method: "PATCH",
3591
+ headers: {
3592
+ ...this.headers,
3593
+ "Content-Type": "application/json",
3594
+ },
3595
+ signal: AbortSignal.timeout(this.timeout_ms),
3596
+ ...this.fetchOptions,
3597
+ body,
3598
+ });
3599
+ await (0, error_js_1.raiseForStatus)(res, "update prompt");
3600
+ return res;
3404
3601
  });
3405
- await (0, error_js_1.raiseForStatus)(response, "update prompt");
3406
3602
  return response.json();
3407
3603
  }
3408
3604
  async deletePrompt(promptIdentifier) {
@@ -3413,23 +3609,30 @@ class Client {
3413
3609
  if (!(await this._currentTenantIsOwner(owner))) {
3414
3610
  throw await this._ownerConflictError("delete a prompt", owner);
3415
3611
  }
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,
3612
+ const response = await this.caller.call(async () => {
3613
+ const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
3614
+ method: "DELETE",
3615
+ headers: this.headers,
3616
+ signal: AbortSignal.timeout(this.timeout_ms),
3617
+ ...this.fetchOptions,
3618
+ });
3619
+ await (0, error_js_1.raiseForStatus)(res, "delete prompt");
3620
+ return res;
3421
3621
  });
3422
- return await response.json();
3622
+ return response.json();
3423
3623
  }
3424
3624
  async pullPromptCommit(promptIdentifier, options) {
3425
3625
  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,
3626
+ const response = await this.caller.call(async () => {
3627
+ const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}/${commitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
3628
+ method: "GET",
3629
+ headers: this.headers,
3630
+ signal: AbortSignal.timeout(this.timeout_ms),
3631
+ ...this.fetchOptions,
3632
+ });
3633
+ await (0, error_js_1.raiseForStatus)(res, "pull prompt commit");
3634
+ return res;
3431
3635
  });
3432
- await (0, error_js_1.raiseForStatus)(response, "pull prompt commit");
3433
3636
  const result = await response.json();
3434
3637
  return {
3435
3638
  owner,