@genesislcap/ai-assistant 15.8.1 → 15.8.3

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.
@@ -1210,12 +1210,22 @@ function readFramedBody(stream, onChunk, vendorLabel, stallTimeout) {
1210
1210
  var MAX_RETRIES = 5;
1211
1211
  function postWithRetry(options) {
1212
1212
  return __awaiter(this, void 0, void 0, function* () {
1213
- var _a, _b, _c, _d;
1213
+ var _a, _b, _c, _d, _e, _f, _g;
1214
1214
  const { url, headers, body, credentials, vendorLabel, retryableStatuses, timeout, stallTimeout, backoffBaseMs, signal } = options;
1215
1215
  const backoff = (attempt) => abortableDelay(backoffBaseMs * (1 << attempt), signal);
1216
1216
  for (let attempt = 0; attempt <= MAX_RETRIES; attempt += 1) {
1217
1217
  const timeoutController = new AbortController();
1218
- let timeoutId = setTimeout(() => timeoutController.abort(new DOMException(`${vendorLabel} request timed out`, "TimeoutError")), timeout);
1218
+ const startedAt = performance.now();
1219
+ let headersAt;
1220
+ let responseCtype;
1221
+ const timedOutMessage = () => {
1222
+ const waited = Math.round(performance.now() - startedAt);
1223
+ if (headersAt === void 0) {
1224
+ return `${vendorLabel} request timed out after ${waited}ms \u2014 no response headers (the service never answered; nothing was received to stall on)`;
1225
+ }
1226
+ return `${vendorLabel} request timed out after ${waited}ms \u2014 headers arrived in ${Math.round(headersAt - startedAt)}ms (content-type: ${responseCtype !== null && responseCtype !== void 0 ? responseCtype : "unknown"}) but no body followed`;
1227
+ };
1228
+ let timeoutId = setTimeout(() => timeoutController.abort(new DOMException(timedOutMessage(), "TimeoutError")), timeout);
1219
1229
  const rearmStallTimer = () => {
1220
1230
  if (stallTimeout <= 0)
1221
1231
  return;
@@ -1231,6 +1241,8 @@ function postWithRetry(options) {
1231
1241
  signal: combinedSignal,
1232
1242
  credentials
1233
1243
  });
1244
+ headersAt = performance.now();
1245
+ responseCtype = (_c = (_b = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, "content-type")) !== null && _c !== void 0 ? _c : void 0;
1234
1246
  if (!response.ok) {
1235
1247
  const errText = yield response.text();
1236
1248
  const parsed = parseJsonOrUndefined(errText);
@@ -1245,13 +1257,13 @@ function postWithRetry(options) {
1245
1257
  }
1246
1258
  throw new Error(`${vendorLabel} request error ${response.status}: ${errText}`);
1247
1259
  }
1248
- if (((_b = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get("content-type")) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes("application/x-ndjson")) && response.body) {
1260
+ if (((_e = (_d = response.headers) === null || _d === void 0 ? void 0 : _d.get("content-type")) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes("application/x-ndjson")) && response.body) {
1249
1261
  rearmStallTimer();
1250
1262
  const frame = yield readFramedBody(response.body, rearmStallTimer, vendorLabel, stallTimeout);
1251
1263
  if (frame.t === "ok")
1252
1264
  return frame.body;
1253
1265
  if (frame.code === "UPSTREAM_STALLED") {
1254
- throw new DOMException(`${vendorLabel} request stalled: ${(_c = frame.error) !== null && _c !== void 0 ? _c : "no upstream data"}`, "TimeoutError");
1266
+ throw new DOMException(`${vendorLabel} request stalled: ${(_f = frame.error) !== null && _f !== void 0 ? _f : "no upstream data"}`, "TimeoutError");
1255
1267
  }
1256
1268
  if (isBudgetRejection(frame.status, frame.code)) {
1257
1269
  throw budgetExhaustedFrom(vendorLabel, frame);
@@ -1262,7 +1274,7 @@ function postWithRetry(options) {
1262
1274
  yield backoff(attempt);
1263
1275
  continue;
1264
1276
  }
1265
- throw new Error(`${vendorLabel} request error ${frame.status}: ${(_d = frame.error) !== null && _d !== void 0 ? _d : JSON.stringify(frame.details)}`);
1277
+ throw new Error(`${vendorLabel} request error ${frame.status}: ${(_g = frame.error) !== null && _g !== void 0 ? _g : JSON.stringify(frame.details)}`);
1266
1278
  }
1267
1279
  return yield response.json();
1268
1280
  } catch (e) {