mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
fix provider thinking compatibility
- claude: handle DeepSeek thinking blocks defensively, unsigned placeholder; fix kept-vs-seen thinking detection - gemini: clamp unsupported max/xhigh thinking levels to high - testUtils: probe Cloud Code Assist for gemini-cli/antigravity with 401 refresh retry - tests: add translator regression coverage Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
decolua
co-authored by
Cursor
parent
cb65a45e1f
commit
c4f80d30d8
@@ -104,6 +104,53 @@ async function probeClineAccessToken(accessToken) {
|
||||
return res;
|
||||
}
|
||||
|
||||
const CLOUD_CODE_ASSIST_TEST_URL = "https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist";
|
||||
const CLOUD_CODE_ASSIST_TEST_BODY = JSON.stringify({
|
||||
metadata: {
|
||||
ideType: "IDE_UNSPECIFIED",
|
||||
platform: "PLATFORM_UNSPECIFIED",
|
||||
pluginType: "GEMINI",
|
||||
},
|
||||
});
|
||||
|
||||
function parseProviderErrorMessage(bodyText, fallback) {
|
||||
if (!bodyText) return fallback;
|
||||
try {
|
||||
const parsed = JSON.parse(bodyText);
|
||||
const message = parsed?.error?.message || parsed?.message || parsed?.error;
|
||||
if (typeof message === "string" && message.trim()) return message.trim();
|
||||
if (message) return JSON.stringify(message);
|
||||
} catch {
|
||||
// fall through
|
||||
}
|
||||
return bodyText.trim() || fallback;
|
||||
}
|
||||
|
||||
async function probeCloudCodeAssistAccess(connection, accessToken, effectiveProxy = null) {
|
||||
const userAgent = connection.provider === "antigravity"
|
||||
? "google-api-nodejs-client/9.15.1 vscode-antigravity/1.107.0"
|
||||
: "google-api-nodejs-client/9.15.1 gemini-cli/0.34.0";
|
||||
|
||||
const res = await fetchWithConnectionProxy(CLOUD_CODE_ASSIST_TEST_URL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Authorization": `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": userAgent,
|
||||
},
|
||||
body: CLOUD_CODE_ASSIST_TEST_BODY,
|
||||
}, effectiveProxy);
|
||||
|
||||
if (res.ok) return { valid: true, error: null };
|
||||
|
||||
const bodyText = await res.text().catch(() => "");
|
||||
return {
|
||||
valid: false,
|
||||
error: parseProviderErrorMessage(bodyText, `API returned ${res.status}`),
|
||||
status: res.status,
|
||||
};
|
||||
}
|
||||
|
||||
async function refreshOAuthToken(connection) {
|
||||
const provider = connection.provider;
|
||||
const refreshToken = connection.refreshToken;
|
||||
@@ -253,6 +300,23 @@ async function testOAuthConnection(connection, effectiveProxy = null) {
|
||||
return { valid: true, error: null, refreshed: false, newTokens: null };
|
||||
}
|
||||
|
||||
if (connection.provider === "gemini-cli" || connection.provider === "antigravity") {
|
||||
const initial = await probeCloudCodeAssistAccess(connection, accessToken, effectiveProxy);
|
||||
if (initial.valid) return { valid: true, error: null, refreshed, newTokens };
|
||||
|
||||
if (initial.status === 401 && config.refreshable && !refreshed && connection.refreshToken) {
|
||||
const tokens = await refreshOAuthToken(connection);
|
||||
if (tokens?.accessToken) {
|
||||
const retry = await probeCloudCodeAssistAccess(connection, tokens.accessToken, effectiveProxy);
|
||||
if (retry.valid) return { valid: true, error: null, refreshed: true, newTokens: tokens };
|
||||
return { valid: false, error: retry.error, refreshed: true, newTokens: tokens };
|
||||
}
|
||||
return { valid: false, error: "Token invalid or revoked", refreshed: false };
|
||||
}
|
||||
|
||||
return { valid: false, error: initial.error, refreshed };
|
||||
}
|
||||
|
||||
if (connection.provider === "cline") {
|
||||
const tryProbe = async (token) => {
|
||||
const res = await probeClineAccessToken(token);
|
||||
|
||||
Reference in New Issue
Block a user