Files
OmniRoute/open-sse/services/antigravityProjectPersist.ts
2026-07-26 03:52:54 -03:00

43 lines
1.7 KiB
TypeScript

/**
* Persist a runtime-discovered Antigravity projectId back onto its connection row
* (#8491).
*
* `ensureAntigravityProjectAssigned()` recovers a missing projectId via a
* `loadCodeAssist` round-trip and hands it back to the caller for the in-flight
* request only — nothing wrote it back to the connection record, so every
* subsequent token refresh (or process restart) lost the discovery and forced a
* fresh round-trip. This module is the single best-effort write path both call
* sites (`open-sse/executors/antigravity.ts` and the models-discovery
* normalizer) funnel through, mirroring the shape `mapAntigravityTokens()`
* already persists at OAuth-exchange time (`src/lib/oauth/providers/antigravity.ts`).
*/
import { updateProviderConnection } from "@/lib/db/providers";
/**
* Write `discoveredProjectId` onto both the `projectId` column and
* `providerSpecificData.projectId` for `connectionId`, preserving any other
* `providerSpecificData` fields already on the connection.
*
* Best-effort / non-fatal by design: a persistence failure must never block
* the in-flight request, which already has the discovered id in hand.
*/
export async function persistDiscoveredAntigravityProjectId(
connectionId: string | undefined | null,
discoveredProjectId: string | undefined | null,
existingProviderSpecificData?: Record<string, unknown> | null
): Promise<void> {
if (!connectionId || !discoveredProjectId) return;
try {
await updateProviderConnection(connectionId, {
projectId: discoveredProjectId,
providerSpecificData: {
...(existingProviderSpecificData || {}),
projectId: discoveredProjectId,
},
});
} catch {
// Non-fatal: persistence failure must never block the in-flight request.
}
}