antigravity-auth 1.6.0 → 1.7.0
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 +79 -41
- package/dist/cli.js +2868 -0
- package/dist/handler.js +25119 -0
- package/dist/index.js +25110 -5
- package/package.json +66 -54
- package/dist/antigravity/oauth.d.ts +0 -30
- package/dist/antigravity/oauth.js +0 -170
- package/dist/claude/login.d.ts +0 -7
- package/dist/claude/login.js +0 -480
- package/dist/claude/menu-helpers.d.ts +0 -22
- package/dist/claude/menu-helpers.js +0 -281
- package/dist/claude/proxy-manager.d.ts +0 -11
- package/dist/claude/proxy-manager.js +0 -129
- package/dist/claude/proxy.d.ts +0 -1
- package/dist/claude/proxy.js +0 -733
- package/dist/constants.d.ts +0 -138
- package/dist/constants.js +0 -216
- package/dist/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/hooks/auto-update-checker/cache.js +0 -70
- package/dist/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/hooks/auto-update-checker/checker.js +0 -233
- package/dist/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/hooks/auto-update-checker/constants.js +0 -22
- package/dist/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/hooks/auto-update-checker/index.js +0 -121
- package/dist/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/hooks/auto-update-checker/logging.js +0 -8
- package/dist/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/hooks/auto-update-checker/types.js +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/opencode/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/opencode/hooks/auto-update-checker/cache.js +0 -70
- package/dist/opencode/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/opencode/hooks/auto-update-checker/checker.js +0 -233
- package/dist/opencode/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/opencode/hooks/auto-update-checker/constants.js +0 -22
- package/dist/opencode/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/opencode/hooks/auto-update-checker/index.js +0 -121
- package/dist/opencode/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/opencode/hooks/auto-update-checker/logging.js +0 -8
- package/dist/opencode/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/opencode/hooks/auto-update-checker/types.js +0 -1
- package/dist/opencode/plugin.d.ts +0 -29
- package/dist/opencode/plugin.js +0 -2954
- package/dist/plugin/accounts.d.ts +0 -173
- package/dist/plugin/accounts.js +0 -966
- package/dist/plugin/auth.d.ts +0 -20
- package/dist/plugin/auth.js +0 -44
- package/dist/plugin/cache/index.d.ts +0 -4
- package/dist/plugin/cache/index.js +0 -4
- package/dist/plugin/cache/signature-cache.d.ts +0 -110
- package/dist/plugin/cache/signature-cache.js +0 -347
- package/dist/plugin/cache.d.ts +0 -43
- package/dist/plugin/cache.js +0 -180
- package/dist/plugin/cli.d.ts +0 -26
- package/dist/plugin/cli.js +0 -126
- package/dist/plugin/config/index.d.ts +0 -15
- package/dist/plugin/config/index.js +0 -15
- package/dist/plugin/config/loader.d.ts +0 -38
- package/dist/plugin/config/loader.js +0 -150
- package/dist/plugin/config/models.d.ts +0 -26
- package/dist/plugin/config/models.js +0 -95
- package/dist/plugin/config/schema.d.ts +0 -144
- package/dist/plugin/config/schema.js +0 -458
- package/dist/plugin/config/updater.d.ts +0 -76
- package/dist/plugin/config/updater.js +0 -205
- package/dist/plugin/core/streaming/index.d.ts +0 -2
- package/dist/plugin/core/streaming/index.js +0 -2
- package/dist/plugin/core/streaming/transformer.d.ts +0 -9
- package/dist/plugin/core/streaming/transformer.js +0 -301
- package/dist/plugin/core/streaming/types.d.ts +0 -28
- package/dist/plugin/core/streaming/types.js +0 -1
- package/dist/plugin/debug.d.ts +0 -93
- package/dist/plugin/debug.js +0 -375
- package/dist/plugin/errors.d.ts +0 -27
- package/dist/plugin/errors.js +0 -41
- package/dist/plugin/fingerprint.d.ts +0 -69
- package/dist/plugin/fingerprint.js +0 -137
- package/dist/plugin/image-saver.d.ts +0 -24
- package/dist/plugin/image-saver.js +0 -78
- package/dist/plugin/logger.d.ts +0 -35
- package/dist/plugin/logger.js +0 -67
- package/dist/plugin/logging-utils.d.ts +0 -22
- package/dist/plugin/logging-utils.js +0 -91
- package/dist/plugin/project.d.ts +0 -32
- package/dist/plugin/project.js +0 -229
- package/dist/plugin/quota.d.ts +0 -34
- package/dist/plugin/quota.js +0 -261
- package/dist/plugin/recovery/constants.d.ts +0 -21
- package/dist/plugin/recovery/constants.js +0 -42
- package/dist/plugin/recovery/index.d.ts +0 -11
- package/dist/plugin/recovery/index.js +0 -11
- package/dist/plugin/recovery/storage.d.ts +0 -23
- package/dist/plugin/recovery/storage.js +0 -340
- package/dist/plugin/recovery/types.d.ts +0 -115
- package/dist/plugin/recovery/types.js +0 -6
- package/dist/plugin/recovery.d.ts +0 -60
- package/dist/plugin/recovery.js +0 -360
- package/dist/plugin/refresh-queue.d.ts +0 -99
- package/dist/plugin/refresh-queue.js +0 -235
- package/dist/plugin/request-helpers.d.ts +0 -281
- package/dist/plugin/request-helpers.js +0 -2200
- package/dist/plugin/request.d.ts +0 -110
- package/dist/plugin/request.js +0 -1489
- package/dist/plugin/rotation.d.ts +0 -182
- package/dist/plugin/rotation.js +0 -364
- package/dist/plugin/search.d.ts +0 -31
- package/dist/plugin/search.js +0 -185
- package/dist/plugin/server.d.ts +0 -22
- package/dist/plugin/server.js +0 -306
- package/dist/plugin/storage.d.ts +0 -136
- package/dist/plugin/storage.js +0 -599
- package/dist/plugin/stores/signature-store.d.ts +0 -4
- package/dist/plugin/stores/signature-store.js +0 -24
- package/dist/plugin/thinking-recovery.d.ts +0 -89
- package/dist/plugin/thinking-recovery.js +0 -289
- package/dist/plugin/token.d.ts +0 -18
- package/dist/plugin/token.js +0 -127
- package/dist/plugin/transform/claude.d.ts +0 -79
- package/dist/plugin/transform/claude.js +0 -256
- package/dist/plugin/transform/cross-model-sanitizer.d.ts +0 -34
- package/dist/plugin/transform/cross-model-sanitizer.js +0 -224
- package/dist/plugin/transform/gemini.d.ts +0 -132
- package/dist/plugin/transform/gemini.js +0 -659
- package/dist/plugin/transform/index.d.ts +0 -14
- package/dist/plugin/transform/index.js +0 -9
- package/dist/plugin/transform/model-resolver.d.ts +0 -98
- package/dist/plugin/transform/model-resolver.js +0 -320
- package/dist/plugin/transform/types.d.ts +0 -110
- package/dist/plugin/transform/types.js +0 -1
- package/dist/plugin/types.d.ts +0 -95
- package/dist/plugin/types.js +0 -1
- package/dist/plugin/ui/ansi.d.ts +0 -31
- package/dist/plugin/ui/ansi.js +0 -45
- package/dist/plugin/ui/auth-menu.d.ts +0 -47
- package/dist/plugin/ui/auth-menu.js +0 -199
- package/dist/plugin/ui/confirm.d.ts +0 -1
- package/dist/plugin/ui/confirm.js +0 -14
- package/dist/plugin/ui/select.d.ts +0 -22
- package/dist/plugin/ui/select.js +0 -243
- package/dist/plugin/version.d.ts +0 -18
- package/dist/plugin/version.js +0 -79
- package/dist/src/antigravity/oauth.d.ts +0 -30
- package/dist/src/antigravity/oauth.js +0 -170
- package/dist/src/constants.d.ts +0 -138
- package/dist/src/constants.js +0 -216
- package/dist/src/hooks/auto-update-checker/cache.d.ts +0 -2
- package/dist/src/hooks/auto-update-checker/cache.js +0 -70
- package/dist/src/hooks/auto-update-checker/checker.d.ts +0 -15
- package/dist/src/hooks/auto-update-checker/checker.js +0 -233
- package/dist/src/hooks/auto-update-checker/constants.d.ts +0 -8
- package/dist/src/hooks/auto-update-checker/constants.js +0 -22
- package/dist/src/hooks/auto-update-checker/index.d.ts +0 -33
- package/dist/src/hooks/auto-update-checker/index.js +0 -121
- package/dist/src/hooks/auto-update-checker/logging.d.ts +0 -2
- package/dist/src/hooks/auto-update-checker/logging.js +0 -8
- package/dist/src/hooks/auto-update-checker/types.d.ts +0 -24
- package/dist/src/hooks/auto-update-checker/types.js +0 -1
- package/dist/src/index.d.ts +0 -6
- package/dist/src/index.js +0 -5
- package/dist/src/plugin/accounts.d.ts +0 -173
- package/dist/src/plugin/accounts.js +0 -966
- package/dist/src/plugin/auth.d.ts +0 -20
- package/dist/src/plugin/auth.js +0 -44
- package/dist/src/plugin/cache/index.d.ts +0 -4
- package/dist/src/plugin/cache/index.js +0 -4
- package/dist/src/plugin/cache/signature-cache.d.ts +0 -110
- package/dist/src/plugin/cache/signature-cache.js +0 -347
- package/dist/src/plugin/cache.d.ts +0 -43
- package/dist/src/plugin/cache.js +0 -180
- package/dist/src/plugin/cli.d.ts +0 -26
- package/dist/src/plugin/cli.js +0 -126
- package/dist/src/plugin/config/index.d.ts +0 -15
- package/dist/src/plugin/config/index.js +0 -15
- package/dist/src/plugin/config/loader.d.ts +0 -38
- package/dist/src/plugin/config/loader.js +0 -150
- package/dist/src/plugin/config/models.d.ts +0 -26
- package/dist/src/plugin/config/models.js +0 -95
- package/dist/src/plugin/config/schema.d.ts +0 -144
- package/dist/src/plugin/config/schema.js +0 -458
- package/dist/src/plugin/config/updater.d.ts +0 -76
- package/dist/src/plugin/config/updater.js +0 -205
- package/dist/src/plugin/core/streaming/index.d.ts +0 -2
- package/dist/src/plugin/core/streaming/index.js +0 -2
- package/dist/src/plugin/core/streaming/transformer.d.ts +0 -9
- package/dist/src/plugin/core/streaming/transformer.js +0 -301
- package/dist/src/plugin/core/streaming/types.d.ts +0 -28
- package/dist/src/plugin/core/streaming/types.js +0 -1
- package/dist/src/plugin/debug.d.ts +0 -93
- package/dist/src/plugin/debug.js +0 -375
- package/dist/src/plugin/errors.d.ts +0 -27
- package/dist/src/plugin/errors.js +0 -41
- package/dist/src/plugin/fingerprint.d.ts +0 -69
- package/dist/src/plugin/fingerprint.js +0 -137
- package/dist/src/plugin/image-saver.d.ts +0 -24
- package/dist/src/plugin/image-saver.js +0 -78
- package/dist/src/plugin/logger.d.ts +0 -35
- package/dist/src/plugin/logger.js +0 -67
- package/dist/src/plugin/logging-utils.d.ts +0 -22
- package/dist/src/plugin/logging-utils.js +0 -91
- package/dist/src/plugin/project.d.ts +0 -32
- package/dist/src/plugin/project.js +0 -229
- package/dist/src/plugin/quota.d.ts +0 -34
- package/dist/src/plugin/quota.js +0 -261
- package/dist/src/plugin/recovery/constants.d.ts +0 -21
- package/dist/src/plugin/recovery/constants.js +0 -42
- package/dist/src/plugin/recovery/index.d.ts +0 -11
- package/dist/src/plugin/recovery/index.js +0 -11
- package/dist/src/plugin/recovery/storage.d.ts +0 -23
- package/dist/src/plugin/recovery/storage.js +0 -340
- package/dist/src/plugin/recovery/types.d.ts +0 -115
- package/dist/src/plugin/recovery/types.js +0 -6
- package/dist/src/plugin/recovery.d.ts +0 -60
- package/dist/src/plugin/recovery.js +0 -360
- package/dist/src/plugin/refresh-queue.d.ts +0 -99
- package/dist/src/plugin/refresh-queue.js +0 -235
- package/dist/src/plugin/request-helpers.d.ts +0 -281
- package/dist/src/plugin/request-helpers.js +0 -2200
- package/dist/src/plugin/request.d.ts +0 -110
- package/dist/src/plugin/request.js +0 -1489
- package/dist/src/plugin/rotation.d.ts +0 -182
- package/dist/src/plugin/rotation.js +0 -364
- package/dist/src/plugin/search.d.ts +0 -31
- package/dist/src/plugin/search.js +0 -185
- package/dist/src/plugin/server.d.ts +0 -22
- package/dist/src/plugin/server.js +0 -306
- package/dist/src/plugin/storage.d.ts +0 -136
- package/dist/src/plugin/storage.js +0 -599
- package/dist/src/plugin/stores/signature-store.d.ts +0 -4
- package/dist/src/plugin/stores/signature-store.js +0 -24
- package/dist/src/plugin/thinking-recovery.d.ts +0 -89
- package/dist/src/plugin/thinking-recovery.js +0 -289
- package/dist/src/plugin/token.d.ts +0 -18
- package/dist/src/plugin/token.js +0 -127
- package/dist/src/plugin/transform/claude.d.ts +0 -79
- package/dist/src/plugin/transform/claude.js +0 -256
- package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +0 -34
- package/dist/src/plugin/transform/cross-model-sanitizer.js +0 -224
- package/dist/src/plugin/transform/gemini.d.ts +0 -132
- package/dist/src/plugin/transform/gemini.js +0 -659
- package/dist/src/plugin/transform/index.d.ts +0 -14
- package/dist/src/plugin/transform/index.js +0 -9
- package/dist/src/plugin/transform/model-resolver.d.ts +0 -98
- package/dist/src/plugin/transform/model-resolver.js +0 -320
- package/dist/src/plugin/transform/types.d.ts +0 -110
- package/dist/src/plugin/transform/types.js +0 -1
- package/dist/src/plugin/types.d.ts +0 -95
- package/dist/src/plugin/types.js +0 -1
- package/dist/src/plugin/ui/ansi.d.ts +0 -31
- package/dist/src/plugin/ui/ansi.js +0 -45
- package/dist/src/plugin/ui/auth-menu.d.ts +0 -47
- package/dist/src/plugin/ui/auth-menu.js +0 -199
- package/dist/src/plugin/ui/confirm.d.ts +0 -1
- package/dist/src/plugin/ui/confirm.js +0 -14
- package/dist/src/plugin/ui/select.d.ts +0 -22
- package/dist/src/plugin/ui/select.js +0 -243
- package/dist/src/plugin/version.d.ts +0 -18
- package/dist/src/plugin/version.js +0 -79
package/package.json
CHANGED
|
@@ -1,54 +1,66 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "antigravity-auth",
|
|
3
|
+
"version": "1.7.0",
|
|
4
|
+
"description": "Google Antigravity provider for OpenCode and Claude Code, built on core-auth — multi-account rotation, quota management, proxy support",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"antigravity": "dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "intisy",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/intisy/antigravity-auth.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"opencode",
|
|
18
|
+
"claude",
|
|
19
|
+
"antigravity",
|
|
20
|
+
"google",
|
|
21
|
+
"oauth",
|
|
22
|
+
"gemini",
|
|
23
|
+
"core-auth",
|
|
24
|
+
"provider"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20.0.0"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"claudeHub": {
|
|
35
|
+
"authProviders": [
|
|
36
|
+
{
|
|
37
|
+
"name": "antigravity",
|
|
38
|
+
"handler": "dist/handler.js",
|
|
39
|
+
"models": []
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "npx tsc --project core-auth/tsconfig.json && node build.mjs",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"prepublishOnly": "npm run build"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@openauthjs/openauth": "^0.4.3",
|
|
51
|
+
"@opencode-ai/plugin": "^0.15.30",
|
|
52
|
+
"proper-lockfile": "^4.1.2",
|
|
53
|
+
"xdg-basedir": "^5.1.0",
|
|
54
|
+
"zod": "^4.0.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^25.9.1",
|
|
58
|
+
"@types/proper-lockfile": "^4.1.4",
|
|
59
|
+
"esbuild": "^0.25.12",
|
|
60
|
+
"typescript": "^5.0.0",
|
|
61
|
+
"vitest": "^4.1.7"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"typescript": "^5"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Result returned to the caller after constructing an OAuth authorization URL.
|
|
3
|
-
*/
|
|
4
|
-
export interface AntigravityAuthorization {
|
|
5
|
-
url: string;
|
|
6
|
-
verifier: string;
|
|
7
|
-
projectId: string;
|
|
8
|
-
}
|
|
9
|
-
interface AntigravityTokenExchangeSuccess {
|
|
10
|
-
type: "success";
|
|
11
|
-
refresh: string;
|
|
12
|
-
access: string;
|
|
13
|
-
expires: number;
|
|
14
|
-
email?: string;
|
|
15
|
-
projectId: string;
|
|
16
|
-
}
|
|
17
|
-
interface AntigravityTokenExchangeFailure {
|
|
18
|
-
type: "failed";
|
|
19
|
-
error: string;
|
|
20
|
-
}
|
|
21
|
-
export type AntigravityTokenExchangeResult = AntigravityTokenExchangeSuccess | AntigravityTokenExchangeFailure;
|
|
22
|
-
/**
|
|
23
|
-
* Build the Antigravity OAuth authorization URL including PKCE and optional project metadata.
|
|
24
|
-
*/
|
|
25
|
-
export declare function authorizeAntigravity(projectId?: string): Promise<AntigravityAuthorization>;
|
|
26
|
-
/**
|
|
27
|
-
* Exchange an authorization code for Antigravity CLI access and refresh tokens.
|
|
28
|
-
*/
|
|
29
|
-
export declare function exchangeAntigravity(code: string, state: string): Promise<AntigravityTokenExchangeResult>;
|
|
30
|
-
export {};
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { generatePKCE } from "@openauthjs/openauth/pkce";
|
|
2
|
-
import { ANTIGRAVITY_CLIENT_ID, ANTIGRAVITY_CLIENT_SECRET, ANTIGRAVITY_REDIRECT_URI, ANTIGRAVITY_SCOPES, ANTIGRAVITY_ENDPOINT_FALLBACKS, ANTIGRAVITY_LOAD_ENDPOINTS, getAntigravityHeaders, GEMINI_CLI_HEADERS, } from "../constants";
|
|
3
|
-
import { createLogger } from "../plugin/logger";
|
|
4
|
-
import { calculateTokenExpiry } from "../plugin/auth";
|
|
5
|
-
const log = createLogger("oauth");
|
|
6
|
-
/**
|
|
7
|
-
* Encode an object into a URL-safe base64 string.
|
|
8
|
-
*/
|
|
9
|
-
function encodeState(payload) {
|
|
10
|
-
return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Decode an OAuth state parameter back into its structured representation.
|
|
14
|
-
*/
|
|
15
|
-
function decodeState(state) {
|
|
16
|
-
const normalized = state.replace(/-/g, "+").replace(/_/g, "/");
|
|
17
|
-
const padded = normalized.padEnd(normalized.length + ((4 - normalized.length % 4) % 4), "=");
|
|
18
|
-
const json = Buffer.from(padded, "base64").toString("utf8");
|
|
19
|
-
const parsed = JSON.parse(json);
|
|
20
|
-
if (typeof parsed.verifier !== "string") {
|
|
21
|
-
throw new Error("Missing PKCE verifier in state");
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
verifier: parsed.verifier,
|
|
25
|
-
projectId: typeof parsed.projectId === "string" ? parsed.projectId : "",
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Build the Antigravity OAuth authorization URL including PKCE and optional project metadata.
|
|
30
|
-
*/
|
|
31
|
-
export async function authorizeAntigravity(projectId = "") {
|
|
32
|
-
const pkce = (await generatePKCE());
|
|
33
|
-
const url = new URL("https://accounts.google.com/o/oauth2/v2/auth");
|
|
34
|
-
url.searchParams.set("client_id", ANTIGRAVITY_CLIENT_ID);
|
|
35
|
-
url.searchParams.set("response_type", "code");
|
|
36
|
-
url.searchParams.set("redirect_uri", ANTIGRAVITY_REDIRECT_URI);
|
|
37
|
-
url.searchParams.set("scope", ANTIGRAVITY_SCOPES.join(" "));
|
|
38
|
-
url.searchParams.set("code_challenge", pkce.challenge);
|
|
39
|
-
url.searchParams.set("code_challenge_method", "S256");
|
|
40
|
-
url.searchParams.set("state", encodeState({ verifier: pkce.verifier, projectId: projectId || "" }));
|
|
41
|
-
url.searchParams.set("access_type", "offline");
|
|
42
|
-
url.searchParams.set("prompt", "consent");
|
|
43
|
-
return {
|
|
44
|
-
url: url.toString(),
|
|
45
|
-
verifier: pkce.verifier,
|
|
46
|
-
projectId: projectId || "",
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const FETCH_TIMEOUT_MS = 10000;
|
|
50
|
-
async function fetchWithTimeout(url, options, timeoutMs = FETCH_TIMEOUT_MS) {
|
|
51
|
-
const controller = new AbortController();
|
|
52
|
-
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
53
|
-
try {
|
|
54
|
-
return await fetch(url, { ...options, signal: controller.signal });
|
|
55
|
-
}
|
|
56
|
-
finally {
|
|
57
|
-
clearTimeout(timeout);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async function fetchProjectID(accessToken) {
|
|
61
|
-
const errors = [];
|
|
62
|
-
const loadHeaders = {
|
|
63
|
-
Authorization: `Bearer ${accessToken}`,
|
|
64
|
-
"Content-Type": "application/json",
|
|
65
|
-
"User-Agent": GEMINI_CLI_HEADERS["User-Agent"],
|
|
66
|
-
"Client-Metadata": getAntigravityHeaders()["Client-Metadata"],
|
|
67
|
-
};
|
|
68
|
-
const loadEndpoints = Array.from(new Set([...ANTIGRAVITY_LOAD_ENDPOINTS, ...ANTIGRAVITY_ENDPOINT_FALLBACKS]));
|
|
69
|
-
for (const baseEndpoint of loadEndpoints) {
|
|
70
|
-
try {
|
|
71
|
-
const url = `${baseEndpoint}/v1internal:loadCodeAssist`;
|
|
72
|
-
const response = await fetchWithTimeout(url, {
|
|
73
|
-
method: "POST",
|
|
74
|
-
headers: loadHeaders,
|
|
75
|
-
body: JSON.stringify({
|
|
76
|
-
metadata: {
|
|
77
|
-
ideType: "ANTIGRAVITY",
|
|
78
|
-
platform: process.platform === "win32" ? "WINDOWS" : "MACOS",
|
|
79
|
-
pluginType: "GEMINI",
|
|
80
|
-
},
|
|
81
|
-
}),
|
|
82
|
-
});
|
|
83
|
-
if (!response.ok) {
|
|
84
|
-
const message = await response.text().catch(() => "");
|
|
85
|
-
errors.push(`loadCodeAssist ${response.status} at ${baseEndpoint}${message ? `: ${message}` : ""}`);
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const data = await response.json();
|
|
89
|
-
if (typeof data.cloudaicompanionProject === "string" && data.cloudaicompanionProject) {
|
|
90
|
-
return data.cloudaicompanionProject;
|
|
91
|
-
}
|
|
92
|
-
if (data.cloudaicompanionProject &&
|
|
93
|
-
typeof data.cloudaicompanionProject.id === "string" &&
|
|
94
|
-
data.cloudaicompanionProject.id) {
|
|
95
|
-
return data.cloudaicompanionProject.id;
|
|
96
|
-
}
|
|
97
|
-
errors.push(`loadCodeAssist missing project id at ${baseEndpoint}`);
|
|
98
|
-
}
|
|
99
|
-
catch (e) {
|
|
100
|
-
errors.push(`loadCodeAssist error at ${baseEndpoint}: ${e instanceof Error ? e.message : String(e)}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (errors.length) {
|
|
104
|
-
log.warn("Failed to resolve Antigravity project via loadCodeAssist", { errors: errors.join("; ") });
|
|
105
|
-
}
|
|
106
|
-
return "";
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Exchange an authorization code for Antigravity CLI access and refresh tokens.
|
|
110
|
-
*/
|
|
111
|
-
export async function exchangeAntigravity(code, state) {
|
|
112
|
-
try {
|
|
113
|
-
const { verifier, projectId } = decodeState(state);
|
|
114
|
-
const startTime = Date.now();
|
|
115
|
-
const tokenResponse = await fetch("https://oauth2.googleapis.com/token", {
|
|
116
|
-
method: "POST",
|
|
117
|
-
headers: {
|
|
118
|
-
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
119
|
-
"Accept": "*/*",
|
|
120
|
-
"Accept-Encoding": "gzip, deflate, br",
|
|
121
|
-
"User-Agent": GEMINI_CLI_HEADERS["User-Agent"],
|
|
122
|
-
},
|
|
123
|
-
body: new URLSearchParams({
|
|
124
|
-
client_id: ANTIGRAVITY_CLIENT_ID,
|
|
125
|
-
client_secret: ANTIGRAVITY_CLIENT_SECRET,
|
|
126
|
-
code,
|
|
127
|
-
grant_type: "authorization_code",
|
|
128
|
-
redirect_uri: ANTIGRAVITY_REDIRECT_URI,
|
|
129
|
-
code_verifier: verifier,
|
|
130
|
-
}),
|
|
131
|
-
});
|
|
132
|
-
if (!tokenResponse.ok) {
|
|
133
|
-
const errorText = await tokenResponse.text();
|
|
134
|
-
return { type: "failed", error: errorText };
|
|
135
|
-
}
|
|
136
|
-
const tokenPayload = (await tokenResponse.json());
|
|
137
|
-
const userInfoResponse = await fetch("https://www.googleapis.com/oauth2/v1/userinfo?alt=json", {
|
|
138
|
-
headers: {
|
|
139
|
-
Authorization: `Bearer ${tokenPayload.access_token}`,
|
|
140
|
-
"User-Agent": GEMINI_CLI_HEADERS["User-Agent"],
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
const userInfo = userInfoResponse.ok
|
|
144
|
-
? (await userInfoResponse.json())
|
|
145
|
-
: {};
|
|
146
|
-
const refreshToken = tokenPayload.refresh_token;
|
|
147
|
-
if (!refreshToken) {
|
|
148
|
-
return { type: "failed", error: "Missing refresh token in response" };
|
|
149
|
-
}
|
|
150
|
-
let effectiveProjectId = projectId;
|
|
151
|
-
if (!effectiveProjectId) {
|
|
152
|
-
effectiveProjectId = await fetchProjectID(tokenPayload.access_token);
|
|
153
|
-
}
|
|
154
|
-
const storedRefresh = `${refreshToken}|${effectiveProjectId || ""}`;
|
|
155
|
-
return {
|
|
156
|
-
type: "success",
|
|
157
|
-
refresh: storedRefresh,
|
|
158
|
-
access: tokenPayload.access_token,
|
|
159
|
-
expires: calculateTokenExpiry(startTime, tokenPayload.expires_in),
|
|
160
|
-
email: userInfo.email,
|
|
161
|
-
projectId: effectiveProjectId || "",
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
return {
|
|
166
|
-
type: "failed",
|
|
167
|
-
error: error instanceof Error ? error.message : "Unknown error",
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|