(input: any, init?: BunFetchRequestInit)
| 534 | options: { |
| 535 | // Don't set baseURL - we'll transform the full URL in the fetch function |
| 536 | async fetch(input: any, init?: BunFetchRequestInit) { |
| 537 | async function loadManagedProject(accessToken: string, projectId?: string): Promise<any | null> { |
| 538 | try { |
| 539 | const metadata: Record<string, string> = { |
| 540 | ideType: "IDE_UNSPECIFIED", |
| 541 | platform: "PLATFORM_UNSPECIFIED", |
| 542 | pluginType: "GEMINI", |
| 543 | } |
| 544 | if (projectId) { |
| 545 | metadata.duetProject = projectId |
| 546 | } |
| 547 | |
| 548 | const requestBody: Record<string, unknown> = { metadata } |
| 549 | if (projectId) { |
| 550 | requestBody.cloudaicompanionProject = projectId |
| 551 | } |
| 552 | |
| 553 | const response = await fetch("https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist", { |
| 554 | method: "POST", |
| 555 | headers: { |
| 556 | "Content-Type": "application/json", |
| 557 | Authorization: `Bearer ${accessToken}`, |
| 558 | ...codeAssistHeaders, |
| 559 | }, |
| 560 | body: JSON.stringify(requestBody), |
| 561 | }) |
| 562 | |
| 563 | if (!response.ok) { |
| 564 | return null |
| 565 | } |
| 566 | |
| 567 | return await response.json() |
| 568 | } catch (error) { |
| 569 | log.error("google oauth load managed project failed", { error }) |
| 570 | return null |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | async function onboardManagedProject( |
| 575 | accessToken: string, |
| 576 | tierId: string, |
| 577 | projectId?: string, |
| 578 | attempts = 10, |
| 579 | delayMs = 5000, |
| 580 | ): Promise<string | undefined> { |
| 581 | const metadata: Record<string, string> = { |
| 582 | ideType: "IDE_UNSPECIFIED", |
| 583 | platform: "PLATFORM_UNSPECIFIED", |
| 584 | pluginType: "GEMINI", |
| 585 | } |
| 586 | if (projectId) { |
| 587 | metadata.duetProject = projectId |
| 588 | } |
| 589 | |
| 590 | const requestBody: Record<string, unknown> = { |
| 591 | tierId, |
| 592 | metadata, |
| 593 | } |
no test coverage detected