mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 13:38:31 +00:00
Fix Antigravity OAuth
This commit is contained in:
@@ -94,7 +94,7 @@ export const CLIENT_METADATA = {
|
|||||||
// Internal anti-loop header to identify requests originating from this proxy
|
// Internal anti-loop header to identify requests originating from this proxy
|
||||||
export const INTERNAL_REQUEST_HEADER = { name: "x-request-source", value: "local" };
|
export const INTERNAL_REQUEST_HEADER = { name: "x-request-source", value: "local" };
|
||||||
|
|
||||||
// Antigravity headers
|
// Antigravity headers (for chat/stream requests)
|
||||||
export const ANTIGRAVITY_HEADERS = {
|
export const ANTIGRAVITY_HEADERS = {
|
||||||
"X-Client-Name": "antigravity",
|
"X-Client-Name": "antigravity",
|
||||||
"X-Client-Version": "1.107.0",
|
"X-Client-Version": "1.107.0",
|
||||||
@@ -108,6 +108,21 @@ export const CLOUD_CODE_API = {
|
|||||||
onboardUser: "https://cloudcode-pa.googleapis.com/v1internal:onboardUser",
|
onboardUser: "https://cloudcode-pa.googleapis.com/v1internal:onboardUser",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Headers for loadCodeAssist / onboardUser API calls (matches CLIProxyAPI Go source)
|
||||||
|
export const LOAD_CODE_ASSIST_HEADERS = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"User-Agent": "google-api-nodejs-client/9.15.1",
|
||||||
|
"X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
||||||
|
"Client-Metadata": JSON.stringify({ ideType: "IDE_UNSPECIFIED", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" }),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Metadata body for loadCodeAssist / onboardUser (string enum, matches CLIProxyAPI Go source)
|
||||||
|
export const LOAD_CODE_ASSIST_METADATA = {
|
||||||
|
ideType: "IDE_UNSPECIFIED",
|
||||||
|
platform: "PLATFORM_UNSPECIFIED",
|
||||||
|
pluginType: "GEMINI",
|
||||||
|
};
|
||||||
|
|
||||||
// Provider configurations
|
// Provider configurations
|
||||||
export const PROVIDERS = {
|
export const PROVIDERS = {
|
||||||
claude: {
|
claude: {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
* This significantly reduces the risk of being flagged by Google's anti-abuse systems.
|
* This significantly reduces the risk of being flagged by Google's anti-abuse systems.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ANTIGRAVITY_HEADERS, CLIENT_METADATA, CLOUD_CODE_API, getPlatformUserAgent} from "../config/constants.js";
|
import {CLOUD_CODE_API, LOAD_CODE_ASSIST_HEADERS, LOAD_CODE_ASSIST_METADATA} from "../config/constants.js";
|
||||||
|
|
||||||
// ─── Cache ────────────────────────────────────────────────────────────────────
|
// ─── Cache ────────────────────────────────────────────────────────────────────
|
||||||
// connectionId -> { projectId: string, fetchedAt: number }
|
// connectionId -> { projectId: string, fetchedAt: number }
|
||||||
@@ -159,13 +159,8 @@ export function removeConnection(connectionId) {
|
|||||||
async function fetchProjectId(accessToken, signal) {
|
async function fetchProjectId(accessToken, signal) {
|
||||||
const response = await fetch(CLOUD_CODE_API.loadCodeAssist, {
|
const response = await fetch(CLOUD_CODE_API.loadCodeAssist, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { ...LOAD_CODE_ASSIST_HEADERS, "Authorization": `Bearer ${accessToken}` },
|
||||||
"Authorization": `Bearer ${accessToken}`,
|
body: JSON.stringify({ metadata: LOAD_CODE_ASSIST_METADATA }),
|
||||||
"Content-Type": "application/json",
|
|
||||||
"User-Agent": getPlatformUserAgent(),
|
|
||||||
...ANTIGRAVITY_HEADERS
|
|
||||||
},
|
|
||||||
body: JSON.stringify({metadata: CLIENT_METADATA, mode: 1}),
|
|
||||||
signal
|
signal
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -205,7 +200,7 @@ async function fetchProjectId(accessToken, signal) {
|
|||||||
async function onboardUser(accessToken, tierID, externalSignal) {
|
async function onboardUser(accessToken, tierID, externalSignal) {
|
||||||
console.log(`[ProjectId] Onboarding user with tier: ${tierID}`);
|
console.log(`[ProjectId] Onboarding user with tier: ${tierID}`);
|
||||||
|
|
||||||
const reqBody = {tierId: tierID, metadata: CLIENT_METADATA, mode: 1};
|
const reqBody = { tierId: tierID, metadata: LOAD_CODE_ASSIST_METADATA };
|
||||||
const MAX_ATTEMPTS = 5;
|
const MAX_ATTEMPTS = 5;
|
||||||
|
|
||||||
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
||||||
@@ -221,12 +216,7 @@ async function onboardUser(accessToken, tierID, externalSignal) {
|
|||||||
try {
|
try {
|
||||||
const response = await fetch(CLOUD_CODE_API.onboardUser, {
|
const response = await fetch(CLOUD_CODE_API.onboardUser, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: { ...LOAD_CODE_ASSIST_HEADERS, "Authorization": `Bearer ${accessToken}` },
|
||||||
"Authorization": `Bearer ${accessToken}`,
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"User-Agent": getPlatformUserAgent(),
|
|
||||||
...ANTIGRAVITY_HEADERS
|
|
||||||
},
|
|
||||||
body: JSON.stringify(reqBody),
|
body: JSON.stringify(reqBody),
|
||||||
signal: localCtrl.signal
|
signal: localCtrl.signal
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ export const ANTIGRAVITY_CONFIG = {
|
|||||||
onboardUserEndpoint: "https://cloudcode-pa.googleapis.com/v1internal:onboardUser",
|
onboardUserEndpoint: "https://cloudcode-pa.googleapis.com/v1internal:onboardUser",
|
||||||
loadCodeAssistUserAgent: "google-api-nodejs-client/9.15.1",
|
loadCodeAssistUserAgent: "google-api-nodejs-client/9.15.1",
|
||||||
loadCodeAssistApiClient: "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
loadCodeAssistApiClient: "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
||||||
loadCodeAssistClientMetadata: JSON.stringify({ ideType: 9, platform: getOAuthPlatformEnum(), pluginType: 2 }),
|
// String enum matches CLIProxyAPI Go source (internal/auth/antigravity/constants.go)
|
||||||
|
loadCodeAssistClientMetadata: JSON.stringify({ ideType: "IDE_UNSPECIFIED", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" }),
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+11
-12
@@ -20,7 +20,6 @@ import {
|
|||||||
KIMI_CODING_CONFIG,
|
KIMI_CODING_CONFIG,
|
||||||
KILOCODE_CONFIG,
|
KILOCODE_CONFIG,
|
||||||
CLINE_CONFIG,
|
CLINE_CONFIG,
|
||||||
getOAuthClientMetadata,
|
|
||||||
} from "./constants/oauth";
|
} from "./constants/oauth";
|
||||||
|
|
||||||
// Provider configurations
|
// Provider configurations
|
||||||
@@ -255,21 +254,22 @@ const PROVIDERS = {
|
|||||||
return await response.json();
|
return await response.json();
|
||||||
},
|
},
|
||||||
postExchange: async (tokens) => {
|
postExchange: async (tokens) => {
|
||||||
const headers = {
|
// Matches CLIProxyAPI Go source: string enum, no mode field
|
||||||
Authorization: `Bearer ${tokens.access_token}`,
|
const loadHeaders = {
|
||||||
|
"Authorization": `Bearer ${tokens.access_token}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"User-Agent": ANTIGRAVITY_CONFIG.loadCodeAssistUserAgent,
|
"User-Agent": ANTIGRAVITY_CONFIG.loadCodeAssistUserAgent,
|
||||||
"X-Goog-Api-Client": ANTIGRAVITY_CONFIG.loadCodeAssistApiClient,
|
"X-Goog-Api-Client": ANTIGRAVITY_CONFIG.loadCodeAssistApiClient,
|
||||||
"Client-Metadata": ANTIGRAVITY_CONFIG.loadCodeAssistClientMetadata,
|
"Client-Metadata": ANTIGRAVITY_CONFIG.loadCodeAssistClientMetadata,
|
||||||
"x-request-source": "local", // MITM passthrough marker
|
"x-request-source": "local",
|
||||||
};
|
};
|
||||||
const metadata = getOAuthClientMetadata();
|
const metadata = { ideType: "IDE_UNSPECIFIED", platform: "PLATFORM_UNSPECIFIED", pluginType: "GEMINI" };
|
||||||
|
|
||||||
// Fetch user info
|
// Fetch user info
|
||||||
const userInfoRes = await fetch(`${ANTIGRAVITY_CONFIG.userInfoUrl}?alt=json`, {
|
const userInfoRes = await fetch(`${ANTIGRAVITY_CONFIG.userInfoUrl}?alt=json`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${tokens.access_token}`,
|
Authorization: `Bearer ${tokens.access_token}`,
|
||||||
"x-request-source": "local", // MITM passthrough marker
|
"x-request-source": "local",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const userInfo = userInfoRes.ok ? await userInfoRes.json() : {};
|
const userInfo = userInfoRes.ok ? await userInfoRes.json() : {};
|
||||||
@@ -280,13 +280,12 @@ const PROVIDERS = {
|
|||||||
try {
|
try {
|
||||||
const loadRes = await fetch(ANTIGRAVITY_CONFIG.loadCodeAssistEndpoint, {
|
const loadRes = await fetch(ANTIGRAVITY_CONFIG.loadCodeAssistEndpoint, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers,
|
headers: loadHeaders,
|
||||||
body: JSON.stringify({ metadata, mode: 1 }),
|
body: JSON.stringify({ metadata }),
|
||||||
});
|
});
|
||||||
if (loadRes.ok) {
|
if (loadRes.ok) {
|
||||||
const data = await loadRes.json();
|
const data = await loadRes.json();
|
||||||
projectId = data.cloudaicompanionProject?.id || data.cloudaicompanionProject || "";
|
projectId = data.cloudaicompanionProject?.id || data.cloudaicompanionProject || "";
|
||||||
// Extract tier ID
|
|
||||||
if (Array.isArray(data.allowedTiers)) {
|
if (Array.isArray(data.allowedTiers)) {
|
||||||
for (const tier of data.allowedTiers) {
|
for (const tier of data.allowedTiers) {
|
||||||
if (tier.isDefault && tier.id) {
|
if (tier.isDefault && tier.id) {
|
||||||
@@ -307,8 +306,8 @@ const PROVIDERS = {
|
|||||||
try {
|
try {
|
||||||
const onboardRes = await fetch(ANTIGRAVITY_CONFIG.onboardUserEndpoint, {
|
const onboardRes = await fetch(ANTIGRAVITY_CONFIG.onboardUserEndpoint, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers,
|
headers: loadHeaders,
|
||||||
body: JSON.stringify({ tierId, metadata, cloudaicompanionProject: projectId, mode: 1 }),
|
body: JSON.stringify({ tierId, metadata }),
|
||||||
});
|
});
|
||||||
if (onboardRes.ok) {
|
if (onboardRes.ok) {
|
||||||
const result = await onboardRes.json();
|
const result = await onboardRes.json();
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { platform, arch } from "os";
|
|
||||||
import open from "open";
|
import open from "open";
|
||||||
import { ANTIGRAVITY_CONFIG } from "../constants/oauth.js";
|
import { ANTIGRAVITY_CONFIG } from "../constants/oauth.js";
|
||||||
import { getServerCredentials } from "../config/index.js";
|
import { getServerCredentials } from "../config/index.js";
|
||||||
@@ -92,21 +91,14 @@ export class AntigravityService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get metadata object for API calls
|
* Get metadata object for loadCodeAssist / onboardUser API calls.
|
||||||
* Uses numeric enum values matching Antigravity binary specifications
|
* Uses string enum values matching CLIProxyAPI Go source.
|
||||||
*/
|
*/
|
||||||
getMetadata() {
|
getMetadata() {
|
||||||
const os = platform();
|
|
||||||
const architecture = arch();
|
|
||||||
let platformEnum = 0; // UNSPECIFIED
|
|
||||||
if (os === "darwin") platformEnum = architecture === "arm64" ? 2 : 1;
|
|
||||||
else if (os === "linux") platformEnum = architecture === "arm64" ? 4 : 3;
|
|
||||||
else if (os === "win32") platformEnum = 5;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ideType: 9, // ANTIGRAVITY
|
ideType: "IDE_UNSPECIFIED",
|
||||||
platform: platformEnum,
|
platform: "PLATFORM_UNSPECIFIED",
|
||||||
pluginType: 2, // GEMINI
|
pluginType: "GEMINI",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +109,7 @@ export class AntigravityService {
|
|||||||
const response = await fetch(this.config.loadCodeAssistEndpoint, {
|
const response = await fetch(this.config.loadCodeAssistEndpoint, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.getApiHeaders(accessToken),
|
headers: this.getApiHeaders(accessToken),
|
||||||
body: JSON.stringify({ metadata: this.getMetadata(), mode: 1 }),
|
body: JSON.stringify({ metadata: this.getMetadata() }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -154,12 +146,7 @@ export class AntigravityService {
|
|||||||
const response = await fetch(this.config.onboardUserEndpoint, {
|
const response = await fetch(this.config.onboardUserEndpoint, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.getApiHeaders(accessToken),
|
headers: this.getApiHeaders(accessToken),
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({ tierId, metadata: this.getMetadata() }),
|
||||||
tierId,
|
|
||||||
metadata: this.getMetadata(),
|
|
||||||
cloudaicompanionProject: projectId,
|
|
||||||
mode: 1,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
Reference in New Issue
Block a user