(accessToken: string)
| 77 | } |
| 78 | |
| 79 | async function fetchProjectID(accessToken: string): Promise<string> { |
| 80 | const errors: string[] = []; |
| 81 | // Use CLIProxy-aligned headers for project discovery to match "real" Antigravity clients. |
| 82 | const loadHeaders: Record<string, string> = { |
| 83 | Authorization: `Bearer ${accessToken}`, |
| 84 | "Content-Type": "application/json", |
| 85 | "User-Agent": "google-api-nodejs-client/9.15.1", |
| 86 | "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1", |
| 87 | "Client-Metadata": ANTIGRAVITY_HEADERS["Client-Metadata"], |
| 88 | }; |
| 89 | |
| 90 | const loadEndpoints = Array.from( |
| 91 | new Set<string>([...ANTIGRAVITY_LOAD_ENDPOINTS, ...ANTIGRAVITY_ENDPOINT_FALLBACKS]), |
| 92 | ); |
| 93 | |
| 94 | for (const baseEndpoint of loadEndpoints) { |
| 95 | try { |
| 96 | const url = `${baseEndpoint}/v1internal:loadCodeAssist`; |
| 97 | const response = await fetch(url, { |
| 98 | method: "POST", |
| 99 | headers: loadHeaders, |
| 100 | body: JSON.stringify({ |
| 101 | metadata: { |
| 102 | ideType: "IDE_UNSPECIFIED", |
| 103 | platform: "PLATFORM_UNSPECIFIED", |
| 104 | pluginType: "GEMINI", |
| 105 | }, |
| 106 | }), |
| 107 | }); |
| 108 | |
| 109 | if (!response.ok) { |
| 110 | const message = await response.text().catch(() => ""); |
| 111 | errors.push( |
| 112 | `loadCodeAssist ${response.status} at ${baseEndpoint}${ |
| 113 | message ? `: ${message}` : "" |
| 114 | }`, |
| 115 | ); |
| 116 | continue; |
| 117 | } |
| 118 | |
| 119 | const data = await response.json(); |
| 120 | if (typeof data.cloudaicompanionProject === "string" && data.cloudaicompanionProject) { |
| 121 | return data.cloudaicompanionProject; |
| 122 | } |
| 123 | if ( |
| 124 | data.cloudaicompanionProject && |
| 125 | typeof data.cloudaicompanionProject.id === "string" && |
| 126 | data.cloudaicompanionProject.id |
| 127 | ) { |
| 128 | return data.cloudaicompanionProject.id; |
| 129 | } |
| 130 | |
| 131 | errors.push(`loadCodeAssist missing project id at ${baseEndpoint}`); |
| 132 | } catch (e) { |
| 133 | errors.push( |
| 134 | `loadCodeAssist error at ${baseEndpoint}: ${ |
| 135 | e instanceof Error ? e.message : String(e) |
| 136 | }`, |
no test coverage detected