@aibridge/driver-agy 0.9.1 → 0.9.2
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/dist/index.d.mts +9 -5
- package/dist/index.mjs +55 -7
- package/package.json +1 -1
- package/src/agyQuota.test.ts +18 -1
- package/src/agyQuota.ts +53 -8
package/dist/index.d.mts
CHANGED
|
@@ -27,11 +27,15 @@ declare function buildAgyPrintArgs(prompt: string, opts: AgyPrintArgs): string[]
|
|
|
27
27
|
* token — no separate login. Mechanism learned from
|
|
28
28
|
* github.com/skainguyen1412/antigravity-usage (reimplemented, not vendored):
|
|
29
29
|
*
|
|
30
|
-
* 1. Read
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
30
|
+
* 1. Read agy's credential — the OS keyring entry (go-keyring, service
|
|
31
|
+
* `gemini`, account `antigravity`) first, then the fallback file
|
|
32
|
+
* `~/.gemini/antigravity-cli/antigravity-oauth-token`. Both hold
|
|
33
|
+
* { token: { access_token, refresh_token, expiry }, auth_method }; agy
|
|
34
|
+
* only writes the file when the keyring is bypassed or unreachable, so
|
|
35
|
+
* the file goes stale once the keyring works. If expired, refresh
|
|
36
|
+
* in-memory via Google's token endpoint with Antigravity's installed-app
|
|
37
|
+
* client (public by design for installed apps); we NEVER write agy's
|
|
38
|
+
* store.
|
|
35
39
|
* 2. POST cloudcode-pa.googleapis.com/v1internal:loadCodeAssist
|
|
36
40
|
* (metadata ideType ANTIGRAVITY / pluginType GEMINI) → project id.
|
|
37
41
|
* 3. POST /v1internal:fetchAvailableModels { project } — the
|
package/dist/index.mjs
CHANGED
|
@@ -36,11 +36,15 @@ const AGY_CANONICAL_TO_NATIVE = {
|
|
|
36
36
|
* token — no separate login. Mechanism learned from
|
|
37
37
|
* github.com/skainguyen1412/antigravity-usage (reimplemented, not vendored):
|
|
38
38
|
*
|
|
39
|
-
* 1. Read
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
39
|
+
* 1. Read agy's credential — the OS keyring entry (go-keyring, service
|
|
40
|
+
* `gemini`, account `antigravity`) first, then the fallback file
|
|
41
|
+
* `~/.gemini/antigravity-cli/antigravity-oauth-token`. Both hold
|
|
42
|
+
* { token: { access_token, refresh_token, expiry }, auth_method }; agy
|
|
43
|
+
* only writes the file when the keyring is bypassed or unreachable, so
|
|
44
|
+
* the file goes stale once the keyring works. If expired, refresh
|
|
45
|
+
* in-memory via Google's token endpoint with Antigravity's installed-app
|
|
46
|
+
* client (public by design for installed apps); we NEVER write agy's
|
|
47
|
+
* store.
|
|
44
48
|
* 2. POST cloudcode-pa.googleapis.com/v1internal:loadCodeAssist
|
|
45
49
|
* (metadata ideType ANTIGRAVITY / pluginType GEMINI) → project id.
|
|
46
50
|
* 3. POST /v1internal:fetchAvailableModels { project } — the
|
|
@@ -70,9 +74,53 @@ function parseQuotaGroups(groups) {
|
|
|
70
74
|
function agyTokenPath() {
|
|
71
75
|
return process.env.AGY_OAUTH_TOKEN_PATH ?? join(homedir(), ".gemini", "antigravity-cli", "antigravity-oauth-token");
|
|
72
76
|
}
|
|
77
|
+
const KEYRING_B64_PREFIX = "go-keyring-base64:";
|
|
78
|
+
/**
|
|
79
|
+
* go-keyring base64-wraps the secret on macOS (`go-keyring-base64:` prefix)
|
|
80
|
+
* and stores it raw on Linux. Returns undefined unless the result parses as
|
|
81
|
+
* the token JSON, so a malformed keyring entry falls through to the file.
|
|
82
|
+
*/
|
|
83
|
+
function decodeKeyringSecret(raw) {
|
|
84
|
+
const s = raw.trim();
|
|
85
|
+
const json = s.startsWith(KEYRING_B64_PREFIX) ? Buffer.from(s.slice(18), "base64").toString("utf8") : s;
|
|
86
|
+
try {
|
|
87
|
+
const parsed = JSON.parse(json);
|
|
88
|
+
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
89
|
+
} catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async function readKeyringCredential() {
|
|
94
|
+
const cmd = {
|
|
95
|
+
darwin: ["security", [
|
|
96
|
+
"find-generic-password",
|
|
97
|
+
"-s",
|
|
98
|
+
"gemini",
|
|
99
|
+
"-a",
|
|
100
|
+
"antigravity",
|
|
101
|
+
"-w"
|
|
102
|
+
]],
|
|
103
|
+
linux: ["secret-tool", [
|
|
104
|
+
"lookup",
|
|
105
|
+
"service",
|
|
106
|
+
"gemini",
|
|
107
|
+
"username",
|
|
108
|
+
"antigravity"
|
|
109
|
+
]]
|
|
110
|
+
}[process.platform];
|
|
111
|
+
if (!cmd) return void 0;
|
|
112
|
+
const res = await runCaptured(cmd[0], cmd[1], { timeoutMs: 5e3 }).catch(() => void 0);
|
|
113
|
+
return res?.code === 0 ? decodeKeyringSecret(res.stdout) : void 0;
|
|
114
|
+
}
|
|
115
|
+
async function readAgyCredential() {
|
|
116
|
+
if (!process.env.AGY_OAUTH_TOKEN_PATH) {
|
|
117
|
+
const fromKeyring = await readKeyringCredential();
|
|
118
|
+
if (fromKeyring) return fromKeyring;
|
|
119
|
+
}
|
|
120
|
+
return JSON.parse(readFileSync(agyTokenPath(), "utf8"));
|
|
121
|
+
}
|
|
73
122
|
async function getAccessToken() {
|
|
74
|
-
const
|
|
75
|
-
const parsed = JSON.parse(raw);
|
|
123
|
+
const parsed = await readAgyCredential();
|
|
76
124
|
const access = parsed.token?.access_token;
|
|
77
125
|
const refresh = parsed.token?.refresh_token;
|
|
78
126
|
const expiry = parsed.token?.expiry;
|
package/package.json
CHANGED
package/src/agyQuota.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import { test } from 'vitest';
|
|
3
|
-
import { findModelQuota, parseModels, parseQuotaGroups } from './agyQuota.ts';
|
|
3
|
+
import { decodeKeyringSecret, findModelQuota, parseModels, parseQuotaGroups } from './agyQuota.ts';
|
|
4
4
|
|
|
5
5
|
test('parseQuotaGroups preserves fractions or defaults to 0 if absent', () => {
|
|
6
6
|
const groups = [
|
|
@@ -124,3 +124,20 @@ test('findModelQuota hits modelId id-form', () => {
|
|
|
124
124
|
const found = findModelQuota(snapshot, 'gemini-3.7-flash-high');
|
|
125
125
|
assert.equal(found?.modelId, 'gemini-3.7-flash-high');
|
|
126
126
|
});
|
|
127
|
+
|
|
128
|
+
test('decodeKeyringSecret accepts raw JSON (linux) and go-keyring base64 (macOS)', () => {
|
|
129
|
+
const token = {
|
|
130
|
+
token: { access_token: 'a', refresh_token: 'r', expiry: '2026-01-01T00:00:00Z' },
|
|
131
|
+
};
|
|
132
|
+
const json = JSON.stringify(token);
|
|
133
|
+
assert.deepEqual(decodeKeyringSecret(`${json}\n`), token);
|
|
134
|
+
const b64 = Buffer.from(json).toString('base64');
|
|
135
|
+
assert.deepEqual(decodeKeyringSecret(`go-keyring-base64:${b64}\n`), token);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('decodeKeyringSecret returns undefined for malformed payloads so the file fallback runs', () => {
|
|
139
|
+
assert.equal(decodeKeyringSecret(''), undefined);
|
|
140
|
+
assert.equal(decodeKeyringSecret('not json'), undefined);
|
|
141
|
+
assert.equal(decodeKeyringSecret('go-keyring-base64:!!!'), undefined);
|
|
142
|
+
assert.equal(decodeKeyringSecret('"a string"'), undefined);
|
|
143
|
+
});
|
package/src/agyQuota.ts
CHANGED
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
* token — no separate login. Mechanism learned from
|
|
4
4
|
* github.com/skainguyen1412/antigravity-usage (reimplemented, not vendored):
|
|
5
5
|
*
|
|
6
|
-
* 1. Read
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* 1. Read agy's credential — the OS keyring entry (go-keyring, service
|
|
7
|
+
* `gemini`, account `antigravity`) first, then the fallback file
|
|
8
|
+
* `~/.gemini/antigravity-cli/antigravity-oauth-token`. Both hold
|
|
9
|
+
* { token: { access_token, refresh_token, expiry }, auth_method }; agy
|
|
10
|
+
* only writes the file when the keyring is bypassed or unreachable, so
|
|
11
|
+
* the file goes stale once the keyring works. If expired, refresh
|
|
12
|
+
* in-memory via Google's token endpoint with Antigravity's installed-app
|
|
13
|
+
* client (public by design for installed apps); we NEVER write agy's
|
|
14
|
+
* store.
|
|
11
15
|
* 2. POST cloudcode-pa.googleapis.com/v1internal:loadCodeAssist
|
|
12
16
|
* (metadata ideType ANTIGRAVITY / pluginType GEMINI) → project id.
|
|
13
17
|
* 3. POST /v1internal:fetchAvailableModels { project } — the
|
|
@@ -21,7 +25,7 @@
|
|
|
21
25
|
import { readFileSync } from 'node:fs';
|
|
22
26
|
import { homedir } from 'node:os';
|
|
23
27
|
import { join } from 'node:path';
|
|
24
|
-
import { AuthExpiredError } from '@aibridge/proc';
|
|
28
|
+
import { AuthExpiredError, runCaptured } from '@aibridge/proc';
|
|
25
29
|
import { AGY_CANONICAL_TO_NATIVE } from './registry.ts';
|
|
26
30
|
|
|
27
31
|
const CLOUDCODE_BASE = 'https://cloudcode-pa.googleapis.com';
|
|
@@ -95,9 +99,50 @@ interface AgyTokenFile {
|
|
|
95
99
|
token?: { access_token?: string; refresh_token?: string; expiry?: string };
|
|
96
100
|
}
|
|
97
101
|
|
|
102
|
+
const KEYRING_B64_PREFIX = 'go-keyring-base64:';
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* go-keyring base64-wraps the secret on macOS (`go-keyring-base64:` prefix)
|
|
106
|
+
* and stores it raw on Linux. Returns undefined unless the result parses as
|
|
107
|
+
* the token JSON, so a malformed keyring entry falls through to the file.
|
|
108
|
+
*/
|
|
109
|
+
export function decodeKeyringSecret(raw: string): AgyTokenFile | undefined {
|
|
110
|
+
const s = raw.trim();
|
|
111
|
+
const json = s.startsWith(KEYRING_B64_PREFIX)
|
|
112
|
+
? Buffer.from(s.slice(KEYRING_B64_PREFIX.length), 'base64').toString('utf8')
|
|
113
|
+
: s;
|
|
114
|
+
try {
|
|
115
|
+
const parsed: unknown = JSON.parse(json);
|
|
116
|
+
return parsed && typeof parsed === 'object' ? (parsed as AgyTokenFile) : undefined;
|
|
117
|
+
} catch {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function readKeyringCredential(): Promise<AgyTokenFile | undefined> {
|
|
123
|
+
const lookup: Record<string, [string, string[]]> = {
|
|
124
|
+
darwin: ['security', ['find-generic-password', '-s', 'gemini', '-a', 'antigravity', '-w']],
|
|
125
|
+
linux: ['secret-tool', ['lookup', 'service', 'gemini', 'username', 'antigravity']],
|
|
126
|
+
};
|
|
127
|
+
const cmd = lookup[process.platform];
|
|
128
|
+
if (!cmd) return undefined;
|
|
129
|
+
// ponytail: a locked keyring may pop a desktop unlock prompt that the 5s
|
|
130
|
+
// timeout then abandons; the file fallback covers it. Surface the reason in
|
|
131
|
+
// the preflight warning if this ever needs diagnosing.
|
|
132
|
+
const res = await runCaptured(cmd[0], cmd[1], { timeoutMs: 5_000 }).catch(() => undefined);
|
|
133
|
+
return res?.code === 0 ? decodeKeyringSecret(res.stdout) : undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function readAgyCredential(): Promise<AgyTokenFile> {
|
|
137
|
+
if (!process.env.AGY_OAUTH_TOKEN_PATH) {
|
|
138
|
+
const fromKeyring = await readKeyringCredential();
|
|
139
|
+
if (fromKeyring) return fromKeyring;
|
|
140
|
+
}
|
|
141
|
+
return JSON.parse(readFileSync(agyTokenPath(), 'utf8')) as AgyTokenFile;
|
|
142
|
+
}
|
|
143
|
+
|
|
98
144
|
async function getAccessToken(): Promise<string> {
|
|
99
|
-
const
|
|
100
|
-
const parsed = JSON.parse(raw) as AgyTokenFile;
|
|
145
|
+
const parsed = await readAgyCredential();
|
|
101
146
|
const access = parsed.token?.access_token;
|
|
102
147
|
const refresh = parsed.token?.refresh_token;
|
|
103
148
|
const expiry = parsed.token?.expiry;
|