(accessToken: string, projectId?: string)
| 1076 | } |
| 1077 | |
| 1078 | async function loadManagedProject(accessToken: string, projectId?: string): Promise<any | null> { |
| 1079 | const metadata: { [key: string]: string } = { |
| 1080 | ideType: "IDE_UNSPECIFIED", |
| 1081 | platform: "PLATFORM_UNSPECIFIED", |
| 1082 | pluginType: "GEMINI", |
| 1083 | } |
| 1084 | if (projectId) { |
| 1085 | metadata.duetProject = projectId |
| 1086 | } |
| 1087 | |
| 1088 | const requestBody: { [key: string]: unknown } = { metadata } |
| 1089 | if (projectId) { |
| 1090 | requestBody.cloudaicompanionProject = projectId |
| 1091 | } |
| 1092 | |
| 1093 | let response: any |
| 1094 | try { |
| 1095 | response = await globalThis.fetch("https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist", { |
| 1096 | method: "POST", |
| 1097 | headers: { |
| 1098 | "Content-Type": "application/json", |
| 1099 | Authorization: `Bearer ${accessToken}`, |
| 1100 | ...codeAssistHeaders, |
| 1101 | }, |
| 1102 | body: JSON.stringify(requestBody), |
| 1103 | }) |
| 1104 | } catch (error) { |
| 1105 | await logDebug("loadCodeAssist.error", { |
| 1106 | error: error instanceof Error ? error.message : String(error), |
| 1107 | }) |
| 1108 | return null |
| 1109 | } |
| 1110 | |
| 1111 | if (!response.ok) { |
| 1112 | const errorText = await readResponseBody(response) |
| 1113 | await logDebug("loadCodeAssist.failed", { ...responseMeta(response), body: errorText }) |
| 1114 | return null |
| 1115 | } |
| 1116 | |
| 1117 | const payload = await response.json() |
| 1118 | await logDebug("loadCodeAssist.ok", { |
| 1119 | hasProject: Boolean(payload?.cloudaicompanionProject), |
| 1120 | currentTier: payload?.currentTier?.id ?? null, |
| 1121 | }) |
| 1122 | return payload |
| 1123 | } |
| 1124 | |
| 1125 | async function onboardManagedProject( |
| 1126 | accessToken: string, |
no test coverage detected