antigravity-claude-proxy 2.7.4 → 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/package.json +3 -2
- package/src/cloudcode/session-manager.js +49 -36
- package/src/constants.js +1 -1
- package/src/index.js +9 -1
- package/src/utils/helpers.js +2 -1
- package/src/utils/tls-client.js +102 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "antigravity-claude-proxy",
|
|
3
|
-
"version": "2.7.
|
|
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",
|
|
@@ -8,46 +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
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
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
|
|
19
32
|
*/
|
|
20
33
|
export function deriveSessionId(anthropicRequest, accountEmail) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
content = msg.content;
|
|
30
|
-
} else if (Array.isArray(msg.content)) {
|
|
31
|
-
// Extract text from content blocks
|
|
32
|
-
content = msg.content
|
|
33
|
-
.filter(block => block.type === 'text' && block.text)
|
|
34
|
-
.map(block => block.text)
|
|
35
|
-
.join('\n');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (content) {
|
|
39
|
-
// Include account email in the content to be hashed to ensure
|
|
40
|
-
// unique session IDs per account for the same conversation.
|
|
41
|
-
// This prevents Google from correlating sessions across accounts.
|
|
42
|
-
const saltedContent = accountEmail ? `${accountEmail}:${content}` : content;
|
|
43
|
-
|
|
44
|
-
// Hash the content with SHA256, return first 32 hex chars
|
|
45
|
-
const hash = crypto.createHash('sha256').update(saltedContent).digest('hex');
|
|
46
|
-
return hash.substring(0, 32);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
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);
|
|
49
42
|
}
|
|
50
43
|
|
|
51
|
-
//
|
|
52
|
-
|
|
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();
|
|
53
66
|
}
|
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}`;
|
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);
|
package/src/utils/helpers.js
CHANGED
|
@@ -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();
|