antigravity-claude-proxy 2.7.5 → 2.7.6
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/package.json
CHANGED
|
@@ -157,7 +157,7 @@ export async function sendMessage(anthropicRequest, accountManager, fallbackEnab
|
|
|
157
157
|
|
|
158
158
|
const response = await throttledFetch(url, {
|
|
159
159
|
method: 'POST',
|
|
160
|
-
headers: buildHeaders(token, model, isThinking ? 'text/event-stream' : 'application/json'),
|
|
160
|
+
headers: buildHeaders(token, model, isThinking ? 'text/event-stream' : 'application/json', payload.request.sessionId),
|
|
161
161
|
body: JSON.stringify(payload)
|
|
162
162
|
});
|
|
163
163
|
|
|
@@ -70,15 +70,21 @@ export function buildCloudCodeRequest(anthropicRequest, projectId, accountEmail)
|
|
|
70
70
|
* @param {string} token - OAuth access token
|
|
71
71
|
* @param {string} model - Model name
|
|
72
72
|
* @param {string} accept - Accept header value (default: 'application/json')
|
|
73
|
+
* @param {string} [sessionId] - Optional session ID for X-Machine-Session-Id header
|
|
73
74
|
* @returns {Object} Headers object
|
|
74
75
|
*/
|
|
75
|
-
export function buildHeaders(token, model, accept = 'application/json') {
|
|
76
|
+
export function buildHeaders(token, model, accept = 'application/json', sessionId) {
|
|
76
77
|
const headers = {
|
|
77
78
|
'Authorization': `Bearer ${token}`,
|
|
78
79
|
'Content-Type': 'application/json',
|
|
79
80
|
...ANTIGRAVITY_HEADERS
|
|
80
81
|
};
|
|
81
82
|
|
|
83
|
+
// Add session ID header if provided (matches Antigravity binary behavior)
|
|
84
|
+
if (sessionId) {
|
|
85
|
+
headers['X-Machine-Session-Id'] = sessionId;
|
|
86
|
+
}
|
|
87
|
+
|
|
82
88
|
const modelFamily = getModelFamily(model);
|
|
83
89
|
|
|
84
90
|
// Add interleaved thinking header only for Claude thinking models
|
|
@@ -155,7 +155,7 @@ export async function* sendMessageStream(anthropicRequest, accountManager, fallb
|
|
|
155
155
|
|
|
156
156
|
const response = await throttledFetch(url, {
|
|
157
157
|
method: 'POST',
|
|
158
|
-
headers: buildHeaders(token, model, 'text/event-stream'),
|
|
158
|
+
headers: buildHeaders(token, model, 'text/event-stream', payload.request.sessionId),
|
|
159
159
|
body: JSON.stringify(payload)
|
|
160
160
|
});
|
|
161
161
|
|
|
@@ -336,7 +336,7 @@ export async function* sendMessageStream(anthropicRequest, accountManager, fallb
|
|
|
336
336
|
// Refetch the response
|
|
337
337
|
currentResponse = await throttledFetch(url, {
|
|
338
338
|
method: 'POST',
|
|
339
|
-
headers: buildHeaders(token, model, 'text/event-stream'),
|
|
339
|
+
headers: buildHeaders(token, model, 'text/event-stream', payload.request.sessionId),
|
|
340
340
|
body: JSON.stringify(payload)
|
|
341
341
|
});
|
|
342
342
|
|
package/src/constants.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { homedir, platform, arch } from 'os';
|
|
7
7
|
import { join } from 'path';
|
|
8
8
|
import { config } from './config.js';
|
|
9
|
+
import { generateSmartUserAgent } from './utils/version-detector.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Get the Antigravity database path based on the current platform.
|
|
@@ -31,9 +32,7 @@ function getAntigravityDbPath() {
|
|
|
31
32
|
* @returns {string} User-Agent in format "antigravity/version os/arch"
|
|
32
33
|
*/
|
|
33
34
|
export function getPlatformUserAgent() {
|
|
34
|
-
|
|
35
|
-
const architecture = arch();
|
|
36
|
-
return `antigravity/1.16.5 ${os}/${architecture}`;
|
|
35
|
+
return generateSmartUserAgent();
|
|
37
36
|
}
|
|
38
37
|
|
|
39
38
|
// IDE Type enum (numeric values as expected by Cloud Code API)
|
|
@@ -103,7 +102,10 @@ export const ANTIGRAVITY_ENDPOINT_FALLBACKS = [
|
|
|
103
102
|
// Strictly matches the generic 'u' method in main.js
|
|
104
103
|
export const ANTIGRAVITY_HEADERS = {
|
|
105
104
|
'User-Agent': getPlatformUserAgent(),
|
|
106
|
-
'Content-Type': 'application/json'
|
|
105
|
+
'Content-Type': 'application/json',
|
|
106
|
+
'X-Client-Name': 'antigravity',
|
|
107
|
+
'X-Client-Version': '1.107.0', // Match product.json version
|
|
108
|
+
'x-goog-api-client': 'gl-node/18.18.2 fire/0.8.6 grpc/1.10.x' // Simulate Google Node.js client environment
|
|
107
109
|
};
|
|
108
110
|
|
|
109
111
|
// Endpoint order for loadCodeAssist (prod first)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
import { platform, homedir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { existsSync } from 'fs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Intelligent Version Detection for Antigravity
|
|
8
|
+
* Attempts to find the local installation and extract its version.
|
|
9
|
+
* Falls back to hard-coded stable versions if detection fails.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Fallback constant
|
|
13
|
+
const FALLBACK_ANTIGRAVITY_VERSION = '1.16.5';
|
|
14
|
+
|
|
15
|
+
// Cache for the generated User-Agent string
|
|
16
|
+
let cachedUserAgent = null;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Compares two semver-ish version strings (X.Y.Z).
|
|
20
|
+
* @param {string} v1 - Version string 1
|
|
21
|
+
* @param {string} v2 - Version string 2
|
|
22
|
+
* @returns {boolean} True if v1 > v2
|
|
23
|
+
*/
|
|
24
|
+
function isVersionHigher(v1, v2) {
|
|
25
|
+
const parts1 = v1.split('.').map(Number);
|
|
26
|
+
const parts2 = v2.split('.').map(Number);
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) {
|
|
29
|
+
const p1 = parts1[i] || 0;
|
|
30
|
+
const p2 = parts2[i] || 0;
|
|
31
|
+
if (p1 > p2) return true;
|
|
32
|
+
if (p1 < p2) return false;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Gets the version config (version, source)
|
|
39
|
+
* @returns {{ version: string, source: string }}
|
|
40
|
+
*/
|
|
41
|
+
function getVersionConfig() {
|
|
42
|
+
const os = platform();
|
|
43
|
+
let detectedVersion = null;
|
|
44
|
+
let finalVersion = FALLBACK_ANTIGRAVITY_VERSION;
|
|
45
|
+
let source = 'fallback';
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
if (os === 'darwin') {
|
|
49
|
+
detectedVersion = getVersionMacos();
|
|
50
|
+
} else if (os === 'win32') {
|
|
51
|
+
detectedVersion = getVersionWindows();
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
// Silently fail and use fallback
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Only use detected version if it's higher than the fallback version
|
|
58
|
+
if (detectedVersion && isVersionHigher(detectedVersion, FALLBACK_ANTIGRAVITY_VERSION)) {
|
|
59
|
+
finalVersion = detectedVersion;
|
|
60
|
+
source = 'local';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
version: finalVersion,
|
|
65
|
+
source
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Generate a simplified User-Agent string used by the Antigravity binary.
|
|
71
|
+
* Format: "antigravity/version os/arch"
|
|
72
|
+
* @returns {string} The User-Agent string
|
|
73
|
+
*/
|
|
74
|
+
export function generateSmartUserAgent() {
|
|
75
|
+
if (cachedUserAgent) return cachedUserAgent;
|
|
76
|
+
|
|
77
|
+
const { version } = getVersionConfig();
|
|
78
|
+
const os = platform();
|
|
79
|
+
const architecture = process.arch;
|
|
80
|
+
|
|
81
|
+
// Map Node.js platform names to binary-friendly names
|
|
82
|
+
const osName = os === 'darwin' ? 'darwin' : (os === 'win32' ? 'win32' : 'linux');
|
|
83
|
+
|
|
84
|
+
cachedUserAgent = `antigravity/${version} ${osName}/${architecture}`;
|
|
85
|
+
return cachedUserAgent;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* MacOS-specific version detection using plutil
|
|
90
|
+
*/
|
|
91
|
+
function getVersionMacos() {
|
|
92
|
+
const appPath = '/Applications/Antigravity.app';
|
|
93
|
+
const plistPath = join(appPath, 'Contents/Info.plist');
|
|
94
|
+
|
|
95
|
+
if (!existsSync(plistPath)) return null;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const version = execSync(`plutil -extract CFBundleShortVersionString raw "${plistPath}"`, { encoding: 'utf8' }).trim();
|
|
99
|
+
if (/^\d+\.\d+\.\d+/.test(version)) {
|
|
100
|
+
return version;
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {
|
|
103
|
+
// plutil failed or file not found
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Windows-specific version detection using PowerShell
|
|
110
|
+
*/
|
|
111
|
+
function getVersionWindows() {
|
|
112
|
+
try {
|
|
113
|
+
const localAppData = process.env.LOCALAPPDATA;
|
|
114
|
+
const programFiles = process.env.ProgramFiles || 'C:\\Program Files';
|
|
115
|
+
|
|
116
|
+
const possiblePaths = [
|
|
117
|
+
join(localAppData, 'Programs', 'Antigravity', 'Antigravity.exe'),
|
|
118
|
+
join(programFiles, 'Antigravity', 'Antigravity.exe')
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
for (const exePath of possiblePaths) {
|
|
122
|
+
if (existsSync(exePath)) {
|
|
123
|
+
const cmd = `powershell -Command "(Get-Item '${exePath}').VersionInfo.FileVersion"`;
|
|
124
|
+
const version = execSync(cmd, { encoding: 'utf8' }).trim();
|
|
125
|
+
const match = version.match(/^(\d+\.\d+\.\d+)/);
|
|
126
|
+
if (match) return match[1];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
// PowerShell or path issues
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|