antigravity-claude-proxy 2.7.3 → 2.7.5

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/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ # ⚠️ DO NOT USE THIS ANYMORE – GOOGLE IS ISSUING TOS VIOLATION BANS FOR THE ACCOUNTS CONNECTED
2
+
1
3
  # Antigravity Claude Proxy
2
4
 
3
5
  [![npm version](https://img.shields.io/npm/v/antigravity-claude-proxy.svg)](https://www.npmjs.com/package/antigravity-claude-proxy)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antigravity-claude-proxy",
3
- "version": "2.7.3",
3
+ "version": "2.7.5",
4
4
  "description": "Proxy server to use Antigravity's Claude models with Claude Code CLI",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -63,7 +63,8 @@
63
63
  "better-sqlite3": "^12.5.0",
64
64
  "cors": "^2.8.5",
65
65
  "express": "^4.18.2",
66
- "undici": "^7.20.0"
66
+ "undici": "^7.20.0",
67
+ "wreq-js": "^2.0.1"
67
68
  },
68
69
  "devDependencies": {
69
70
  "@tailwindcss/forms": "^0.5.7",
@@ -235,7 +235,7 @@ export async function discoverProject(token, projectId = undefined) {
235
235
  'Content-Type': 'application/json',
236
236
  ...LOAD_CODE_ASSIST_HEADERS
237
237
  },
238
- body: JSON.stringify({ metadata })
238
+ body: JSON.stringify({ metadata, mode: 1 })
239
239
  });
240
240
 
241
241
  if (!response.ok) {
@@ -139,7 +139,7 @@ export async function sendMessage(anthropicRequest, accountManager, fallbackEnab
139
139
  // Get token and project for this account
140
140
  const token = await accountManager.getTokenForAccount(account);
141
141
  const project = await accountManager.getProjectForAccount(account, token);
142
- const payload = buildCloudCodeRequest(anthropicRequest, project);
142
+ const payload = buildCloudCodeRequest(anthropicRequest, project, account.email);
143
143
 
144
144
  logger.debug(`[CloudCode] Sending request for model: ${model}`);
145
145
 
@@ -49,12 +49,12 @@ export async function listModels(token) {
49
49
  const modelList = Object.entries(data.models)
50
50
  .filter(([modelId]) => isSupportedModel(modelId))
51
51
  .map(([modelId, modelData]) => ({
52
- id: modelId,
53
- object: 'model',
54
- created: Math.floor(Date.now() / 1000),
55
- owned_by: 'anthropic',
56
- description: modelData.displayName || modelId
57
- }));
52
+ id: modelId,
53
+ object: 'model',
54
+ created: Math.floor(Date.now() / 1000),
55
+ owned_by: 'anthropic',
56
+ description: modelData.displayName || modelId
57
+ }));
58
58
 
59
59
  // Warm the model validation cache
60
60
  modelCache.validModels = new Set(modelList.map(m => m.id));
@@ -183,10 +183,8 @@ export async function getSubscriptionTier(token) {
183
183
  method: 'POST',
184
184
  headers,
185
185
  body: JSON.stringify({
186
- metadata: {
187
- ...CLIENT_METADATA,
188
- duetProject: 'rising-fact-p41fc'
189
- }
186
+ metadata: CLIENT_METADATA,
187
+ mode: 1
190
188
  })
191
189
  });
192
190
 
@@ -19,14 +19,15 @@ import { deriveSessionId } from './session-manager.js';
19
19
  *
20
20
  * @param {Object} anthropicRequest - The Anthropic-format request
21
21
  * @param {string} projectId - The project ID to use
22
+ * @param {string} accountEmail - The account email for session ID derivation
22
23
  * @returns {Object} The Cloud Code API request payload
23
24
  */
24
- export function buildCloudCodeRequest(anthropicRequest, projectId) {
25
+ export function buildCloudCodeRequest(anthropicRequest, projectId, accountEmail) {
25
26
  const model = anthropicRequest.model;
26
27
  const googleRequest = convertAnthropicToGoogle(anthropicRequest);
27
28
 
28
29
  // Use stable session ID derived from first user message for cache continuity
29
- googleRequest.sessionId = deriveSessionId(anthropicRequest);
30
+ googleRequest.sessionId = deriveSessionId(anthropicRequest, accountEmail);
30
31
 
31
32
  // Build system instruction parts array with [ignore] tags to prevent model from
32
33
  // identifying as "Antigravity" (fixes GitHub issue #76)
@@ -8,40 +8,59 @@
8
8
 
9
9
  import crypto from 'crypto';
10
10
 
11
+
12
+ // Runtime storage for session IDs (per account)
13
+ // This mimics the behavior of the binary which generates a session ID at startup
14
+ // and keeps it for the process lifetime.
15
+ // Key: accountEmail, Value: sessionId
16
+ const runtimeSessionStore = new Map();
17
+
11
18
  /**
12
- * Derive a stable session ID from the first user message in the conversation.
13
- * This ensures the same conversation uses the same session ID across turns,
14
- * enabling prompt caching (cache is scoped to session + organization).
19
+ * Get or create a session ID for the given account.
20
+ *
21
+ * The binary generates a session ID once at startup: `p.sessionID = rs() + Date.now()`.
22
+ * Since our proxy is long-running, we simulate this "per-launch" behavior by storing
23
+ * a generated ID in memory for each account.
15
24
  *
16
- * @param {Object} anthropicRequest - The Anthropic-format request
17
- * @returns {string} A stable session ID (32 hex characters) or random UUID if no user message
25
+ * - If the proxy restarts, the ID changes (matching binary/VS Code restart behavior).
26
+ * - Within a running proxy instance, the ID is stable for that account.
27
+ * - This enables prompt caching while using the EXACT random logic of the binary.
28
+ *
29
+ * @param {Object} anthropicRequest - The Anthropic-format request (unused for ID generation now)
30
+ * @param {string} accountEmail - The account email to scope the session ID
31
+ * @returns {string} A stable session ID string matching binary format
18
32
  */
19
- export function deriveSessionId(anthropicRequest) {
20
- const messages = anthropicRequest.messages || [];
21
-
22
- // Find the first user message
23
- for (const msg of messages) {
24
- if (msg.role === 'user') {
25
- let content = '';
26
-
27
- if (typeof msg.content === 'string') {
28
- content = msg.content;
29
- } else if (Array.isArray(msg.content)) {
30
- // Extract text from content blocks
31
- content = msg.content
32
- .filter(block => block.type === 'text' && block.text)
33
- .map(block => block.text)
34
- .join('\n');
35
- }
36
-
37
- if (content) {
38
- // Hash the content with SHA256, return first 32 hex chars
39
- const hash = crypto.createHash('sha256').update(content).digest('hex');
40
- return hash.substring(0, 32);
41
- }
42
- }
33
+ export function deriveSessionId(anthropicRequest, accountEmail) {
34
+ if (!accountEmail) {
35
+ // Fallback for requests without an account (should differ every time)
36
+ return generateBinaryStyleId();
37
+ }
38
+
39
+ // Check if we already have a session ID for this account in this process run
40
+ if (runtimeSessionStore.has(accountEmail)) {
41
+ return runtimeSessionStore.get(accountEmail);
43
42
  }
44
43
 
45
- // Fallback to random UUID if no user message found
46
- return crypto.randomUUID();
44
+ // Generate a new ID using the binary's exact logic
45
+ const newSessionId = generateBinaryStyleId();
46
+
47
+ // Store it for future requests from this account
48
+ runtimeSessionStore.set(accountEmail, newSessionId);
49
+
50
+ return newSessionId;
51
+ }
52
+
53
+ /**
54
+ * Generate a Session ID using the binary's exact logic.
55
+ * logic: `rs() + Date.now()` where `rs()` is randomUUID
56
+ */
57
+ function generateBinaryStyleId() {
58
+ return crypto.randomUUID() + Date.now().toString();
59
+ }
60
+
61
+ /**
62
+ * Clears all session IDs (e.g. useful for testing or explicit reset)
63
+ */
64
+ export function clearSessionStore() {
65
+ runtimeSessionStore.clear();
47
66
  }
@@ -139,7 +139,7 @@ export async function* sendMessageStream(anthropicRequest, accountManager, fallb
139
139
  // Get token and project for this account
140
140
  const token = await accountManager.getTokenForAccount(account);
141
141
  const project = await accountManager.getProjectForAccount(account, token);
142
- const payload = buildCloudCodeRequest(anthropicRequest, project);
142
+ const payload = buildCloudCodeRequest(anthropicRequest, project, account.email);
143
143
 
144
144
  logger.debug(`[CloudCode] Starting stream for model: ${model}`);
145
145
 
package/src/constants.js CHANGED
@@ -30,7 +30,7 @@ function getAntigravityDbPath() {
30
30
  * Generate platform-specific User-Agent string.
31
31
  * @returns {string} User-Agent in format "antigravity/version os/arch"
32
32
  */
33
- function getPlatformUserAgent() {
33
+ export function getPlatformUserAgent() {
34
34
  const os = platform();
35
35
  const architecture = arch();
36
36
  return `antigravity/1.16.5 ${os}/${architecture}`;
@@ -40,24 +40,25 @@ function getPlatformUserAgent() {
40
40
  // Reference: Antigravity binary analysis - google.internal.cloud.code.v1internal.ClientMetadata.IdeType
41
41
  export const IDE_TYPE = {
42
42
  UNSPECIFIED: 0,
43
- JETSKI: 5, // Internal codename for Gemini CLI
44
- ANTIGRAVITY: 6,
43
+ JETSKI: 10, // Internal codename for Gemini CLI
44
+ ANTIGRAVITY: 9,
45
45
  PLUGINS: 7
46
46
  };
47
47
 
48
- // Platform enum
49
- // Reference: Antigravity binary analysis - google.internal.cloud.code.v1internal.ClientMetadata.Platform
48
+ // Platform enum (as specified in Antigravity binary)
50
49
  export const PLATFORM = {
51
50
  UNSPECIFIED: 0,
52
- WINDOWS: 1,
53
- LINUX: 2,
54
- MACOS: 3
51
+ DARWIN_AMD64: 1,
52
+ DARWIN_ARM64: 2,
53
+ LINUX_AMD64: 3,
54
+ LINUX_ARM64: 4,
55
+ WINDOWS_AMD64: 5
55
56
  };
56
57
 
57
- // Plugin type enum
58
+ // Plugin type enum (as specified in Antigravity binary)
58
59
  export const PLUGIN_TYPE = {
59
60
  UNSPECIFIED: 0,
60
- DUET_AI: 1,
61
+ CLOUD_CODE: 1,
61
62
  GEMINI: 2
62
63
  };
63
64
 
@@ -66,12 +67,17 @@ export const PLUGIN_TYPE = {
66
67
  * @returns {number} Platform enum value
67
68
  */
68
69
  function getPlatformEnum() {
69
- switch (platform()) {
70
- case 'darwin': return PLATFORM.MACOS;
71
- case 'win32': return PLATFORM.WINDOWS;
72
- case 'linux': return PLATFORM.LINUX;
73
- default: return PLATFORM.UNSPECIFIED;
70
+ const os = platform();
71
+ const architecture = arch();
72
+
73
+ if (os === 'darwin') {
74
+ return architecture === 'arm64' ? PLATFORM.DARWIN_ARM64 : PLATFORM.DARWIN_AMD64;
75
+ } else if (os === 'linux') {
76
+ return architecture === 'arm64' ? PLATFORM.LINUX_ARM64 : PLATFORM.LINUX_AMD64;
77
+ } else if (os === 'win32') {
78
+ return PLATFORM.WINDOWS_AMD64;
74
79
  }
80
+ return PLATFORM.UNSPECIFIED;
75
81
  }
76
82
 
77
83
  // Centralized client metadata (used in request bodies for loadCodeAssist, onboardUser, etc.)
@@ -93,10 +99,11 @@ export const ANTIGRAVITY_ENDPOINT_FALLBACKS = [
93
99
  ];
94
100
 
95
101
  // Required headers for Antigravity API requests
102
+ // Headers for general Antigravity API requests
103
+ // Strictly matches the generic 'u' method in main.js
96
104
  export const ANTIGRAVITY_HEADERS = {
97
105
  'User-Agent': getPlatformUserAgent(),
98
- 'X-Goog-Api-Client': 'google-cloud-sdk vscode_cloudshelleditor/0.1',
99
- 'Client-Metadata': JSON.stringify(CLIENT_METADATA)
106
+ 'Content-Type': 'application/json'
100
107
  };
101
108
 
102
109
  // Endpoint order for loadCodeAssist (prod first)
@@ -110,6 +117,7 @@ export const LOAD_CODE_ASSIST_ENDPOINTS = [
110
117
  export const ONBOARD_USER_ENDPOINTS = ANTIGRAVITY_ENDPOINT_FALLBACKS;
111
118
 
112
119
  // Headers for loadCodeAssist API
120
+ // Matches the minimal headers seen in the binary's u() method
113
121
  export const LOAD_CODE_ASSIST_HEADERS = ANTIGRAVITY_HEADERS;
114
122
 
115
123
  // Default project ID if none can be discovered
package/src/index.js CHANGED
@@ -12,6 +12,7 @@ import { logger } from './utils/logger.js';
12
12
  import { config } from './config.js';
13
13
  import { getStrategyLabel, STRATEGY_NAMES, DEFAULT_STRATEGY } from './account-manager/strategies/index.js';
14
14
  import { getPackageVersion } from './utils/helpers.js';
15
+ import tlsClient from './utils/tls-client.js';
15
16
  import path from 'path';
16
17
  import os from 'os';
17
18
 
@@ -159,8 +160,15 @@ ${environmentSection}
159
160
  });
160
161
 
161
162
  // Graceful shutdown
162
- const shutdown = () => {
163
+ const shutdown = async () => {
163
164
  logger.info('Shutting down server...');
165
+
166
+ try {
167
+ await tlsClient.exit();
168
+ } catch (err) {
169
+ logger.error('Error shutting down TLS client:', err);
170
+ }
171
+
164
172
  server.close(() => {
165
173
  logger.success('Server stopped');
166
174
  process.exit(0);
@@ -2,6 +2,7 @@ import { readFileSync } from 'fs';
2
2
  import { fileURLToPath } from 'url';
3
3
  import path from 'path';
4
4
  import { config } from '../config.js';
5
+ import tlsClient from './tls-client.js';
5
6
 
6
7
  /**
7
8
  * Shared Utility Functions
@@ -86,7 +87,7 @@ export async function throttledFetch(url, options) {
86
87
  await sleep(delayMs);
87
88
  }
88
89
  }
89
- return fetch(url, options);
90
+ return tlsClient.fetch(url, options);
90
91
  }
91
92
 
92
93
  /**
@@ -0,0 +1,102 @@
1
+ import { createRequire } from 'module';
2
+ import { Readable } from 'stream';
3
+ import { getPlatformUserAgent } from '../constants.js';
4
+
5
+ const require = createRequire(import.meta.url);
6
+ const { createSession } = require('wreq-js');
7
+
8
+ class TlsClient {
9
+ constructor() {
10
+ this.userAgent = getPlatformUserAgent();
11
+ this.session = null;
12
+ }
13
+
14
+ async getSession() {
15
+ if (this.session) return this.session;
16
+ this.session = await createSession({
17
+ browser: 'chrome_124',
18
+ os: 'macos',
19
+ userAgent: this.userAgent
20
+ });
21
+ return this.session;
22
+ }
23
+
24
+ async fetch(url, options = {}) {
25
+ const session = await this.getSession();
26
+ const method = (options.method || 'GET').toUpperCase();
27
+
28
+ const wreqOptions = {
29
+ method,
30
+ headers: options.headers,
31
+ body: options.body,
32
+ redirect: options.redirect === 'manual' ? 'manual' : 'follow',
33
+ };
34
+
35
+ try {
36
+ const response = await session.fetch(url, wreqOptions);
37
+ return new ResponseWrapper(response);
38
+ } catch (error) {
39
+ console.error('wreq-js fetch failed:', error);
40
+ throw error;
41
+ }
42
+ }
43
+
44
+ async exit() {
45
+ if (this.session) {
46
+ await this.session.close();
47
+ this.session = null;
48
+ }
49
+ }
50
+ }
51
+
52
+ class ResponseWrapper {
53
+ constructor(wreqResponse) {
54
+ this.status = wreqResponse.status;
55
+ this.statusText = wreqResponse.statusText || (this.status === 200 ? 'OK' : `Status ${this.status}`);
56
+ this.headers = new Headers(wreqResponse.headers);
57
+ this.url = wreqResponse.url;
58
+ this.ok = this.status >= 200 && this.status < 300;
59
+
60
+ if (wreqResponse.body) {
61
+ if (typeof wreqResponse.body.getReader === 'function') {
62
+ this.body = wreqResponse.body;
63
+ } else {
64
+ this.body = Readable.toWeb(wreqResponse.body);
65
+ }
66
+ } else {
67
+ this.body = null;
68
+ }
69
+ }
70
+
71
+ async text() {
72
+ if (!this.body) return '';
73
+ const reader = this.body.getReader();
74
+ const chunks = [];
75
+ while (true) {
76
+ const { done, value } = await reader.read();
77
+ if (done) break;
78
+ chunks.push(typeof value === 'string' ? Buffer.from(value) : value);
79
+ }
80
+ return Buffer.concat(chunks).toString('utf8');
81
+ }
82
+
83
+ async json() {
84
+ const text = await this.text();
85
+ return JSON.parse(text);
86
+ }
87
+ }
88
+
89
+ class Headers {
90
+ constructor(headersObj = {}) {
91
+ this.map = new Map();
92
+ for (const [key, value] of Object.entries(headersObj)) {
93
+ this.map.set(key.toLowerCase(), Array.isArray(value) ? value.join(', ') : value);
94
+ }
95
+ }
96
+
97
+ get(name) { return this.map.get(name.toLowerCase()) || null; }
98
+ has(name) { return this.map.has(name.toLowerCase()); }
99
+ forEach(callback) { this.map.forEach(callback); }
100
+ }
101
+
102
+ export default new TlsClient();