@cortexkit/opencode-antigravity-auth 3.0.26 → 3.0.27
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/cli.js.map +1 -1
- package/dist/cli.meta.json +2 -2
- package/dist/index.js +670 -201
- package/dist/index.js.map +3 -3
- package/dist/index.meta.json +18 -18
- package/dist/server.js +874 -325
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/ga/server/index.d.ts +3 -1
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +89 -6
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.js +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +4 -2
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts +1 -1
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +27 -20
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/index.js +2 -2
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/request-helpers.d.ts +139 -0
- package/dist/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/src/plugin/request-helpers.js +512 -0
- package/dist/src/plugin/request-helpers.js.map +1 -1
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +219 -63
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/shared/request-services.d.ts +1 -1
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +36 -127
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/vault-menu.d.ts +1 -1
- package/dist/src/plugin/shared/vault-menu.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-menu.js +4 -2
- package/dist/src/plugin/shared/vault-menu.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +11 -4
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +67 -16
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/types/src/ga/server/index.d.ts +3 -1
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/request-helpers.d.ts +139 -0
- package/dist/types/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts +1 -1
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-menu.d.ts +1 -1
- package/dist/types/src/plugin/shared/vault-menu.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +11 -4
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -29931,6 +29931,11 @@ function createVaultAccountPool(options) {
|
|
|
29931
29931
|
};
|
|
29932
29932
|
let firstRead = null;
|
|
29933
29933
|
const clock2 = options.now ?? Date.now;
|
|
29934
|
+
const schedule2 = options.schedule ?? ((callback, delayMs) => {
|
|
29935
|
+
const timer = setTimeout(callback, delayMs);
|
|
29936
|
+
timer.unref?.();
|
|
29937
|
+
return () => clearTimeout(timer);
|
|
29938
|
+
});
|
|
29934
29939
|
let readGeneration = 0;
|
|
29935
29940
|
let firstReadStartedAt = null;
|
|
29936
29941
|
const readOnce = () => {
|
|
@@ -29945,7 +29950,11 @@ function createVaultAccountPool(options) {
|
|
|
29945
29950
|
firstRead = (async () => {
|
|
29946
29951
|
await source.refresh();
|
|
29947
29952
|
const rows = await rowsFromSource();
|
|
29948
|
-
if (current())
|
|
29953
|
+
if (current())
|
|
29954
|
+
selector.replaceAccounts(rows, {
|
|
29955
|
+
keyOf: vaultAccountRowKey,
|
|
29956
|
+
refresh: refreshVaultAccountRow
|
|
29957
|
+
});
|
|
29949
29958
|
})().then(
|
|
29950
29959
|
() => {
|
|
29951
29960
|
if (current()) firstReadStartedAt = null;
|
|
@@ -29960,39 +29969,64 @@ function createVaultAccountPool(options) {
|
|
|
29960
29969
|
);
|
|
29961
29970
|
return firstRead;
|
|
29962
29971
|
};
|
|
29963
|
-
const
|
|
29964
|
-
let
|
|
29972
|
+
const waitForRead = async (read, signal, remaining) => {
|
|
29973
|
+
let cancelTimer2;
|
|
29974
|
+
let detachAbort;
|
|
29965
29975
|
try {
|
|
29966
|
-
await Promise.race([
|
|
29967
|
-
|
|
29968
|
-
new Promise((
|
|
29969
|
-
|
|
29970
|
-
|
|
29971
|
-
|
|
29972
|
-
|
|
29973
|
-
|
|
29974
|
-
|
|
29975
|
-
2e3
|
|
29976
|
-
);
|
|
29977
|
-
timer.unref?.();
|
|
29976
|
+
return await Promise.race([
|
|
29977
|
+
read.then(() => true),
|
|
29978
|
+
new Promise((resolve27, reject) => {
|
|
29979
|
+
const abort = () => reject(signal?.reason);
|
|
29980
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
29981
|
+
detachAbort = () => signal?.removeEventListener("abort", abort);
|
|
29982
|
+
if (remaining !== void 0)
|
|
29983
|
+
cancelTimer2 = schedule2(() => resolve27(false), remaining);
|
|
29984
|
+
if (signal?.aborted) abort();
|
|
29978
29985
|
})
|
|
29979
29986
|
]);
|
|
29980
29987
|
} finally {
|
|
29981
|
-
|
|
29988
|
+
cancelTimer2?.();
|
|
29989
|
+
detachAbort?.();
|
|
29982
29990
|
}
|
|
29983
29991
|
};
|
|
29992
|
+
const waitForFirstRoster = async (signal) => {
|
|
29993
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
29994
|
+
signal?.throwIfAborted();
|
|
29995
|
+
const read = readOnce();
|
|
29996
|
+
const remaining = firstReadStartedAt === null ? VAULT_REFRESH_STALL_MS : Math.max(0, VAULT_REFRESH_STALL_MS - (clock2() - firstReadStartedAt));
|
|
29997
|
+
if (await waitForRead(read, signal, remaining)) return;
|
|
29998
|
+
}
|
|
29999
|
+
throw new Error(
|
|
30000
|
+
"The vault roster is not available yet. Check vault access and try the request again."
|
|
30001
|
+
);
|
|
30002
|
+
};
|
|
29984
30003
|
return {
|
|
29985
30004
|
selector,
|
|
29986
30005
|
credentials,
|
|
29987
30006
|
state,
|
|
29988
|
-
async sync() {
|
|
30007
|
+
async sync(signal) {
|
|
29989
30008
|
const pending = firstRead;
|
|
29990
|
-
await waitForFirstRoster();
|
|
30009
|
+
await waitForFirstRoster(signal);
|
|
29991
30010
|
if (pending !== null) await replace();
|
|
29992
30011
|
},
|
|
29993
|
-
|
|
29994
|
-
|
|
29995
|
-
|
|
30012
|
+
syncCached: replace,
|
|
30013
|
+
async syncForDisplay(signal) {
|
|
30014
|
+
try {
|
|
30015
|
+
signal?.throwIfAborted();
|
|
30016
|
+
const read = readOnce();
|
|
30017
|
+
const remaining = firstReadStartedAt === null ? 0 : Math.max(
|
|
30018
|
+
0,
|
|
30019
|
+
VAULT_DISPLAY_ROSTER_WAIT_MS - (clock2() - firstReadStartedAt)
|
|
30020
|
+
);
|
|
30021
|
+
await waitForRead(read, signal, remaining);
|
|
30022
|
+
} catch {
|
|
30023
|
+
}
|
|
30024
|
+
await replace();
|
|
30025
|
+
},
|
|
30026
|
+
async refresh(signal) {
|
|
30027
|
+
const discovering = firstRead === null || firstReadStartedAt !== null;
|
|
30028
|
+
await waitForFirstRoster(signal);
|
|
30029
|
+
if (!discovering) await waitForRead(source.refresh(), signal);
|
|
29996
30030
|
await replace();
|
|
29997
30031
|
},
|
|
29998
30032
|
flush: async () => {
|
|
@@ -30092,7 +30126,7 @@ async function checkVaultQuota(input2) {
|
|
|
30092
30126
|
}
|
|
30093
30127
|
return { checked, notChecked: rows.length - checked };
|
|
30094
30128
|
}
|
|
30095
|
-
var VaultSendGrant, VAULT_REFRESH_STALL_MS;
|
|
30129
|
+
var VaultSendGrant, VAULT_REFRESH_STALL_MS, VAULT_DISPLAY_ROSTER_WAIT_MS;
|
|
30096
30130
|
var init_vault_request_credentials = __esm({
|
|
30097
30131
|
"src/plugin/shared/vault-request-credentials.ts"() {
|
|
30098
30132
|
"use strict";
|
|
@@ -30118,6 +30152,7 @@ var init_vault_request_credentials = __esm({
|
|
|
30118
30152
|
}
|
|
30119
30153
|
};
|
|
30120
30154
|
VAULT_REFRESH_STALL_MS = 3e4;
|
|
30155
|
+
VAULT_DISPLAY_ROSTER_WAIT_MS = 2e3;
|
|
30121
30156
|
}
|
|
30122
30157
|
});
|
|
30123
30158
|
|
|
@@ -49168,6 +49203,358 @@ function createNativeGoogleErrorResponse(options) {
|
|
|
49168
49203
|
headers
|
|
49169
49204
|
});
|
|
49170
49205
|
}
|
|
49206
|
+
function extractAntigravityError(body) {
|
|
49207
|
+
if (!body || typeof body !== "object") return null;
|
|
49208
|
+
let target = body;
|
|
49209
|
+
if (Array.isArray(body)) {
|
|
49210
|
+
if (body.length === 0 || !body[0] || typeof body[0] !== "object" || Array.isArray(body[0])) {
|
|
49211
|
+
return null;
|
|
49212
|
+
}
|
|
49213
|
+
target = body[0];
|
|
49214
|
+
}
|
|
49215
|
+
const candidate = target.error;
|
|
49216
|
+
if (candidate && typeof candidate === "object" && !Array.isArray(candidate)) {
|
|
49217
|
+
return candidate;
|
|
49218
|
+
}
|
|
49219
|
+
return null;
|
|
49220
|
+
}
|
|
49221
|
+
var MAX_FINITE_WAIT_MS = BigInt(Math.ceil(Number.MAX_VALUE));
|
|
49222
|
+
var MAX_FINITE_WAIT_SECONDS = (MAX_FINITE_WAIT_MS + 999n) / 1000n;
|
|
49223
|
+
var MAX_FINITE_FORWARDING_MS = MAX_FINITE_WAIT_SECONDS * 1000n;
|
|
49224
|
+
var RFC_HTTP_DATE_REGEX = /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), \d{2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4} \d{2}:\d{2}:\d{2} GMT$/;
|
|
49225
|
+
function validateRetryAfterSecondsBigInt(raw) {
|
|
49226
|
+
if (raw === null || raw === void 0) return null;
|
|
49227
|
+
if (typeof raw === "bigint") {
|
|
49228
|
+
return raw >= 0n && raw <= MAX_FINITE_WAIT_SECONDS ? raw : null;
|
|
49229
|
+
}
|
|
49230
|
+
if (typeof raw === "number") {
|
|
49231
|
+
if (!Number.isFinite(raw) || raw < 0 || !Number.isInteger(raw)) {
|
|
49232
|
+
return null;
|
|
49233
|
+
}
|
|
49234
|
+
const b = BigInt(raw);
|
|
49235
|
+
return b <= MAX_FINITE_WAIT_SECONDS ? b : null;
|
|
49236
|
+
}
|
|
49237
|
+
if (typeof raw !== "string") return null;
|
|
49238
|
+
const trimmed = raw.trim();
|
|
49239
|
+
if (trimmed.length === 0) return null;
|
|
49240
|
+
if (/^\d+$/.test(trimmed)) {
|
|
49241
|
+
if (trimmed.length > 309) return null;
|
|
49242
|
+
const val = BigInt(trimmed);
|
|
49243
|
+
return val >= 0n && val <= MAX_FINITE_WAIT_SECONDS ? val : null;
|
|
49244
|
+
}
|
|
49245
|
+
if (RFC_HTTP_DATE_REGEX.test(trimmed)) {
|
|
49246
|
+
const parsedDate = Date.parse(trimmed);
|
|
49247
|
+
if (!Number.isNaN(parsedDate)) {
|
|
49248
|
+
const roundtrip = new Date(parsedDate).toUTCString();
|
|
49249
|
+
if (roundtrip === trimmed) {
|
|
49250
|
+
const diffSec = Math.ceil((parsedDate - Date.now()) / 1e3);
|
|
49251
|
+
if (diffSec >= 0 && Number.isSafeInteger(diffSec)) {
|
|
49252
|
+
return BigInt(diffSec);
|
|
49253
|
+
}
|
|
49254
|
+
}
|
|
49255
|
+
}
|
|
49256
|
+
}
|
|
49257
|
+
return null;
|
|
49258
|
+
}
|
|
49259
|
+
function validateRetryAfterMsBigInt(raw) {
|
|
49260
|
+
if (raw === null || raw === void 0) return null;
|
|
49261
|
+
if (typeof raw === "bigint") {
|
|
49262
|
+
return raw >= 0n && raw <= MAX_FINITE_FORWARDING_MS ? raw : null;
|
|
49263
|
+
}
|
|
49264
|
+
if (typeof raw === "number") {
|
|
49265
|
+
if (!Number.isFinite(raw) || raw < 0 || !Number.isInteger(raw)) {
|
|
49266
|
+
return null;
|
|
49267
|
+
}
|
|
49268
|
+
const b = BigInt(raw);
|
|
49269
|
+
return b <= MAX_FINITE_FORWARDING_MS ? b : null;
|
|
49270
|
+
}
|
|
49271
|
+
if (typeof raw !== "string") return null;
|
|
49272
|
+
const trimmed = raw.trim();
|
|
49273
|
+
if (trimmed.length === 0 || !/^\d+$/.test(trimmed)) return null;
|
|
49274
|
+
if (trimmed.length > 309) return null;
|
|
49275
|
+
const val = BigInt(trimmed);
|
|
49276
|
+
return val >= 0n && val <= MAX_FINITE_FORWARDING_MS ? val : null;
|
|
49277
|
+
}
|
|
49278
|
+
function deriveRetryHeaderPairFromMs(ms) {
|
|
49279
|
+
if (typeof ms !== "bigint" || ms < 0n || ms > MAX_FINITE_FORWARDING_MS) {
|
|
49280
|
+
throw new RangeError(
|
|
49281
|
+
`deriveRetryHeaderPairFromMs: ms must be a non-negative BigInt <= MAX_FINITE_FORWARDING_MS (got ${String(ms)})`
|
|
49282
|
+
);
|
|
49283
|
+
}
|
|
49284
|
+
const sec = (ms + 999n) / 1000n;
|
|
49285
|
+
return {
|
|
49286
|
+
"retry-after": sec.toString(),
|
|
49287
|
+
"retry-after-ms": ms.toString()
|
|
49288
|
+
};
|
|
49289
|
+
}
|
|
49290
|
+
function deriveRetryHeaderPairFromSeconds(sec) {
|
|
49291
|
+
if (typeof sec !== "bigint" || sec < 0n || sec > MAX_FINITE_WAIT_SECONDS) {
|
|
49292
|
+
throw new RangeError(
|
|
49293
|
+
`deriveRetryHeaderPairFromSeconds: sec must be a non-negative BigInt <= MAX_FINITE_WAIT_SECONDS (got ${String(sec)})`
|
|
49294
|
+
);
|
|
49295
|
+
}
|
|
49296
|
+
const ms = sec * 1000n;
|
|
49297
|
+
return {
|
|
49298
|
+
"retry-after": sec.toString(),
|
|
49299
|
+
"retry-after-ms": ms.toString()
|
|
49300
|
+
};
|
|
49301
|
+
}
|
|
49302
|
+
function collectForwardedHeaders(sourceHeaders) {
|
|
49303
|
+
if (!sourceHeaders) return {};
|
|
49304
|
+
const getHeader2 = (name) => {
|
|
49305
|
+
if (typeof sourceHeaders.get === "function") {
|
|
49306
|
+
return sourceHeaders.get(name);
|
|
49307
|
+
}
|
|
49308
|
+
const record3 = sourceHeaders;
|
|
49309
|
+
for (const [key, value] of Object.entries(record3)) {
|
|
49310
|
+
if (key.toLowerCase() === name) return value;
|
|
49311
|
+
}
|
|
49312
|
+
return void 0;
|
|
49313
|
+
};
|
|
49314
|
+
const rawRetryAfterMs = getHeader2("retry-after-ms");
|
|
49315
|
+
const validMs = validateRetryAfterMsBigInt(rawRetryAfterMs);
|
|
49316
|
+
if (validMs !== null) {
|
|
49317
|
+
return deriveRetryHeaderPairFromMs(validMs);
|
|
49318
|
+
}
|
|
49319
|
+
const rawRetryAfter = getHeader2("retry-after");
|
|
49320
|
+
const validSec = validateRetryAfterSecondsBigInt(rawRetryAfter);
|
|
49321
|
+
if (validSec !== null) {
|
|
49322
|
+
return deriveRetryHeaderPairFromSeconds(validSec);
|
|
49323
|
+
}
|
|
49324
|
+
return {};
|
|
49325
|
+
}
|
|
49326
|
+
function isQuotaError(status, message, details) {
|
|
49327
|
+
if (status === 429) return true;
|
|
49328
|
+
const lower = (message ?? "").toLowerCase();
|
|
49329
|
+
if (hasQuotaResetClause(lower)) return true;
|
|
49330
|
+
return hasStructuredQuotaReason(details);
|
|
49331
|
+
}
|
|
49332
|
+
var QUOTA_REASON_CODES = /* @__PURE__ */ new Set([
|
|
49333
|
+
"QUOTA_EXHAUSTED",
|
|
49334
|
+
"RATE_LIMIT_EXCEEDED",
|
|
49335
|
+
"RESOURCE_EXHAUSTED"
|
|
49336
|
+
]);
|
|
49337
|
+
function hasQuotaResetClause(lowerMessage) {
|
|
49338
|
+
if (lowerMessage.length === 0) return false;
|
|
49339
|
+
if (extractResetDurationFromText(lowerMessage) === null) return false;
|
|
49340
|
+
return lowerMessage.includes("quota") || lowerMessage.includes("rate limit") || lowerMessage.includes("rate_limit") || lowerMessage.includes("resource_exhausted");
|
|
49341
|
+
}
|
|
49342
|
+
function hasStructuredQuotaReason(details) {
|
|
49343
|
+
if (!Array.isArray(details)) return false;
|
|
49344
|
+
return details.some((detail) => {
|
|
49345
|
+
if (!detail || typeof detail !== "object") return false;
|
|
49346
|
+
const record3 = detail;
|
|
49347
|
+
const type = record3["@type"];
|
|
49348
|
+
if (typeof type === "string" && type.includes("google.rpc.QuotaFailure"))
|
|
49349
|
+
return true;
|
|
49350
|
+
const reason = record3.reason;
|
|
49351
|
+
if (typeof reason === "string" && QUOTA_REASON_CODES.has(reason))
|
|
49352
|
+
return true;
|
|
49353
|
+
const nested = record3.details;
|
|
49354
|
+
return Array.isArray(nested) ? hasStructuredQuotaReason(nested) : false;
|
|
49355
|
+
});
|
|
49356
|
+
}
|
|
49357
|
+
var RESET_CLAUSE_REGEX = /\b(?:quota\s+)?resets?\s+(?:in|after)\s+(?=\d+(?:\.\d+)?[ \t]*(?:ms|[dhms]))((?:(?:\d+(?:\.\d+)?[ \t]*d)[ \t]*)?(?:(?:\d+(?:\.\d+)?[ \t]*h)[ \t]*)?(?:(?:\d+(?:\.\d+)?[ \t]*m(?!s))[ \t]*)?(?:(?:\d+(?:\.\d+)?[ \t]*s)[ \t]*)?(?:(?:\d+(?:\.\d+)?[ \t]*ms))?)(?![a-zA-Z0-9_-])/gi;
|
|
49358
|
+
function extractResetDurationFromText(text2) {
|
|
49359
|
+
if (typeof text2 !== "string" || text2.length === 0) return null;
|
|
49360
|
+
const regex = new RegExp(RESET_CLAUSE_REGEX.source, "i");
|
|
49361
|
+
const match = text2.match(regex);
|
|
49362
|
+
if (!match?.[1]) return null;
|
|
49363
|
+
const raw = match[1].trim().replace(/[.,;:]+$/, "");
|
|
49364
|
+
return raw.length > 0 ? raw : null;
|
|
49365
|
+
}
|
|
49366
|
+
function normalizeResetDuration(text2) {
|
|
49367
|
+
if (typeof text2 !== "string" || text2.length === 0) return text2;
|
|
49368
|
+
return text2.replace(RESET_CLAUSE_REGEX, (_match, rawDuration) => {
|
|
49369
|
+
if (!rawDuration) return _match;
|
|
49370
|
+
const duration = String(rawDuration).match(/^(.*?)([ \t]*)$/);
|
|
49371
|
+
if (!duration) return _match;
|
|
49372
|
+
const spaced = (duration[1] ?? "").replace(
|
|
49373
|
+
/(\d+(?:\.\d+)?)[ \t]*(ms|[dhms])(?=\d)/gi,
|
|
49374
|
+
"$1$2 "
|
|
49375
|
+
);
|
|
49376
|
+
return `quota resets in ${spaced}${duration[2] ?? ""}`;
|
|
49377
|
+
});
|
|
49378
|
+
}
|
|
49379
|
+
var DURATION_REGEX = /^(?:(\d+(?:\.\d+)?|\.\d+)[ \t]*d)?(?:[ \t]*(\d+(?:\.\d+)?|\.\d+)[ \t]*h)?(?:[ \t]*(\d+(?:\.\d+)?|\.\d+)[ \t]*m(?!s))?(?:[ \t]*(\d+(?:\.\d+)?|\.\d+)[ \t]*s)?(?:[ \t]*(\d+(?:\.\d+)?|\.\d+)[ \t]*ms)?$/i;
|
|
49380
|
+
function parseDecimalComponent(str, multMs) {
|
|
49381
|
+
const parts = str.split(".");
|
|
49382
|
+
const intStr = parts[0] ?? "";
|
|
49383
|
+
const fracStr = parts[1] ?? "";
|
|
49384
|
+
const effectiveIntStr = intStr.replace(/^0+/, "");
|
|
49385
|
+
if (effectiveIntStr.length > 15) return null;
|
|
49386
|
+
if (str.length > 60) return null;
|
|
49387
|
+
const intPart = intStr.length > 0 ? BigInt(intStr) : 0n;
|
|
49388
|
+
return { intPart, fracStr, mult: multMs };
|
|
49389
|
+
}
|
|
49390
|
+
function parseDurationToMsBigInt(duration, options) {
|
|
49391
|
+
if (typeof duration !== "string") return null;
|
|
49392
|
+
const trimmed = duration.trim();
|
|
49393
|
+
if (trimmed.length === 0) return null;
|
|
49394
|
+
let dStr;
|
|
49395
|
+
let hStr;
|
|
49396
|
+
let mStr;
|
|
49397
|
+
let sStr;
|
|
49398
|
+
let msStr;
|
|
49399
|
+
const match = trimmed.match(DURATION_REGEX);
|
|
49400
|
+
if (match) {
|
|
49401
|
+
;
|
|
49402
|
+
[, dStr, hStr, mStr, sStr, msStr] = match;
|
|
49403
|
+
}
|
|
49404
|
+
if (dStr === void 0 && hStr === void 0 && mStr === void 0 && sStr === void 0 && msStr === void 0) {
|
|
49405
|
+
if (options?.allowBareSeconds && /^(?:\d+(?:\.\d+)?|\.\d+)$/.test(trimmed)) {
|
|
49406
|
+
sStr = trimmed;
|
|
49407
|
+
} else {
|
|
49408
|
+
return null;
|
|
49409
|
+
}
|
|
49410
|
+
}
|
|
49411
|
+
const rawComponents = [];
|
|
49412
|
+
if (dStr !== void 0) rawComponents.push({ str: dStr, mult: 86400000n });
|
|
49413
|
+
if (hStr !== void 0) rawComponents.push({ str: hStr, mult: 3600000n });
|
|
49414
|
+
if (mStr !== void 0) rawComponents.push({ str: mStr, mult: 60000n });
|
|
49415
|
+
if (sStr !== void 0) rawComponents.push({ str: sStr, mult: 1000n });
|
|
49416
|
+
if (msStr !== void 0) rawComponents.push({ str: msStr, mult: 1n });
|
|
49417
|
+
if (rawComponents.length === 0) return null;
|
|
49418
|
+
let maxFracDigits = 0;
|
|
49419
|
+
const parsedComponents = [];
|
|
49420
|
+
for (const rc of rawComponents) {
|
|
49421
|
+
const parsed = parseDecimalComponent(rc.str, rc.mult);
|
|
49422
|
+
if (!parsed) return null;
|
|
49423
|
+
if (parsed.fracStr.length > maxFracDigits) {
|
|
49424
|
+
maxFracDigits = parsed.fracStr.length;
|
|
49425
|
+
}
|
|
49426
|
+
parsedComponents.push(parsed);
|
|
49427
|
+
}
|
|
49428
|
+
const commonDenominator = 10n ** BigInt(maxFracDigits);
|
|
49429
|
+
let totalScaledNumerator = 0n;
|
|
49430
|
+
for (const c of parsedComponents) {
|
|
49431
|
+
const fracLen = BigInt(c.fracStr.length);
|
|
49432
|
+
const fracVal = c.fracStr.length > 0 ? BigInt(c.fracStr) : 0n;
|
|
49433
|
+
const scaleFactor = 10n ** (BigInt(maxFracDigits) - fracLen);
|
|
49434
|
+
const numerator = (c.intPart * commonDenominator + fracVal * scaleFactor) * c.mult;
|
|
49435
|
+
totalScaledNumerator += numerator;
|
|
49436
|
+
}
|
|
49437
|
+
if (totalScaledNumerator === 0n) {
|
|
49438
|
+
return options?.allowZero ? 0n : null;
|
|
49439
|
+
}
|
|
49440
|
+
const quotient = totalScaledNumerator / commonDenominator;
|
|
49441
|
+
const remainder = totalScaledNumerator % commonDenominator;
|
|
49442
|
+
let rounded = remainder * 2n >= commonDenominator ? quotient + 1n : quotient;
|
|
49443
|
+
if (rounded === 0n) {
|
|
49444
|
+
rounded = 1n;
|
|
49445
|
+
}
|
|
49446
|
+
if (rounded > MAX_FINITE_FORWARDING_MS) {
|
|
49447
|
+
return null;
|
|
49448
|
+
}
|
|
49449
|
+
return rounded;
|
|
49450
|
+
}
|
|
49451
|
+
function resolveRetryMetadata(options) {
|
|
49452
|
+
const {
|
|
49453
|
+
details,
|
|
49454
|
+
message,
|
|
49455
|
+
status,
|
|
49456
|
+
headers,
|
|
49457
|
+
retryAfterMs,
|
|
49458
|
+
resetAfterMs,
|
|
49459
|
+
retryAfterSeconds,
|
|
49460
|
+
allowZero,
|
|
49461
|
+
allowBareSeconds
|
|
49462
|
+
} = options;
|
|
49463
|
+
const bodyParserOptions = {
|
|
49464
|
+
allowZero,
|
|
49465
|
+
allowBareSeconds
|
|
49466
|
+
};
|
|
49467
|
+
if (Array.isArray(details)) {
|
|
49468
|
+
for (const entry of details) {
|
|
49469
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
49470
|
+
const type = entry["@type"];
|
|
49471
|
+
if (typeof type === "string" && type.includes("google.rpc.RetryInfo")) {
|
|
49472
|
+
const retryDelay = entry.retryDelay;
|
|
49473
|
+
if (typeof retryDelay === "string") {
|
|
49474
|
+
const ms = parseDurationToMsBigInt(retryDelay, bodyParserOptions);
|
|
49475
|
+
if (ms !== null) {
|
|
49476
|
+
return { delayMs: ms };
|
|
49477
|
+
}
|
|
49478
|
+
} else if (typeof retryDelay === "number") {
|
|
49479
|
+
if (Number.isFinite(retryDelay) && retryDelay >= 0) {
|
|
49480
|
+
const scaled = retryDelay * 1e3;
|
|
49481
|
+
if (Number.isFinite(scaled)) {
|
|
49482
|
+
const rounded = Math.round(scaled);
|
|
49483
|
+
if (Number.isSafeInteger(rounded) && rounded >= 0) {
|
|
49484
|
+
if (retryDelay === 0) {
|
|
49485
|
+
if (allowZero) return { delayMs: 0n };
|
|
49486
|
+
} else {
|
|
49487
|
+
return { delayMs: BigInt(Math.max(1, rounded)) };
|
|
49488
|
+
}
|
|
49489
|
+
}
|
|
49490
|
+
}
|
|
49491
|
+
}
|
|
49492
|
+
}
|
|
49493
|
+
}
|
|
49494
|
+
}
|
|
49495
|
+
for (const entry of details) {
|
|
49496
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
49497
|
+
const metadata = entry.metadata;
|
|
49498
|
+
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
49499
|
+
const quotaResetDelay = metadata.quotaResetDelay;
|
|
49500
|
+
if (typeof quotaResetDelay === "string") {
|
|
49501
|
+
const ms = parseDurationToMsBigInt(quotaResetDelay, bodyParserOptions);
|
|
49502
|
+
if (ms !== null) {
|
|
49503
|
+
const quotaResetTime = typeof metadata.quotaResetTimeStamp === "string" ? metadata.quotaResetTimeStamp : typeof metadata.quotaResetTime === "string" ? metadata.quotaResetTime : void 0;
|
|
49504
|
+
return {
|
|
49505
|
+
delayMs: ms,
|
|
49506
|
+
...quotaResetTime !== void 0 ? { quotaResetTime } : {}
|
|
49507
|
+
};
|
|
49508
|
+
}
|
|
49509
|
+
}
|
|
49510
|
+
}
|
|
49511
|
+
}
|
|
49512
|
+
}
|
|
49513
|
+
const validGaMs = validateRetryAfterMsBigInt(retryAfterMs);
|
|
49514
|
+
if (validGaMs !== null) {
|
|
49515
|
+
return { delayMs: validGaMs };
|
|
49516
|
+
}
|
|
49517
|
+
const validResetMs = validateRetryAfterMsBigInt(resetAfterMs);
|
|
49518
|
+
if (validResetMs !== null) {
|
|
49519
|
+
return { delayMs: validResetMs };
|
|
49520
|
+
}
|
|
49521
|
+
const validGaSec = validateRetryAfterSecondsBigInt(retryAfterSeconds);
|
|
49522
|
+
if (validGaSec !== null) {
|
|
49523
|
+
return { delayMs: validGaSec * 1000n };
|
|
49524
|
+
}
|
|
49525
|
+
if (isQuotaError(status, message, details) && typeof message === "string") {
|
|
49526
|
+
const rawDuration = extractResetDurationFromText(message);
|
|
49527
|
+
if (rawDuration !== null) {
|
|
49528
|
+
const ms = parseDurationToMsBigInt(rawDuration, bodyParserOptions);
|
|
49529
|
+
if (ms !== null) {
|
|
49530
|
+
return { delayMs: ms };
|
|
49531
|
+
}
|
|
49532
|
+
}
|
|
49533
|
+
}
|
|
49534
|
+
if (headers) {
|
|
49535
|
+
const getHeader2 = (name) => {
|
|
49536
|
+
if (typeof headers.get === "function") {
|
|
49537
|
+
return headers.get(name);
|
|
49538
|
+
}
|
|
49539
|
+
const record3 = headers;
|
|
49540
|
+
for (const [key, value] of Object.entries(record3)) {
|
|
49541
|
+
if (key.toLowerCase() === name) return value;
|
|
49542
|
+
}
|
|
49543
|
+
return void 0;
|
|
49544
|
+
};
|
|
49545
|
+
const rawMs = getHeader2("retry-after-ms");
|
|
49546
|
+
const validHeaderMs = validateRetryAfterMsBigInt(rawMs);
|
|
49547
|
+
if (validHeaderMs !== null) {
|
|
49548
|
+
return { delayMs: validHeaderMs };
|
|
49549
|
+
}
|
|
49550
|
+
const rawSec = getHeader2("retry-after");
|
|
49551
|
+
const validHeaderSec = validateRetryAfterSecondsBigInt(rawSec);
|
|
49552
|
+
if (validHeaderSec !== null) {
|
|
49553
|
+
return { delayMs: validHeaderSec * 1000n };
|
|
49554
|
+
}
|
|
49555
|
+
}
|
|
49556
|
+
return null;
|
|
49557
|
+
}
|
|
49171
49558
|
|
|
49172
49559
|
// src/plugin/thinking-recovery.ts
|
|
49173
49560
|
function isThinkingPart2(part) {
|
|
@@ -50888,10 +51275,12 @@ async function transformAntigravityResponseIn(wire, response, streaming, debugCo
|
|
|
50888
51275
|
const debugText = wire.debug.isDebugTuiEnabled() && Array.isArray(debugLines) && debugLines.length > 0 ? formatDebugLinesForThinking(debugLines) : wire.signatures.keepThinking ? SYNTHETIC_THINKING_PLACEHOLDER : void 0;
|
|
50889
51276
|
const cacheSignatures = shouldCacheThinkingSignatures(effectiveModel);
|
|
50890
51277
|
if (!isJsonResponse && !isEventStreamResponse) {
|
|
50891
|
-
|
|
50892
|
-
|
|
50893
|
-
|
|
50894
|
-
|
|
51278
|
+
if (response.ok) {
|
|
51279
|
+
wire.debug.logAntigravityDebugResponse(debugContext, response, {
|
|
51280
|
+
note: "Non-JSON response (body omitted)"
|
|
51281
|
+
});
|
|
51282
|
+
return response;
|
|
51283
|
+
}
|
|
50895
51284
|
}
|
|
50896
51285
|
if (streaming && response.ok && isEventStreamResponse && response.body) {
|
|
50897
51286
|
const headers = new Headers(response.headers);
|
|
@@ -50940,27 +51329,143 @@ async function transformAntigravityResponseIn(wire, response, streaming, debugCo
|
|
|
50940
51329
|
headers
|
|
50941
51330
|
});
|
|
50942
51331
|
}
|
|
50943
|
-
|
|
50944
|
-
|
|
51332
|
+
if (!response.ok) {
|
|
51333
|
+
const projectIds = projectId ? [projectId] : void 0;
|
|
50945
51334
|
const headers = new Headers(response.headers);
|
|
50946
|
-
const
|
|
51335
|
+
const initialForwarded = collectForwardedHeaders(headers);
|
|
51336
|
+
if (initialForwarded["retry-after"] !== void 0 && initialForwarded["retry-after-ms"] !== void 0) {
|
|
51337
|
+
headers.set("Retry-After", initialForwarded["retry-after"]);
|
|
51338
|
+
headers.set("retry-after", initialForwarded["retry-after"]);
|
|
51339
|
+
headers.set("retry-after-ms", initialForwarded["retry-after-ms"]);
|
|
51340
|
+
} else {
|
|
51341
|
+
headers.delete("Retry-After");
|
|
51342
|
+
headers.delete("retry-after");
|
|
51343
|
+
headers.delete("retry-after-ms");
|
|
51344
|
+
}
|
|
51345
|
+
let text2;
|
|
51346
|
+
try {
|
|
51347
|
+
text2 = await response.text();
|
|
51348
|
+
} catch (readError) {
|
|
51349
|
+
const sanitizedCause = readError instanceof Error || readError !== null && typeof readError === "object" ? redactCredentialError(readError, void 0, projectIds) : void 0;
|
|
51350
|
+
const safeMessage = sanitizedCause ? sanitizedCause.message : redactCredentialText(String(readError), void 0, projectIds);
|
|
51351
|
+
const scrubbedStatusText = redactCredentialText(
|
|
51352
|
+
response.statusText,
|
|
51353
|
+
void 0,
|
|
51354
|
+
projectIds
|
|
51355
|
+
);
|
|
51356
|
+
const plainHeaders = {};
|
|
51357
|
+
for (const [key, value] of headers.entries()) {
|
|
51358
|
+
plainHeaders[key] = redactCredentialText(value, void 0, projectIds);
|
|
51359
|
+
}
|
|
51360
|
+
if (initialForwarded["retry-after"] !== void 0 && initialForwarded["retry-after-ms"] !== void 0) {
|
|
51361
|
+
plainHeaders["retry-after"] = initialForwarded["retry-after"];
|
|
51362
|
+
plainHeaders["retry-after-ms"] = initialForwarded["retry-after-ms"];
|
|
51363
|
+
plainHeaders["Retry-After"] = initialForwarded["retry-after"];
|
|
51364
|
+
}
|
|
51365
|
+
const freshError = new Error(
|
|
51366
|
+
`Failed to read response body: ${safeMessage}`,
|
|
51367
|
+
sanitizedCause ? { cause: sanitizedCause } : void 0
|
|
51368
|
+
);
|
|
51369
|
+
Object.assign(freshError, {
|
|
51370
|
+
statusCode: response.status,
|
|
51371
|
+
status: response.status,
|
|
51372
|
+
statusText: scrubbedStatusText,
|
|
51373
|
+
headers: plainHeaders
|
|
51374
|
+
});
|
|
51375
|
+
throw freshError;
|
|
51376
|
+
}
|
|
50947
51377
|
noteGeminiDumpResponse(dumpContext, response);
|
|
50948
51378
|
appendGeminiDumpResponseText(dumpContext, text2);
|
|
50949
|
-
|
|
50950
|
-
|
|
51379
|
+
const createSafeFallback = (bodyContent, contentTypeOverride) => {
|
|
51380
|
+
const fallbackHeaders = new Headers(headers);
|
|
51381
|
+
fallbackHeaders.delete("content-length");
|
|
51382
|
+
if (contentTypeOverride) {
|
|
51383
|
+
fallbackHeaders.set("content-type", contentTypeOverride);
|
|
51384
|
+
}
|
|
51385
|
+
const safeText = redactProjectIdText(bodyContent, projectIds);
|
|
51386
|
+
const fallbackResponse = new Response(safeText, {
|
|
51387
|
+
status: response.status,
|
|
51388
|
+
statusText: response.statusText,
|
|
51389
|
+
headers: fallbackHeaders
|
|
51390
|
+
});
|
|
51391
|
+
return redactCredentialResponse(
|
|
51392
|
+
fallbackResponse,
|
|
51393
|
+
void 0,
|
|
51394
|
+
safeText,
|
|
51395
|
+
projectIds
|
|
51396
|
+
);
|
|
51397
|
+
};
|
|
51398
|
+
try {
|
|
51399
|
+
let parsedBody = null;
|
|
51400
|
+
let isJson = false;
|
|
50951
51401
|
try {
|
|
50952
|
-
|
|
51402
|
+
parsedBody = JSON.parse(text2);
|
|
51403
|
+
isJson = true;
|
|
50953
51404
|
} catch {
|
|
50954
|
-
|
|
51405
|
+
isJson = false;
|
|
51406
|
+
}
|
|
51407
|
+
if (!isJson && (isEventStreamResponse || text2.includes("data:"))) {
|
|
51408
|
+
for (const line of text2.split("\n")) {
|
|
51409
|
+
const trimmed = line.trim();
|
|
51410
|
+
if (trimmed.startsWith("data:")) {
|
|
51411
|
+
const payload = trimmed.slice(5).trim();
|
|
51412
|
+
if (payload.length > 0 && payload !== "[DONE]") {
|
|
51413
|
+
try {
|
|
51414
|
+
parsedBody = JSON.parse(payload);
|
|
51415
|
+
isJson = true;
|
|
51416
|
+
break;
|
|
51417
|
+
} catch {
|
|
51418
|
+
}
|
|
51419
|
+
}
|
|
51420
|
+
}
|
|
51421
|
+
}
|
|
50955
51422
|
}
|
|
50956
|
-
if (
|
|
50957
|
-
|
|
50958
|
-
|
|
50959
|
-
|
|
50960
|
-
|
|
50961
|
-
|
|
50962
|
-
|
|
50963
|
-
|
|
51423
|
+
if (!isJson && isJsonResponse) {
|
|
51424
|
+
parsedBody = {
|
|
51425
|
+
error: {
|
|
51426
|
+
code: response.status,
|
|
51427
|
+
message: text2,
|
|
51428
|
+
status: "UNAVAILABLE"
|
|
51429
|
+
}
|
|
51430
|
+
};
|
|
51431
|
+
isJson = true;
|
|
51432
|
+
}
|
|
51433
|
+
const errorRecord = isJson ? extractAntigravityError(parsedBody) : null;
|
|
51434
|
+
const retryMeta = resolveRetryMetadata({
|
|
51435
|
+
details: errorRecord?.details,
|
|
51436
|
+
message: typeof errorRecord?.message === "string" ? errorRecord.message : void 0,
|
|
51437
|
+
status: response.status,
|
|
51438
|
+
headers,
|
|
51439
|
+
// The transformer renders what the host sees, so it follows the
|
|
51440
|
+
// executor's rule: an upstream zero delay falls through to the
|
|
51441
|
+
// response's own header instead of becoming a zero wait here.
|
|
51442
|
+
allowZero: false
|
|
51443
|
+
});
|
|
51444
|
+
if (retryMeta !== null) {
|
|
51445
|
+
const pair = deriveRetryHeaderPairFromMs(retryMeta.delayMs);
|
|
51446
|
+
headers.set("Retry-After", pair["retry-after"]);
|
|
51447
|
+
headers.set("retry-after", pair["retry-after"]);
|
|
51448
|
+
headers.set("retry-after-ms", pair["retry-after-ms"]);
|
|
51449
|
+
} else {
|
|
51450
|
+
headers.delete("Retry-After");
|
|
51451
|
+
headers.delete("retry-after");
|
|
51452
|
+
headers.delete("retry-after-ms");
|
|
51453
|
+
}
|
|
51454
|
+
let diagnosticErrorText = "";
|
|
51455
|
+
if (errorRecord && typeof errorRecord.message === "string") {
|
|
51456
|
+
diagnosticErrorText = errorRecord.message;
|
|
51457
|
+
} else if (parsedBody && typeof parsedBody === "object" && !Array.isArray(parsedBody)) {
|
|
51458
|
+
const errProp = parsedBody.error;
|
|
51459
|
+
if (typeof errProp === "string") {
|
|
51460
|
+
diagnosticErrorText = errProp;
|
|
51461
|
+
} else {
|
|
51462
|
+
diagnosticErrorText = text2;
|
|
51463
|
+
}
|
|
51464
|
+
} else {
|
|
51465
|
+
diagnosticErrorText = text2;
|
|
51466
|
+
}
|
|
51467
|
+
const safeProjectId = maskSensitiveIdentifier(projectId) || "Unknown";
|
|
51468
|
+
const debugInfo = `
|
|
50964
51469
|
|
|
50965
51470
|
[Debug Info]
|
|
50966
51471
|
Requested Model: ${requestedModel || "Unknown"}
|
|
@@ -50971,48 +51476,91 @@ Status: ${response.status}
|
|
|
50971
51476
|
Request ID: ${headers.get("x-request-id") || "N/A"}${toolDebugMissing !== void 0 ? `
|
|
50972
51477
|
Tool Debug Missing: ${toolDebugMissing}` : ""}${toolDebugSummary ? `
|
|
50973
51478
|
Tool Debug Summary: ${toolDebugSummary}` : ""}`;
|
|
50974
|
-
|
|
51479
|
+
const injectedDebug = debugText ? `
|
|
50975
51480
|
|
|
50976
51481
|
${debugText}` : "";
|
|
50977
|
-
|
|
50978
|
-
|
|
50979
|
-
|
|
50980
|
-
|
|
50981
|
-
|
|
50982
|
-
|
|
50983
|
-
|
|
50984
|
-
|
|
50985
|
-
|
|
50986
|
-
|
|
50987
|
-
|
|
50988
|
-
|
|
50989
|
-
|
|
50990
|
-
|
|
50991
|
-
|
|
50992
|
-
|
|
51482
|
+
const safeDiagnosticText = redactProjectIdText(
|
|
51483
|
+
diagnosticErrorText,
|
|
51484
|
+
projectIds
|
|
51485
|
+
);
|
|
51486
|
+
const errorType = detectErrorType(safeDiagnosticText);
|
|
51487
|
+
if (errorType === "thinking_block_order") {
|
|
51488
|
+
const recoveryError = new Error("THINKING_RECOVERY_NEEDED");
|
|
51489
|
+
recoveryError.recoveryType = errorType;
|
|
51490
|
+
recoveryError.originalError = parsedBody ?? safeDiagnosticText;
|
|
51491
|
+
recoveryError.debugInfo = debugInfo;
|
|
51492
|
+
throw recoveryError;
|
|
51493
|
+
}
|
|
51494
|
+
const errorMessageLower = safeDiagnosticText.toLowerCase();
|
|
51495
|
+
if (errorMessageLower.includes("prompt is too long") || errorMessageLower.includes("context length exceeded") || errorMessageLower.includes("context_length_exceeded") || errorMessageLower.includes("maximum context length")) {
|
|
51496
|
+
headers.set("x-antigravity-context-error", "prompt_too_long");
|
|
51497
|
+
}
|
|
51498
|
+
if (errorMessageLower.includes("tool_use") && errorMessageLower.includes("tool_result") && (errorMessageLower.includes("without") || errorMessageLower.includes("immediately after"))) {
|
|
51499
|
+
headers.set("x-antigravity-context-error", "tool_pairing");
|
|
51500
|
+
}
|
|
51501
|
+
if (!isJson && !isEventStreamResponse) {
|
|
51502
|
+
return await createSafeFallback(text2);
|
|
51503
|
+
}
|
|
51504
|
+
if (!isJson) {
|
|
51505
|
+
return await createSafeFallback(text2);
|
|
51506
|
+
}
|
|
51507
|
+
if (errorRecord !== null) {
|
|
51508
|
+
const upstreamErrorMessage = typeof errorRecord.message === "string" && errorRecord.message.length > 0 ? errorRecord.message : "Unknown error";
|
|
51509
|
+
const rawErrorMessage = redactProjectIdText(
|
|
51510
|
+
upstreamErrorMessage,
|
|
51511
|
+
projectIds
|
|
51512
|
+
);
|
|
51513
|
+
const isQuota = isQuotaError(
|
|
51514
|
+
response.status,
|
|
51515
|
+
upstreamErrorMessage,
|
|
51516
|
+
errorRecord.details
|
|
51517
|
+
);
|
|
51518
|
+
const normalizedErrorMessage = isQuota ? normalizeResetDuration(rawErrorMessage) : rawErrorMessage;
|
|
51519
|
+
errorRecord.message = normalizedErrorMessage + debugInfo + injectedDebug;
|
|
51520
|
+
const responseHeaders2 = new Headers(headers);
|
|
51521
|
+
responseHeaders2.delete("content-length");
|
|
51522
|
+
responseHeaders2.set("content-type", "application/json");
|
|
51523
|
+
const finalBody2 = JSON.stringify(parsedBody);
|
|
51524
|
+
const finalResponse2 = new Response(finalBody2, {
|
|
50993
51525
|
status: response.status,
|
|
50994
51526
|
statusText: response.statusText,
|
|
50995
|
-
headers
|
|
51527
|
+
headers: responseHeaders2
|
|
50996
51528
|
});
|
|
50997
|
-
|
|
50998
|
-
|
|
50999
|
-
|
|
51000
|
-
|
|
51529
|
+
return await redactCredentialResponse(
|
|
51530
|
+
finalResponse2,
|
|
51531
|
+
void 0,
|
|
51532
|
+
finalBody2,
|
|
51533
|
+
projectIds
|
|
51001
51534
|
);
|
|
51002
|
-
if (retryInfo?.retryDelay) {
|
|
51003
|
-
const match = retryInfo.retryDelay.match(/^([\d.]+)s$/);
|
|
51004
|
-
if (match?.[1]) {
|
|
51005
|
-
const retrySeconds = parseFloat(match[1]);
|
|
51006
|
-
if (!Number.isNaN(retrySeconds) && retrySeconds > 0) {
|
|
51007
|
-
const retryAfterSec = Math.ceil(retrySeconds).toString();
|
|
51008
|
-
const retryAfterMs = Math.ceil(retrySeconds * 1e3).toString();
|
|
51009
|
-
headers.set("Retry-After", retryAfterSec);
|
|
51010
|
-
headers.set("retry-after-ms", retryAfterMs);
|
|
51011
|
-
}
|
|
51012
|
-
}
|
|
51013
|
-
}
|
|
51014
51535
|
}
|
|
51536
|
+
const responseHeaders = new Headers(headers);
|
|
51537
|
+
responseHeaders.delete("content-length");
|
|
51538
|
+
responseHeaders.set("content-type", "application/json");
|
|
51539
|
+
const finalBody = JSON.stringify(parsedBody);
|
|
51540
|
+
const finalResponse = new Response(finalBody, {
|
|
51541
|
+
status: response.status,
|
|
51542
|
+
statusText: response.statusText,
|
|
51543
|
+
headers: responseHeaders
|
|
51544
|
+
});
|
|
51545
|
+
return await redactCredentialResponse(
|
|
51546
|
+
finalResponse,
|
|
51547
|
+
void 0,
|
|
51548
|
+
finalBody,
|
|
51549
|
+
projectIds
|
|
51550
|
+
);
|
|
51551
|
+
} catch (transformError) {
|
|
51552
|
+
if (transformError instanceof Error && transformError.message === "THINKING_RECOVERY_NEEDED") {
|
|
51553
|
+
throw transformError;
|
|
51554
|
+
}
|
|
51555
|
+
return await createSafeFallback(text2);
|
|
51015
51556
|
}
|
|
51557
|
+
}
|
|
51558
|
+
const responseFallback = response.clone();
|
|
51559
|
+
try {
|
|
51560
|
+
const headers = new Headers(response.headers);
|
|
51561
|
+
const text2 = await response.text();
|
|
51562
|
+
noteGeminiDumpResponse(dumpContext, response);
|
|
51563
|
+
appendGeminiDumpResponseText(dumpContext, text2);
|
|
51016
51564
|
const init = {
|
|
51017
51565
|
status: response.status,
|
|
51018
51566
|
statusText: response.statusText,
|
|
@@ -52238,7 +52786,7 @@ var BackgroundVaultQuotaRefresh = class {
|
|
|
52238
52786
|
outcome.stage = "roster";
|
|
52239
52787
|
const { source, pool } = await this.options.currentVaultPool();
|
|
52240
52788
|
await this.assertActive(controller);
|
|
52241
|
-
await pool.sync();
|
|
52789
|
+
await pool.sync(controller.signal);
|
|
52242
52790
|
await this.assertActive(controller);
|
|
52243
52791
|
outcome.stage = "state";
|
|
52244
52792
|
const state = await this.options.readProviderState();
|
|
@@ -54108,23 +54656,6 @@ function createNoAccountResponse(message, model) {
|
|
|
54108
54656
|
function terminalFetchError(lastError, fallbackMessage) {
|
|
54109
54657
|
return lastError ?? new Error(fallbackMessage);
|
|
54110
54658
|
}
|
|
54111
|
-
function retryAfterMsFromResponse(response, defaultRetryMs = 6e4) {
|
|
54112
|
-
const retryAfterMsHeader = response.headers.get("retry-after-ms");
|
|
54113
|
-
if (retryAfterMsHeader) {
|
|
54114
|
-
const parsed = Number.parseInt(retryAfterMsHeader, 10);
|
|
54115
|
-
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
54116
|
-
return parsed;
|
|
54117
|
-
}
|
|
54118
|
-
}
|
|
54119
|
-
const retryAfterHeader = response.headers.get("retry-after");
|
|
54120
|
-
if (retryAfterHeader) {
|
|
54121
|
-
const parsed = Number.parseInt(retryAfterHeader, 10);
|
|
54122
|
-
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
54123
|
-
return parsed * 1e3;
|
|
54124
|
-
}
|
|
54125
|
-
}
|
|
54126
|
-
return defaultRetryMs;
|
|
54127
|
-
}
|
|
54128
54659
|
function formatWaitTime(ms) {
|
|
54129
54660
|
if (ms < 1e3) return `${ms}ms`;
|
|
54130
54661
|
const seconds = Math.ceil(ms / 1e3);
|
|
@@ -54146,10 +54677,11 @@ function sleep4(ms, signal) {
|
|
|
54146
54677
|
);
|
|
54147
54678
|
return;
|
|
54148
54679
|
}
|
|
54680
|
+
const timerMs = Math.min(Math.max(0, Math.floor(ms)), 2147483647);
|
|
54149
54681
|
const timeout = setTimeout(() => {
|
|
54150
54682
|
cleanup2();
|
|
54151
54683
|
resolve27();
|
|
54152
|
-
},
|
|
54684
|
+
}, timerMs);
|
|
54153
54685
|
const onAbort = () => {
|
|
54154
54686
|
cleanup2();
|
|
54155
54687
|
reject(
|
|
@@ -54244,7 +54776,7 @@ function createRequestExecutor(deps) {
|
|
|
54244
54776
|
};
|
|
54245
54777
|
async function execute(input2, init, options, selectedCredentials, selectedProjectIds, deadline, waitPolicy) {
|
|
54246
54778
|
const assertAdmission = async () => {
|
|
54247
|
-
await deadline.wait(() => deps.assertAdmission?.());
|
|
54779
|
+
await deadline.wait(() => deps.assertAdmission?.(deadline.signal));
|
|
54248
54780
|
};
|
|
54249
54781
|
const logResponseBody2 = (...args) => deadline.wait(() => debug.logResponseBody(...args));
|
|
54250
54782
|
await assertAdmission();
|
|
@@ -55256,10 +55788,6 @@ function createRequestExecutor(deps) {
|
|
|
55256
55788
|
}
|
|
55257
55789
|
const defaultRetryMs = (config.default_retry_after_seconds ?? 60) * 1e3;
|
|
55258
55790
|
const _maxBackoffMs = (config.max_backoff_seconds ?? 60) * 1e3;
|
|
55259
|
-
const headerRetryMs = retryAfterMsFromResponse(
|
|
55260
|
-
response,
|
|
55261
|
-
defaultRetryMs
|
|
55262
|
-
);
|
|
55263
55791
|
const bodyInfo = await (async () => {
|
|
55264
55792
|
try {
|
|
55265
55793
|
const text2 = await deadline.wait(
|
|
@@ -55275,8 +55803,12 @@ function createRequestExecutor(deps) {
|
|
|
55275
55803
|
return null;
|
|
55276
55804
|
}
|
|
55277
55805
|
})();
|
|
55278
|
-
const reasonInfo =
|
|
55279
|
-
|
|
55806
|
+
const reasonInfo = extractRateLimitBodyInfo(
|
|
55807
|
+
bodyInfo,
|
|
55808
|
+
response.status,
|
|
55809
|
+
response.headers
|
|
55810
|
+
);
|
|
55811
|
+
const serverRetryMs = reasonInfo.retryDelayMs ?? defaultRetryMs;
|
|
55280
55812
|
const rateLimitReason = parseRateLimitReason(
|
|
55281
55813
|
reasonInfo.reason,
|
|
55282
55814
|
reasonInfo.message,
|
|
@@ -56043,15 +56575,15 @@ function parseModelUnavailableError(bodyText) {
|
|
|
56043
56575
|
}
|
|
56044
56576
|
return { status: "NOT_FOUND", reasons };
|
|
56045
56577
|
}
|
|
56046
|
-
function extractRateLimitBodyInfo(body) {
|
|
56047
|
-
|
|
56048
|
-
const
|
|
56049
|
-
const
|
|
56050
|
-
const details = error && typeof error === "object" ? error.details : void 0;
|
|
56578
|
+
function extractRateLimitBodyInfo(body, status, headers) {
|
|
56579
|
+
const errorRecord = extractAntigravityError(body);
|
|
56580
|
+
const message = errorRecord && typeof errorRecord.message === "string" ? errorRecord.message : void 0;
|
|
56581
|
+
const details = errorRecord && Array.isArray(errorRecord.details) ? errorRecord.details : void 0;
|
|
56051
56582
|
let reason;
|
|
56052
56583
|
if (Array.isArray(details)) {
|
|
56053
56584
|
for (const detail of details) {
|
|
56054
|
-
if (!detail || typeof detail !== "object")
|
|
56585
|
+
if (!detail || typeof detail !== "object" || Array.isArray(detail))
|
|
56586
|
+
continue;
|
|
56055
56587
|
const type = detail["@type"];
|
|
56056
56588
|
if (typeof type === "string" && type.includes("google.rpc.ErrorInfo")) {
|
|
56057
56589
|
const detailReason = detail.reason;
|
|
@@ -56061,95 +56593,28 @@ function extractRateLimitBodyInfo(body) {
|
|
|
56061
56593
|
}
|
|
56062
56594
|
}
|
|
56063
56595
|
}
|
|
56064
|
-
for (const detail of details) {
|
|
56065
|
-
if (!detail || typeof detail !== "object") continue;
|
|
56066
|
-
const type = detail["@type"];
|
|
56067
|
-
if (typeof type === "string" && type.includes("google.rpc.RetryInfo")) {
|
|
56068
|
-
const retryDelay = detail.retryDelay;
|
|
56069
|
-
if (typeof retryDelay === "string") {
|
|
56070
|
-
const retryDelayMs = parseDurationToMs(retryDelay);
|
|
56071
|
-
if (retryDelayMs !== null) {
|
|
56072
|
-
return { retryDelayMs, message, reason };
|
|
56073
|
-
}
|
|
56074
|
-
}
|
|
56075
|
-
}
|
|
56076
|
-
}
|
|
56077
|
-
for (const detail of details) {
|
|
56078
|
-
if (!detail || typeof detail !== "object") continue;
|
|
56079
|
-
const metadata = detail.metadata;
|
|
56080
|
-
if (metadata && typeof metadata === "object") {
|
|
56081
|
-
const quotaResetDelay = metadata.quotaResetDelay;
|
|
56082
|
-
const quotaResetTime = metadata.quotaResetTimeStamp;
|
|
56083
|
-
if (typeof quotaResetDelay === "string") {
|
|
56084
|
-
const quotaResetDelayMs = parseDurationToMs(quotaResetDelay);
|
|
56085
|
-
if (quotaResetDelayMs !== null) {
|
|
56086
|
-
return {
|
|
56087
|
-
retryDelayMs: quotaResetDelayMs,
|
|
56088
|
-
message,
|
|
56089
|
-
quotaResetTime,
|
|
56090
|
-
reason
|
|
56091
|
-
};
|
|
56092
|
-
}
|
|
56093
|
-
}
|
|
56094
|
-
}
|
|
56095
|
-
}
|
|
56096
|
-
}
|
|
56097
|
-
if (message) {
|
|
56098
|
-
const reset = message.match(/(?:reset after|resets? in)\s+([0-9hms.]+)/i);
|
|
56099
|
-
const rawDuration = reset?.[1];
|
|
56100
|
-
if (rawDuration) {
|
|
56101
|
-
const parsed = parseDurationToMs(rawDuration);
|
|
56102
|
-
if (parsed !== null) {
|
|
56103
|
-
return { retryDelayMs: parsed, message, reason };
|
|
56104
|
-
}
|
|
56105
|
-
}
|
|
56106
|
-
}
|
|
56107
|
-
return { retryDelayMs: null, message, reason };
|
|
56108
|
-
}
|
|
56109
|
-
function parseDurationToMs(duration) {
|
|
56110
|
-
const simpleMatch = duration.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/i);
|
|
56111
|
-
if (simpleMatch) {
|
|
56112
|
-
const value = parseFloat(simpleMatch[1]);
|
|
56113
|
-
const unit = (simpleMatch[2] || "s").toLowerCase();
|
|
56114
|
-
switch (unit) {
|
|
56115
|
-
case "h":
|
|
56116
|
-
return value * 3600 * 1e3;
|
|
56117
|
-
case "m":
|
|
56118
|
-
return value * 60 * 1e3;
|
|
56119
|
-
case "s":
|
|
56120
|
-
return value * 1e3;
|
|
56121
|
-
case "ms":
|
|
56122
|
-
return value;
|
|
56123
|
-
default:
|
|
56124
|
-
return value * 1e3;
|
|
56125
|
-
}
|
|
56126
56596
|
}
|
|
56127
|
-
const
|
|
56128
|
-
|
|
56129
|
-
|
|
56130
|
-
|
|
56131
|
-
|
|
56132
|
-
|
|
56133
|
-
|
|
56134
|
-
|
|
56135
|
-
|
|
56136
|
-
|
|
56137
|
-
|
|
56138
|
-
|
|
56139
|
-
|
|
56140
|
-
|
|
56141
|
-
|
|
56142
|
-
|
|
56143
|
-
|
|
56144
|
-
|
|
56145
|
-
|
|
56146
|
-
|
|
56147
|
-
|
|
56148
|
-
totalMs += value;
|
|
56149
|
-
break;
|
|
56150
|
-
}
|
|
56151
|
-
}
|
|
56152
|
-
return matchFound ? totalMs : null;
|
|
56597
|
+
const resolved = resolveRetryMetadata({
|
|
56598
|
+
details,
|
|
56599
|
+
message,
|
|
56600
|
+
status,
|
|
56601
|
+
headers,
|
|
56602
|
+
// The executor keeps its historical reading of Google's body fields: an
|
|
56603
|
+
// upstream zero ("0s") falls through to the configured default retry
|
|
56604
|
+
// instead of retrying immediately, and a unitless delay such as "90"
|
|
56605
|
+
// still means 90 seconds.
|
|
56606
|
+
allowZero: false,
|
|
56607
|
+
allowBareSeconds: true
|
|
56608
|
+
});
|
|
56609
|
+
const retryDelayMs = resolved !== null ? Number(
|
|
56610
|
+
resolved.delayMs > BigInt(Number.MAX_SAFE_INTEGER) ? BigInt(Number.MAX_SAFE_INTEGER) : resolved.delayMs
|
|
56611
|
+
) : null;
|
|
56612
|
+
return {
|
|
56613
|
+
retryDelayMs,
|
|
56614
|
+
message,
|
|
56615
|
+
quotaResetTime: resolved?.quotaResetTime,
|
|
56616
|
+
reason
|
|
56617
|
+
};
|
|
56153
56618
|
}
|
|
56154
56619
|
|
|
56155
56620
|
// src/plugin/fetch-interceptor.ts
|
|
@@ -56342,7 +56807,10 @@ function createVaultFetchInterceptor(context) {
|
|
|
56342
56807
|
const pool = context.pool ?? createVaultAccountPool({ source });
|
|
56343
56808
|
const selector = pool.selector;
|
|
56344
56809
|
const executor = createRequestExecutor({
|
|
56345
|
-
assertAdmission:
|
|
56810
|
+
assertAdmission: async (signal) => {
|
|
56811
|
+
await context.assertAdmission?.();
|
|
56812
|
+
await pool.sync(signal);
|
|
56813
|
+
},
|
|
56346
56814
|
...openCode1EngineCollaborators({
|
|
56347
56815
|
...context,
|
|
56348
56816
|
transport: agyTransport
|
|
@@ -56359,7 +56827,6 @@ function createVaultFetchInterceptor(context) {
|
|
|
56359
56827
|
async function fetch(input2, init) {
|
|
56360
56828
|
if (!isGenerativeLanguageRequest(input2)) return upstreamFetch(input2, init);
|
|
56361
56829
|
if (disposed) throw new Error("The vault request runtime is disposed");
|
|
56362
|
-
await pool.sync();
|
|
56363
56830
|
return executor.execute(input2, init);
|
|
56364
56831
|
}
|
|
56365
56832
|
function dispose() {
|
|
@@ -56841,7 +57308,8 @@ function createVaultAccountMenuSections(pool, selectorOf, checkQuota) {
|
|
|
56841
57308
|
return {
|
|
56842
57309
|
accounts: {
|
|
56843
57310
|
title: "Accounts",
|
|
56844
|
-
build: () => {
|
|
57311
|
+
build: async () => {
|
|
57312
|
+
await pool.syncForDisplay();
|
|
56845
57313
|
const rows = pool.selector.rows;
|
|
56846
57314
|
return {
|
|
56847
57315
|
lines: [
|
|
@@ -56857,7 +57325,8 @@ function createVaultAccountMenuSections(pool, selectorOf, checkQuota) {
|
|
|
56857
57325
|
},
|
|
56858
57326
|
quota: {
|
|
56859
57327
|
title: "Quota",
|
|
56860
|
-
build: () => {
|
|
57328
|
+
build: async () => {
|
|
57329
|
+
await pool.syncForDisplay();
|
|
56861
57330
|
const rows = pool.selector.rows;
|
|
56862
57331
|
return {
|
|
56863
57332
|
lines: rows.length === 0 ? [] : rows.map(
|
|
@@ -57071,7 +57540,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
57071
57540
|
},
|
|
57072
57541
|
vault: async () => {
|
|
57073
57542
|
const { pool } = await currentVaultPool();
|
|
57074
|
-
await pool.
|
|
57543
|
+
await pool.syncCached();
|
|
57075
57544
|
const projection = buildVaultSidebarProjection(
|
|
57076
57545
|
pool,
|
|
57077
57546
|
await vaultCustody.readState(),
|
|
@@ -57273,7 +57742,7 @@ var createAntigravityPlugin = (providerId, options = {}) => async (input2) => {
|
|
|
57273
57742
|
let current;
|
|
57274
57743
|
try {
|
|
57275
57744
|
current = await currentVaultPool();
|
|
57276
|
-
await current.pool.
|
|
57745
|
+
await current.pool.syncForDisplay();
|
|
57277
57746
|
} catch {
|
|
57278
57747
|
return showUnavailableVaultMenu();
|
|
57279
57748
|
}
|