(input: {
provider: Provider.Info
})
| 957 | } |
| 958 | |
| 959 | async function fetchGoogleUsage(input: { |
| 960 | provider: Provider.Info |
| 961 | }): Promise<Omit<Record, "providerID" | "providerName" | "fetchedAt">> { |
| 962 | const debugFile = path.join(Global.Path.log, "google-usage-debug.log") |
| 963 | const logDebug = async (message: string, data?: { [key: string]: unknown }) => { |
| 964 | const safe = data ? JSON.stringify(data) : "" |
| 965 | const line = `[${new Date().toISOString()}] ${message}${safe ? ` ${safe}` : ""}\n` |
| 966 | await fs.appendFile(debugFile, line).catch(() => {}) |
| 967 | } |
| 968 | |
| 969 | const readResponseBody = async (response: any): Promise<string> => { |
| 970 | if (response && typeof response.text === "function") { |
| 971 | return await response.text().catch(() => "[read text failed]") |
| 972 | } |
| 973 | if (response && typeof response.json === "function") { |
| 974 | return await response |
| 975 | .json() |
| 976 | .then((data: unknown) => JSON.stringify(data)) |
| 977 | .catch(() => "[read json failed]") |
| 978 | } |
| 979 | return "[no body reader]" |
| 980 | } |
| 981 | |
| 982 | const responseMeta = (response: any) => { |
| 983 | const headers = |
| 984 | response && response.headers && typeof response.headers.entries === "function" |
| 985 | ? Object.fromEntries(response.headers.entries()) |
| 986 | : undefined |
| 987 | return { |
| 988 | status: response?.status, |
| 989 | statusText: response?.statusText, |
| 990 | headers, |
| 991 | hasText: typeof response?.text === "function", |
| 992 | hasJson: typeof response?.json === "function", |
| 993 | hasArrayBuffer: typeof response?.arrayBuffer === "function", |
| 994 | type: response ? Object.prototype.toString.call(response) : "undefined", |
| 995 | ctor: response?.constructor?.name, |
| 996 | keys: response ? Object.keys(response) : undefined, |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | await logDebug("fetchGoogleUsage.start") |
| 1001 | const auth = await Auth.get(input.provider.id) |
| 1002 | if (!auth || auth.type !== "oauth") { |
| 1003 | await logDebug("auth.missing_or_invalid") |
| 1004 | throw new Error("Google OAuth authentication is required. Run `arctic auth login` and select Google.") |
| 1005 | } |
| 1006 | |
| 1007 | const codeAssistHeaders = { |
| 1008 | "User-Agent": "google-api-nodejs-client/9.15.1", |
| 1009 | "X-Goog-Api-Client": "gl-node/22.17.0", |
| 1010 | "Client-Metadata": "ideType=IDE_UNSPECIFIED,platform=PLATFORM_UNSPECIFIED,pluginType=GEMINI", |
| 1011 | } |
| 1012 | |
| 1013 | function parseRefreshParts(refresh: string): { |
| 1014 | refreshToken: string |
| 1015 | projectId?: string |
| 1016 | managedProjectId?: string |
nothing calls this directly
no test coverage detected