@fxz26284407/yuanma-gateway 0.1.3 → 0.1.4
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/bin/yuanma-gateway.mjs +0 -0
- package/dist/antigravity-native.js +32 -5
- package/package.json +2 -1
package/bin/yuanma-gateway.mjs
CHANGED
|
File without changes
|
|
@@ -11,11 +11,34 @@ const binary = '/Applications/Antigravity.app/Contents/Resources/bin/language_se
|
|
|
11
11
|
export class AntigravityNative {
|
|
12
12
|
#authority;
|
|
13
13
|
#checked = 0;
|
|
14
|
+
#connecting;
|
|
15
|
+
#epoch = 0;
|
|
14
16
|
ready = false;
|
|
15
17
|
get generation() { return this.#authority ? this.#authority.pid + ':' + this.#authority.port : ''; }
|
|
16
18
|
async connect() {
|
|
17
|
-
|
|
19
|
+
// ponytail: recheck ownership every 30s; failures invalidate sooner, without replaying requests.
|
|
20
|
+
if (this.ready && Date.now() - this.#checked < 30000)
|
|
18
21
|
return;
|
|
22
|
+
if (this.#connecting)
|
|
23
|
+
return this.#connecting;
|
|
24
|
+
const epoch = this.#epoch, pending = this.discover(epoch);
|
|
25
|
+
this.#connecting = pending;
|
|
26
|
+
try {
|
|
27
|
+
await pending;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (epoch === this.#epoch) {
|
|
31
|
+
this.ready = false;
|
|
32
|
+
this.#checked = 0;
|
|
33
|
+
}
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
if (this.#connecting === pending)
|
|
38
|
+
this.#connecting = undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async discover(epoch) {
|
|
19
42
|
requireValue(process.platform === 'darwin', 'BACKEND_UNAVAILABLE', 'Antigravity 桌面接入需要 macOS', 503);
|
|
20
43
|
const version = JSON.parse(await readFile(app + '/package.json', 'utf8')).version;
|
|
21
44
|
requireValue(version === '2.29.0', 'PROTOCOL_INCOMPATIBLE', '当前仅适配 Antigravity App 2.29.0,请核对桌面版本', 503);
|
|
@@ -34,7 +57,7 @@ export class AntigravityNative {
|
|
|
34
57
|
const desktop = processes[0];
|
|
35
58
|
const { stdout: listeners } = await exec('/usr/sbin/lsof', ['-nP', '-a', '-p', String(desktop.pid), '-iTCP', '-sTCP:LISTEN', '-Fn'], { maxBuffer: 65536 });
|
|
36
59
|
const ports = [...new Set([...listeners.matchAll(/^n(?:127\.0\.0\.1|\*|\[::1\]):(\d+)$/gm)].map(m => Number(m[1])))];
|
|
37
|
-
requireValue(ports.length > 0
|
|
60
|
+
requireValue(ports.length > 0, 'BACKEND_UNAVAILABLE', '无法核实 Antigravity 桌面监听地址', 503);
|
|
38
61
|
const executable = await stat(binary);
|
|
39
62
|
requireValue(executable.isFile() && !(executable.mode & 0o002), 'UNSAFE_STORAGE', 'Antigravity 可执行文件权限异常', 403);
|
|
40
63
|
let found;
|
|
@@ -50,6 +73,7 @@ export class AntigravityNative {
|
|
|
50
73
|
catch { /* Only ports owned by the verified desktop process are considered. */ }
|
|
51
74
|
}
|
|
52
75
|
requireValue(found, 'BACKEND_UNAVAILABLE', 'Antigravity 桌面会话接口未就绪', 503);
|
|
76
|
+
requireValue(epoch === this.#epoch, 'BACKEND_UNAVAILABLE', 'Antigravity 连接已关闭', 503);
|
|
53
77
|
this.#authority = found;
|
|
54
78
|
this.#checked = Date.now();
|
|
55
79
|
this.ready = true;
|
|
@@ -61,7 +85,7 @@ export class AntigravityNative {
|
|
|
61
85
|
return await this.rpc(authority, method, params, timeout, signal);
|
|
62
86
|
}
|
|
63
87
|
catch (error) {
|
|
64
|
-
if (!signal?.aborted) {
|
|
88
|
+
if (!signal?.aborted && this.#authority === authority) {
|
|
65
89
|
this.ready = false;
|
|
66
90
|
this.#checked = 0;
|
|
67
91
|
}
|
|
@@ -91,7 +115,10 @@ export class AntigravityNative {
|
|
|
91
115
|
payload.copy(frame, 5);
|
|
92
116
|
let ended = false, received = false;
|
|
93
117
|
const finish = (error) => { if (ended)
|
|
94
|
-
return; ended = true; clearTimeout(first); req.destroy();
|
|
118
|
+
return; ended = true; clearTimeout(first); req.destroy(); if (error && this.#authority === authority) {
|
|
119
|
+
this.ready = false;
|
|
120
|
+
this.#checked = 0;
|
|
121
|
+
} onEnd(error); };
|
|
95
122
|
const req = request({ hostname: '127.0.0.1', port: authority.port, path: '/exa.language_server_pb.LanguageServerService/' + method, method: 'POST', rejectUnauthorized: false, headers: { 'content-type': 'application/connect+json', 'connect-protocol-version': '1', 'x-codeium-csrf-token': authority.token } }, res => {
|
|
96
123
|
if (res.statusCode !== 200) {
|
|
97
124
|
finish(new Error('Antigravity 状态订阅不可用(HTTP ' + res.statusCode + ')'));
|
|
@@ -180,5 +207,5 @@ export class AntigravityNative {
|
|
|
180
207
|
req.end(payload);
|
|
181
208
|
});
|
|
182
209
|
}
|
|
183
|
-
close() { this.#authority = undefined; this.#checked = 0; this.ready = false; }
|
|
210
|
+
close() { this.#epoch++; this.#connecting = undefined; this.#authority = undefined; this.#checked = 0; this.ready = false; }
|
|
184
211
|
}
|