@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.
- package/dist/chat-driver.cjs +17 -5
- package/dist/chat-driver.cjs.map +2 -2
- package/dist/chat-driver.mjs +17 -5
- package/dist/chat-driver.mjs.map +2 -2
- package/package.json +17 -17
package/dist/chat-driver.mjs
CHANGED
|
@@ -1163,12 +1163,22 @@ function readFramedBody(stream, onChunk, vendorLabel, stallTimeout) {
|
|
|
1163
1163
|
var MAX_RETRIES = 5;
|
|
1164
1164
|
function postWithRetry(options) {
|
|
1165
1165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1166
|
-
var _a, _b, _c, _d;
|
|
1166
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1167
1167
|
const { url, headers, body, credentials, vendorLabel, retryableStatuses, timeout, stallTimeout, backoffBaseMs, signal } = options;
|
|
1168
1168
|
const backoff = (attempt) => abortableDelay(backoffBaseMs * (1 << attempt), signal);
|
|
1169
1169
|
for (let attempt = 0; attempt <= MAX_RETRIES; attempt += 1) {
|
|
1170
1170
|
const timeoutController = new AbortController();
|
|
1171
|
-
|
|
1171
|
+
const startedAt = performance.now();
|
|
1172
|
+
let headersAt;
|
|
1173
|
+
let responseCtype;
|
|
1174
|
+
const timedOutMessage = () => {
|
|
1175
|
+
const waited = Math.round(performance.now() - startedAt);
|
|
1176
|
+
if (headersAt === void 0) {
|
|
1177
|
+
return `${vendorLabel} request timed out after ${waited}ms \u2014 no response headers (the service never answered; nothing was received to stall on)`;
|
|
1178
|
+
}
|
|
1179
|
+
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`;
|
|
1180
|
+
};
|
|
1181
|
+
let timeoutId = setTimeout(() => timeoutController.abort(new DOMException(timedOutMessage(), "TimeoutError")), timeout);
|
|
1172
1182
|
const rearmStallTimer = () => {
|
|
1173
1183
|
if (stallTimeout <= 0)
|
|
1174
1184
|
return;
|
|
@@ -1184,6 +1194,8 @@ function postWithRetry(options) {
|
|
|
1184
1194
|
signal: combinedSignal,
|
|
1185
1195
|
credentials
|
|
1186
1196
|
});
|
|
1197
|
+
headersAt = performance.now();
|
|
1198
|
+
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;
|
|
1187
1199
|
if (!response.ok) {
|
|
1188
1200
|
const errText = yield response.text();
|
|
1189
1201
|
const parsed = parseJsonOrUndefined(errText);
|
|
@@ -1198,13 +1210,13 @@ function postWithRetry(options) {
|
|
|
1198
1210
|
}
|
|
1199
1211
|
throw new Error(`${vendorLabel} request error ${response.status}: ${errText}`);
|
|
1200
1212
|
}
|
|
1201
|
-
if (((
|
|
1213
|
+
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) {
|
|
1202
1214
|
rearmStallTimer();
|
|
1203
1215
|
const frame = yield readFramedBody(response.body, rearmStallTimer, vendorLabel, stallTimeout);
|
|
1204
1216
|
if (frame.t === "ok")
|
|
1205
1217
|
return frame.body;
|
|
1206
1218
|
if (frame.code === "UPSTREAM_STALLED") {
|
|
1207
|
-
throw new DOMException(`${vendorLabel} request stalled: ${(
|
|
1219
|
+
throw new DOMException(`${vendorLabel} request stalled: ${(_f = frame.error) !== null && _f !== void 0 ? _f : "no upstream data"}`, "TimeoutError");
|
|
1208
1220
|
}
|
|
1209
1221
|
if (isBudgetRejection(frame.status, frame.code)) {
|
|
1210
1222
|
throw budgetExhaustedFrom(vendorLabel, frame);
|
|
@@ -1215,7 +1227,7 @@ function postWithRetry(options) {
|
|
|
1215
1227
|
yield backoff(attempt);
|
|
1216
1228
|
continue;
|
|
1217
1229
|
}
|
|
1218
|
-
throw new Error(`${vendorLabel} request error ${frame.status}: ${(
|
|
1230
|
+
throw new Error(`${vendorLabel} request error ${frame.status}: ${(_g = frame.error) !== null && _g !== void 0 ? _g : JSON.stringify(frame.details)}`);
|
|
1219
1231
|
}
|
|
1220
1232
|
return yield response.json();
|
|
1221
1233
|
} catch (e) {
|