opencode-antigravity-auth 1.0.1 → 1.0.3

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
@@ -17,7 +17,7 @@ Enable Opencode to authenticate against **Antigravity** (Google's IDE) via OAuth
17
17
 
18
18
  ```json
19
19
  {
20
- "plugin": ["opencode-antigravity-auth"]
20
+ "plugin": ["opencode-antigravity-auth@1.0.3"]
21
21
  }
22
22
  ```
23
23
 
package/package.json CHANGED
@@ -1,23 +1,56 @@
1
1
  {
2
2
  "name": "opencode-antigravity-auth",
3
- "module": "index.ts",
4
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
+ "description": "Google Antigravity IDE OAuth auth plugin for Opencode - access Gemini 3 Pro and Claude 4.5 using Google credentials",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "license": "MIT",
5
9
  "author": "noefabris",
6
- "repository": "https://github.com/NoeFabris/opencode-antigravity-auth",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/NoeFabris/opencode-antigravity-auth.git"
13
+ },
14
+ "homepage": "https://github.com/NoeFabris/opencode-antigravity-auth#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/NoeFabris/opencode-antigravity-auth/issues"
17
+ },
18
+ "keywords": [
19
+ "opencode",
20
+ "google",
21
+ "antigravity",
22
+ "gemini",
23
+ "oauth",
24
+ "plugin",
25
+ "auth",
26
+ "claude"
27
+ ],
28
+ "engines": {
29
+ "node": ">=20.0.0"
30
+ },
7
31
  "files": [
8
- "index.ts",
9
- "src"
32
+ "dist/",
33
+ "README.md",
34
+ "LICENSE"
10
35
  ],
11
- "license": "MIT",
12
- "type": "module",
13
- "devDependencies": {
14
- "@opencode-ai/plugin": "^0.15.30",
15
- "@types/bun": "latest",
16
- "@types/node": "^24.10.1"
36
+ "scripts": {
37
+ "build": "tsc",
38
+ "typecheck": "tsc --noEmit",
39
+ "test": "vitest run",
40
+ "test:watch": "vitest",
41
+ "test:ui": "vitest --ui",
42
+ "test:coverage": "vitest run --coverage"
17
43
  },
18
44
  "peerDependencies": {
19
45
  "typescript": "^5"
20
46
  },
47
+ "devDependencies": {
48
+ "@opencode-ai/plugin": "^0.15.30",
49
+ "@types/node": "^24.10.1",
50
+ "@vitest/ui": "^3.0.0",
51
+ "typescript": "^5.0.0",
52
+ "vitest": "^3.0.0"
53
+ },
21
54
  "dependencies": {
22
55
  "@openauthjs/openauth": "^0.4.3"
23
56
  }
package/index.ts DELETED
@@ -1,14 +0,0 @@
1
- export {
2
- AntigravityCLIOAuthPlugin,
3
- GoogleOAuthPlugin,
4
- } from "./src/plugin";
5
-
6
- export {
7
- authorizeAntigravity,
8
- exchangeAntigravity,
9
- } from "./src/antigravity/oauth";
10
-
11
- export type {
12
- AntigravityAuthorization,
13
- AntigravityTokenExchangeResult,
14
- } from "./src/antigravity/oauth";
@@ -1,250 +0,0 @@
1
- import { generatePKCE } from "@openauthjs/openauth/pkce";
2
-
3
- import {
4
- ANTIGRAVITY_CLIENT_ID,
5
- ANTIGRAVITY_CLIENT_SECRET,
6
- ANTIGRAVITY_REDIRECT_URI,
7
- ANTIGRAVITY_SCOPES,
8
- ANTIGRAVITY_ENDPOINT_FALLBACKS,
9
- ANTIGRAVITY_LOAD_ENDPOINTS,
10
- ANTIGRAVITY_HEADERS,
11
- } from "../constants";
12
-
13
- interface PkcePair {
14
- challenge: string;
15
- verifier: string;
16
- }
17
-
18
- interface AntigravityAuthState {
19
- verifier: string;
20
- projectId: string;
21
- }
22
-
23
- /**
24
- * Result returned to the caller after constructing an OAuth authorization URL.
25
- */
26
- export interface AntigravityAuthorization {
27
- url: string;
28
- verifier: string;
29
- projectId: string;
30
- }
31
-
32
- interface AntigravityTokenExchangeSuccess {
33
- type: "success";
34
- refresh: string;
35
- access: string;
36
- expires: number;
37
- email?: string;
38
- projectId: string;
39
- }
40
-
41
- interface AntigravityTokenExchangeFailure {
42
- type: "failed";
43
- error: string;
44
- }
45
-
46
- export type AntigravityTokenExchangeResult =
47
- | AntigravityTokenExchangeSuccess
48
- | AntigravityTokenExchangeFailure;
49
-
50
- interface AntigravityTokenResponse {
51
- access_token: string;
52
- expires_in: number;
53
- refresh_token: string;
54
- }
55
-
56
- interface AntigravityUserInfo {
57
- email?: string;
58
- }
59
-
60
- /**
61
- * Encode an object into a URL-safe base64 string.
62
- */
63
- function encodeState(payload: AntigravityAuthState): string {
64
- return Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
65
- }
66
-
67
- /**
68
- * Decode an OAuth state parameter back into its structured representation.
69
- */
70
- function decodeState(state: string): AntigravityAuthState {
71
- const normalized = state.replace(/-/g, "+").replace(/_/g, "/");
72
- const padded = normalized.padEnd(normalized.length + ((4 - normalized.length % 4) % 4), "=");
73
- const json = Buffer.from(padded, "base64").toString("utf8");
74
- const parsed = JSON.parse(json);
75
- if (typeof parsed.verifier !== "string") {
76
- throw new Error("Missing PKCE verifier in state");
77
- }
78
- return {
79
- verifier: parsed.verifier,
80
- projectId: typeof parsed.projectId === "string" ? parsed.projectId : "",
81
- };
82
- }
83
-
84
- /**
85
- * Build the Antigravity OAuth authorization URL including PKCE and optional project metadata.
86
- */
87
- export async function authorizeAntigravity(projectId = ""): Promise<AntigravityAuthorization> {
88
- const pkce = (await generatePKCE()) as PkcePair;
89
-
90
- const url = new URL("https://accounts.google.com/o/oauth2/v2/auth");
91
- url.searchParams.set("client_id", ANTIGRAVITY_CLIENT_ID);
92
- url.searchParams.set("response_type", "code");
93
- url.searchParams.set("redirect_uri", ANTIGRAVITY_REDIRECT_URI);
94
- url.searchParams.set("scope", ANTIGRAVITY_SCOPES.join(" "));
95
- url.searchParams.set("code_challenge", pkce.challenge);
96
- url.searchParams.set("code_challenge_method", "S256");
97
- url.searchParams.set(
98
- "state",
99
- encodeState({ verifier: pkce.verifier, projectId: projectId || "" }),
100
- );
101
- url.searchParams.set("access_type", "offline");
102
- url.searchParams.set("prompt", "consent");
103
-
104
- return {
105
- url: url.toString(),
106
- verifier: pkce.verifier,
107
- projectId: projectId || "",
108
- };
109
- }
110
-
111
- async function fetchProjectID(accessToken: string): Promise<string> {
112
- const errors: string[] = [];
113
- // Use CLIProxy-aligned headers for project discovery to match "real" Antigravity clients.
114
- const loadHeaders: Record<string, string> = {
115
- Authorization: `Bearer ${accessToken}`,
116
- "Content-Type": "application/json",
117
- "User-Agent": "google-api-nodejs-client/9.15.1",
118
- "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
119
- "Client-Metadata": ANTIGRAVITY_HEADERS["Client-Metadata"],
120
- };
121
-
122
- const loadEndpoints = Array.from(
123
- new Set<string>([...ANTIGRAVITY_LOAD_ENDPOINTS, ...ANTIGRAVITY_ENDPOINT_FALLBACKS]),
124
- );
125
-
126
- for (const baseEndpoint of loadEndpoints) {
127
- try {
128
- const url = `${baseEndpoint}/v1internal:loadCodeAssist`;
129
- const response = await fetch(url, {
130
- method: "POST",
131
- headers: loadHeaders,
132
- body: JSON.stringify({
133
- metadata: {
134
- ideType: "IDE_UNSPECIFIED",
135
- platform: "PLATFORM_UNSPECIFIED",
136
- pluginType: "GEMINI",
137
- },
138
- }),
139
- });
140
-
141
- if (!response.ok) {
142
- const message = await response.text().catch(() => "");
143
- errors.push(
144
- `loadCodeAssist ${response.status} at ${baseEndpoint}${
145
- message ? `: ${message}` : ""
146
- }`,
147
- );
148
- continue;
149
- }
150
-
151
- const data = await response.json();
152
- if (typeof data.cloudaicompanionProject === "string" && data.cloudaicompanionProject) {
153
- return data.cloudaicompanionProject;
154
- }
155
- if (
156
- data.cloudaicompanionProject &&
157
- typeof data.cloudaicompanionProject.id === "string" &&
158
- data.cloudaicompanionProject.id
159
- ) {
160
- return data.cloudaicompanionProject.id;
161
- }
162
-
163
- errors.push(`loadCodeAssist missing project id at ${baseEndpoint}`);
164
- } catch (e) {
165
- errors.push(
166
- `loadCodeAssist error at ${baseEndpoint}: ${
167
- e instanceof Error ? e.message : String(e)
168
- }`,
169
- );
170
- }
171
- }
172
-
173
- if (errors.length) {
174
- console.warn("Failed to resolve Antigravity project via loadCodeAssist:", errors.join("; "));
175
- }
176
- return "";
177
- }
178
-
179
- /**
180
- * Exchange an authorization code for Antigravity CLI access and refresh tokens.
181
- */
182
- export async function exchangeAntigravity(
183
- code: string,
184
- state: string,
185
- ): Promise<AntigravityTokenExchangeResult> {
186
- try {
187
- const { verifier, projectId } = decodeState(state);
188
-
189
- const tokenResponse = await fetch("https://oauth2.googleapis.com/token", {
190
- method: "POST",
191
- headers: {
192
- "Content-Type": "application/x-www-form-urlencoded",
193
- },
194
- body: new URLSearchParams({
195
- client_id: ANTIGRAVITY_CLIENT_ID,
196
- client_secret: ANTIGRAVITY_CLIENT_SECRET,
197
- code,
198
- grant_type: "authorization_code",
199
- redirect_uri: ANTIGRAVITY_REDIRECT_URI,
200
- code_verifier: verifier,
201
- }),
202
- });
203
-
204
- if (!tokenResponse.ok) {
205
- const errorText = await tokenResponse.text();
206
- return { type: "failed", error: errorText };
207
- }
208
-
209
- const tokenPayload = (await tokenResponse.json()) as AntigravityTokenResponse;
210
-
211
- const userInfoResponse = await fetch(
212
- "https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
213
- {
214
- headers: {
215
- Authorization: `Bearer ${tokenPayload.access_token}`,
216
- },
217
- },
218
- );
219
-
220
- const userInfo = userInfoResponse.ok
221
- ? ((await userInfoResponse.json()) as AntigravityUserInfo)
222
- : {};
223
-
224
- const refreshToken = tokenPayload.refresh_token;
225
- if (!refreshToken) {
226
- return { type: "failed", error: "Missing refresh token in response" };
227
- }
228
-
229
- let effectiveProjectId = projectId;
230
- if (!effectiveProjectId) {
231
- effectiveProjectId = await fetchProjectID(tokenPayload.access_token);
232
- }
233
-
234
- const storedRefresh = `${refreshToken}|${effectiveProjectId || ""}`;
235
-
236
- return {
237
- type: "success",
238
- refresh: storedRefresh,
239
- access: tokenPayload.access_token,
240
- expires: Date.now() + tokenPayload.expires_in * 1000,
241
- email: userInfo.email,
242
- projectId: effectiveProjectId || "",
243
- };
244
- } catch (error) {
245
- return {
246
- type: "failed",
247
- error: error instanceof Error ? error.message : "Unknown error",
248
- };
249
- }
250
- }
package/src/constants.ts DELETED
@@ -1,75 +0,0 @@
1
- /**
2
- * Constants used for Antigravity OAuth flows and Cloud Code Assist API integration.
3
- */
4
- export const ANTIGRAVITY_CLIENT_ID = "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com";
5
-
6
- /**
7
- * Client secret issued for the Antigravity OAuth application.
8
- */
9
- export const ANTIGRAVITY_CLIENT_SECRET = "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";
10
-
11
- /**
12
- * Scopes required for Antigravity integrations.
13
- */
14
- export const ANTIGRAVITY_SCOPES: readonly string[] = [
15
- "https://www.googleapis.com/auth/cloud-platform",
16
- "https://www.googleapis.com/auth/userinfo.email",
17
- "https://www.googleapis.com/auth/userinfo.profile",
18
- "https://www.googleapis.com/auth/cclog",
19
- "https://www.googleapis.com/auth/experimentsandconfigs",
20
- ];
21
-
22
- /**
23
- * OAuth redirect URI used by the local CLI callback server.
24
- */
25
- export const ANTIGRAVITY_REDIRECT_URI = "http://localhost:51121/oauth-callback";
26
-
27
- /**
28
- * Root endpoints for the Antigravity API (in fallback order).
29
- * CLIProxy and Vibeproxy use the daily sandbox endpoint first,
30
- * then fallback to autopush and prod if needed.
31
- */
32
- export const ANTIGRAVITY_ENDPOINT_DAILY = "https://daily-cloudcode-pa.sandbox.googleapis.com";
33
- export const ANTIGRAVITY_ENDPOINT_AUTOPUSH = "https://autopush-cloudcode-pa.sandbox.googleapis.com";
34
- export const ANTIGRAVITY_ENDPOINT_PROD = "https://cloudcode-pa.googleapis.com";
35
-
36
- /**
37
- * Endpoint fallback order (daily → autopush → prod).
38
- * Shared across request handling and project discovery to mirror CLIProxy behavior.
39
- */
40
- export const ANTIGRAVITY_ENDPOINT_FALLBACKS = [
41
- ANTIGRAVITY_ENDPOINT_DAILY,
42
- ANTIGRAVITY_ENDPOINT_AUTOPUSH,
43
- ANTIGRAVITY_ENDPOINT_PROD,
44
- ] as const;
45
-
46
- /**
47
- * Preferred endpoint order for project discovery (prod first, then fallbacks).
48
- * loadCodeAssist appears to be best supported on prod for managed project resolution.
49
- */
50
- export const ANTIGRAVITY_LOAD_ENDPOINTS = [
51
- ANTIGRAVITY_ENDPOINT_PROD,
52
- ANTIGRAVITY_ENDPOINT_DAILY,
53
- ANTIGRAVITY_ENDPOINT_AUTOPUSH,
54
- ] as const;
55
-
56
- /**
57
- * Primary endpoint to use (daily sandbox - same as CLIProxy/Vibeproxy).
58
- */
59
- export const ANTIGRAVITY_ENDPOINT = ANTIGRAVITY_ENDPOINT_DAILY;
60
-
61
- /**
62
- * Hardcoded project id used when Antigravity does not return one (e.g., business/workspace accounts).
63
- */
64
- export const ANTIGRAVITY_DEFAULT_PROJECT_ID = "rising-fact-p41fc";
65
-
66
- export const ANTIGRAVITY_HEADERS = {
67
- "User-Agent": "antigravity/1.11.5 windows/amd64",
68
- "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
69
- "Client-Metadata": '{"ideType":"IDE_UNSPECIFIED","platform":"PLATFORM_UNSPECIFIED","pluginType":"GEMINI"}',
70
- } as const;
71
-
72
- /**
73
- * Provider identifier shared between the plugin loader and credential store.
74
- */
75
- export const ANTIGRAVITY_PROVIDER_ID = "google";
@@ -1,38 +0,0 @@
1
- import type { AuthDetails, OAuthAuthDetails, RefreshParts } from "./types";
2
-
3
- const ACCESS_TOKEN_EXPIRY_BUFFER_MS = 60 * 1000;
4
-
5
- export function isOAuthAuth(auth: AuthDetails): auth is OAuthAuthDetails {
6
- return auth.type === "oauth";
7
- }
8
-
9
- /**
10
- * Splits a packed refresh string into its constituent refresh token and project IDs.
11
- */
12
- export function parseRefreshParts(refresh: string): RefreshParts {
13
- const [refreshToken = "", projectId = "", managedProjectId = ""] = (refresh ?? "").split("|");
14
- return {
15
- refreshToken,
16
- projectId: projectId || undefined,
17
- managedProjectId: managedProjectId || undefined,
18
- };
19
- }
20
-
21
- /**
22
- * Serializes refresh token parts into the stored string format.
23
- */
24
- export function formatRefreshParts(parts: RefreshParts): string {
25
- const projectSegment = parts.projectId ?? "";
26
- const base = `${parts.refreshToken}|${projectSegment}`;
27
- return parts.managedProjectId ? `${base}|${parts.managedProjectId}` : base;
28
- }
29
-
30
- /**
31
- * Determines whether an access token is expired or missing, with buffer for clock skew.
32
- */
33
- export function accessTokenExpired(auth: OAuthAuthDetails): boolean {
34
- if (!auth.access || typeof auth.expires !== "number") {
35
- return true;
36
- }
37
- return auth.expires <= Date.now() + ACCESS_TOKEN_EXPIRY_BUFFER_MS;
38
- }
@@ -1,65 +0,0 @@
1
- import { accessTokenExpired } from "./auth";
2
- import type { OAuthAuthDetails } from "./types";
3
-
4
- const authCache = new Map<string, OAuthAuthDetails>();
5
-
6
- /**
7
- * Produces a stable cache key from a refresh token string.
8
- */
9
- function normalizeRefreshKey(refresh?: string): string | undefined {
10
- const key = refresh?.trim();
11
- return key ? key : undefined;
12
- }
13
-
14
- /**
15
- * Returns a cached auth snapshot when available, favoring unexpired tokens.
16
- */
17
- export function resolveCachedAuth(auth: OAuthAuthDetails): OAuthAuthDetails {
18
- const key = normalizeRefreshKey(auth.refresh);
19
- if (!key) {
20
- return auth;
21
- }
22
-
23
- const cached = authCache.get(key);
24
- if (!cached) {
25
- authCache.set(key, auth);
26
- return auth;
27
- }
28
-
29
- if (!accessTokenExpired(auth)) {
30
- authCache.set(key, auth);
31
- return auth;
32
- }
33
-
34
- if (!accessTokenExpired(cached)) {
35
- return cached;
36
- }
37
-
38
- authCache.set(key, auth);
39
- return auth;
40
- }
41
-
42
- /**
43
- * Stores the latest auth snapshot keyed by refresh token.
44
- */
45
- export function storeCachedAuth(auth: OAuthAuthDetails): void {
46
- const key = normalizeRefreshKey(auth.refresh);
47
- if (!key) {
48
- return;
49
- }
50
- authCache.set(key, auth);
51
- }
52
-
53
- /**
54
- * Clears cached auth globally or for a specific refresh token.
55
- */
56
- export function clearCachedAuth(refresh?: string): void {
57
- if (!refresh) {
58
- authCache.clear();
59
- return;
60
- }
61
- const key = normalizeRefreshKey(refresh);
62
- if (key) {
63
- authCache.delete(key);
64
- }
65
- }
package/src/plugin/cli.ts DELETED
@@ -1,15 +0,0 @@
1
- import { createInterface } from "node:readline/promises";
2
- import { stdin as input, stdout as output } from "node:process";
3
-
4
- /**
5
- * Prompts the user for a project ID via stdin/stdout.
6
- */
7
- export async function promptProjectId(): Promise<string> {
8
- const rl = createInterface({ input, output });
9
- try {
10
- const answer = await rl.question("Project ID (leave blank to use your default project): ");
11
- return answer.trim();
12
- } finally {
13
- rl.close();
14
- }
15
- }