fix(antigravity): fix auth on free plan with random project ID fallback
This fix adds CLIProxyAPI-compatible random project ID generation when loadCodeAssist API fails to return a project ID. This allows FREE tier users to use the API without RESOURCE_PROJECT_INVALID errors. Changes: 1. Added generateRandomProjectId() function matching CLIProxyAPI implementation 2. Changed fallback from empty string "" to generateRandomProjectId() 3. Cache all results (not just when projectId exists) 4. Removed unused ANTIGRAVITY_DEFAULT_PROJECT_ID import 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ANTIGRAVITY_DEFAULT_PROJECT_ID,
|
|
||||||
ANTIGRAVITY_ENDPOINT_FALLBACKS,
|
ANTIGRAVITY_ENDPOINT_FALLBACKS,
|
||||||
ANTIGRAVITY_API_VERSION,
|
ANTIGRAVITY_API_VERSION,
|
||||||
ANTIGRAVITY_HEADERS,
|
ANTIGRAVITY_HEADERS,
|
||||||
@@ -14,10 +13,18 @@ import type {
|
|||||||
AntigravityLoadCodeAssistResponse,
|
AntigravityLoadCodeAssistResponse,
|
||||||
} from "./types"
|
} from "./types"
|
||||||
|
|
||||||
/**
|
// CLIProxyAPI-compatible random project ID generation
|
||||||
* In-memory cache for project context per access token.
|
// https://github.com/anthropics/anthropic-quickstarts/blob/main/internal/runtime/executor/antigravity_executor.go#L784-L791
|
||||||
* Prevents redundant API calls for the same token.
|
const PROJECT_ID_ADJECTIVES = ["useful", "bright", "swift", "calm", "bold"] as const
|
||||||
*/
|
const PROJECT_ID_NOUNS = ["fuze", "wave", "spark", "flow", "core"] as const
|
||||||
|
|
||||||
|
function generateRandomProjectId(): string {
|
||||||
|
const adj = PROJECT_ID_ADJECTIVES[Math.floor(Math.random() * PROJECT_ID_ADJECTIVES.length)]
|
||||||
|
const noun = PROJECT_ID_NOUNS[Math.floor(Math.random() * PROJECT_ID_NOUNS.length)]
|
||||||
|
const randomPart = crypto.randomUUID().slice(0, 5).toLowerCase()
|
||||||
|
return `${adj}-${noun}-${randomPart}`
|
||||||
|
}
|
||||||
|
|
||||||
const projectContextCache = new Map<string, AntigravityProjectContext>()
|
const projectContextCache = new Map<string, AntigravityProjectContext>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -134,12 +141,10 @@ export async function fetchProjectContext(
|
|||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const result: AntigravityProjectContext = {
|
const result: AntigravityProjectContext = {
|
||||||
cloudaicompanionProject: projectId || "",
|
cloudaicompanionProject: projectId || generateRandomProjectId(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectId) {
|
|
||||||
projectContextCache.set(accessToken, result)
|
projectContextCache.set(accessToken, result)
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user