2025-12-25 08:39:48 -08:00
|
|
|
/**
|
|
|
|
|
* Admin Gemini API endpoints
|
|
|
|
|
* Handles Gemini OAuth flows for administrators
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { apiClient } from '../client'
|
|
|
|
|
|
|
|
|
|
export interface GeminiAuthUrlResponse {
|
|
|
|
|
auth_url: string
|
|
|
|
|
session_id: string
|
|
|
|
|
state: string
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-25 23:52:26 -08:00
|
|
|
export interface GeminiOAuthCapabilities {
|
|
|
|
|
ai_studio_oauth_enabled: boolean
|
|
|
|
|
required_redirect_uris: string[]
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-25 08:39:48 -08:00
|
|
|
export interface GeminiAuthUrlRequest {
|
|
|
|
|
proxy_id?: number
|
2025-12-25 21:25:02 -08:00
|
|
|
project_id?: string
|
2026-01-03 06:32:04 -08:00
|
|
|
oauth_type?: 'code_assist' | 'google_one' | 'ai_studio'
|
2026-01-04 15:36:00 +08:00
|
|
|
tier_id?: string
|
2025-12-25 08:39:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface GeminiExchangeCodeRequest {
|
|
|
|
|
session_id: string
|
|
|
|
|
state: string
|
|
|
|
|
code: string
|
|
|
|
|
proxy_id?: number
|
2026-01-03 06:32:04 -08:00
|
|
|
oauth_type?: 'code_assist' | 'google_one' | 'ai_studio'
|
2026-01-04 15:36:00 +08:00
|
|
|
tier_id?: string
|
2025-12-25 08:39:48 -08:00
|
|
|
}
|
|
|
|
|
|
2026-01-03 06:32:04 -08:00
|
|
|
export type GeminiTokenInfo = {
|
|
|
|
|
access_token?: string
|
|
|
|
|
refresh_token?: string
|
|
|
|
|
token_type?: string
|
|
|
|
|
scope?: string
|
|
|
|
|
expires_in?: number
|
|
|
|
|
expires_at?: number
|
|
|
|
|
project_id?: string
|
|
|
|
|
oauth_type?: string
|
|
|
|
|
tier_id?: string
|
|
|
|
|
extra?: Record<string, unknown>
|
|
|
|
|
[key: string]: unknown
|
|
|
|
|
}
|
2025-12-25 08:39:48 -08:00
|
|
|
|
|
|
|
|
export async function generateAuthUrl(
|
|
|
|
|
payload: GeminiAuthUrlRequest
|
|
|
|
|
): Promise<GeminiAuthUrlResponse> {
|
|
|
|
|
const { data } = await apiClient.post<GeminiAuthUrlResponse>(
|
|
|
|
|
'/admin/gemini/oauth/auth-url',
|
|
|
|
|
payload
|
|
|
|
|
)
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function exchangeCode(payload: GeminiExchangeCodeRequest): Promise<GeminiTokenInfo> {
|
|
|
|
|
const { data } = await apiClient.post<GeminiTokenInfo>(
|
|
|
|
|
'/admin/gemini/oauth/exchange-code',
|
|
|
|
|
payload
|
|
|
|
|
)
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-25 23:52:26 -08:00
|
|
|
export async function getCapabilities(): Promise<GeminiOAuthCapabilities> {
|
|
|
|
|
const { data } = await apiClient.get<GeminiOAuthCapabilities>('/admin/gemini/oauth/capabilities')
|
|
|
|
|
return data
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default { generateAuthUrl, exchangeCode, getCapabilities }
|