@shawnstack/quickforge 1.3.18 → 1.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/bin/quickforge.mjs +258 -49
- package/dist/assets/anthropic-Bj3HAZgj.js +39 -0
- package/dist/assets/azure-openai-responses-IdZZrSrI.js +1 -0
- package/dist/assets/github-copilot-headers-CMb2BbzT.js +1 -0
- package/dist/assets/google-Brt_lS1J.js +1 -0
- package/dist/assets/{google-shared-XhYUKiGZ.js → google-shared-CLc4ziON.js} +3 -3
- package/dist/assets/google-vertex-B6HsoZ34.js +1 -0
- package/dist/assets/{index-Dm7aEWvT.js → index-D0CVLdX_.js} +525 -489
- package/dist/assets/index-D0W9hAl_.css +3 -0
- package/dist/assets/{mistral-DxhS4Wkn.js → mistral-CenXqwPz.js} +3 -3
- package/dist/assets/openai-codex-responses-D9ffGwbj.js +7 -0
- package/dist/assets/openai-completions-eWdeSGBG.js +5 -0
- package/dist/assets/openai-responses-Cavpmjeu.js +1 -0
- package/dist/assets/{openai-responses-shared-f_P3e1nz.js → openai-responses-shared-DF3ZGaUx.js} +5 -3
- package/dist/assets/transform-messages-CmnxG9RB.js +1 -0
- package/dist/index.html +2 -2
- package/node_modules/@anthropic-ai/sdk/CHANGELOG.md +34 -0
- package/node_modules/@anthropic-ai/sdk/bin/migration-config.json +185 -0
- package/node_modules/@anthropic-ai/sdk/package.json +1 -1
- package/node_modules/@anthropic-ai/sdk/resources/beta/beta.js +4 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/beta.mjs +4 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/files.js +5 -5
- package/node_modules/@anthropic-ai/sdk/resources/beta/files.mjs +5 -5
- package/node_modules/@anthropic-ai/sdk/resources/beta/index.js +11 -9
- package/node_modules/@anthropic-ai/sdk/resources/beta/index.mjs +1 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/index.js +11 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/index.mjs +5 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/memories.js +130 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/memories.mjs +126 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/memory-stores.js +145 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/memory-stores.mjs +140 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/memory-versions.js +81 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores/memory-versions.mjs +77 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores.js +6 -0
- package/node_modules/@anthropic-ai/sdk/resources/beta/memory-stores.mjs +3 -0
- package/node_modules/@anthropic-ai/sdk/tools/memory/node.js +12 -5
- package/node_modules/@anthropic-ai/sdk/tools/memory/node.mjs +12 -5
- package/node_modules/@anthropic-ai/sdk/version.js +1 -1
- package/node_modules/@anthropic-ai/sdk/version.mjs +1 -1
- package/node_modules/@aws-sdk/client-bedrock-runtime/package.json +5 -5
- package/node_modules/@aws-sdk/core/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/dist-cjs/fromHttp/fromHttp.js +12 -6
- package/node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/fromHttp.js +12 -6
- package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -2
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
- package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-websocket/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/package.json +3 -3
- package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +1 -2
- package/node_modules/@aws-sdk/token-providers/package.json +3 -3
- package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
- package/node_modules/@mariozechner/pi-agent-core/README.md +14 -0
- package/node_modules/@mariozechner/pi-agent-core/dist/agent-loop.js +9 -0
- package/node_modules/@mariozechner/pi-agent-core/dist/agent.js +1 -1
- package/node_modules/@mariozechner/pi-agent-core/package.json +2 -2
- package/node_modules/@mariozechner/pi-ai/README.md +20 -31
- package/node_modules/@mariozechner/pi-ai/dist/env-api-keys.js +7 -0
- package/node_modules/@mariozechner/pi-ai/dist/index.js +2 -0
- package/node_modules/@mariozechner/pi-ai/dist/models.generated.js +2420 -1213
- package/node_modules/@mariozechner/pi-ai/dist/models.js +28 -20
- package/node_modules/@mariozechner/pi-ai/dist/providers/amazon-bedrock.js +11 -11
- package/node_modules/@mariozechner/pi-ai/dist/providers/anthropic.js +43 -26
- package/node_modules/@mariozechner/pi-ai/dist/providers/azure-openai-responses.js +12 -6
- package/node_modules/@mariozechner/pi-ai/dist/providers/cloudflare.js +10 -3
- package/node_modules/@mariozechner/pi-ai/dist/providers/google-shared.js +4 -13
- package/node_modules/@mariozechner/pi-ai/dist/providers/google-vertex.js +4 -3
- package/node_modules/@mariozechner/pi-ai/dist/providers/google.js +4 -3
- package/node_modules/@mariozechner/pi-ai/dist/providers/mistral.js +8 -7
- package/node_modules/@mariozechner/pi-ai/dist/providers/openai-codex-responses.js +296 -41
- package/node_modules/@mariozechner/pi-ai/dist/providers/openai-completions.js +169 -153
- package/node_modules/@mariozechner/pi-ai/dist/providers/openai-responses-shared.js +14 -1
- package/node_modules/@mariozechner/pi-ai/dist/providers/openai-responses.js +22 -8
- package/node_modules/@mariozechner/pi-ai/dist/providers/register-builtins.js +0 -18
- package/node_modules/@mariozechner/pi-ai/dist/providers/simple-options.js +1 -0
- package/node_modules/@mariozechner/pi-ai/dist/session-resources.js +22 -0
- package/node_modules/@mariozechner/pi-ai/dist/utils/diagnostics.js +25 -0
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/index.js +0 -10
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/openai-codex.js +25 -14
- package/node_modules/@mariozechner/pi-ai/dist/utils/overflow.js +14 -0
- package/node_modules/@mariozechner/pi-ai/package.json +2 -6
- package/package.json +3 -3
- package/server/agent-manager.mjs +279 -12
- package/server/auto-compaction.mjs +1 -2
- package/server/conversation-compaction.mjs +0 -5
- package/server/index.mjs +1 -0
- package/server/routes/static.mjs +1 -0
- package/server/routes/tools.mjs +3 -1
- package/server/session-utils.mjs +6 -1
- package/server/share-store.mjs +27 -4
- package/server/subagents.mjs +101 -0
- package/server/system-prompt.mjs +30 -1
- package/server/tools/definitions.mjs +18 -0
- package/server/tools/index.mjs +1013 -911
- package/dist/assets/anthropic-Ck2DxOfr.js +0 -39
- package/dist/assets/azure-openai-responses-DIoz5q4Z.js +0 -1
- package/dist/assets/github-copilot-headers-CrI0CIJ7.js +0 -1
- package/dist/assets/google-Dau-4ve_.js +0 -1
- package/dist/assets/google-gemini-cli-DttMmbGb.js +0 -2
- package/dist/assets/google-vertex-BeukMl44.js +0 -1
- package/dist/assets/index-DgJVElbv.css +0 -3
- package/dist/assets/openai-codex-responses-X3sTzNAa.js +0 -7
- package/dist/assets/openai-completions-CRB9Vm0w.js +0 -5
- package/dist/assets/openai-responses-DXluu3oi.js +0 -1
- package/dist/assets/transform-messages-CV4kCtBB.js +0 -1
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/LICENSE +0 -201
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/README.md +0 -62
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-cjs/index.js +0 -156
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/constants.js +0 -2
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromEnvSigningName.js +0 -16
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js +0 -80
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromStatic.js +0 -8
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/getNewSsoOidcToken.js +0 -11
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/getSsoOidcClient.js +0 -10
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/index.js +0 -4
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/nodeProvider.js +0 -5
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/validateTokenExpiry.js +0 -7
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/validateTokenKey.js +0 -7
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js +0 -8
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/package.json +0 -69
- package/node_modules/@mariozechner/pi-ai/dist/providers/google-gemini-cli.js +0 -779
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/google-antigravity.js +0 -377
- package/node_modules/@mariozechner/pi-ai/dist/utils/oauth/google-gemini-cli.js +0 -482
|
@@ -1,482 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gemini CLI OAuth flow (Google Cloud Code Assist)
|
|
3
|
-
* Standard Gemini models only (gemini-2.0-flash, gemini-2.5-*)
|
|
4
|
-
*
|
|
5
|
-
* NOTE: This module uses Node.js http.createServer for the OAuth callback.
|
|
6
|
-
* It is only intended for CLI use, not browser environments.
|
|
7
|
-
*/
|
|
8
|
-
import { oauthErrorHtml, oauthSuccessHtml } from "./oauth-page.js";
|
|
9
|
-
import { generatePKCE } from "./pkce.js";
|
|
10
|
-
const CALLBACK_HOST = process.env.PI_OAUTH_CALLBACK_HOST || "127.0.0.1";
|
|
11
|
-
let _createServer = null;
|
|
12
|
-
let _httpImportPromise = null;
|
|
13
|
-
if (typeof process !== "undefined" && (process.versions?.node || process.versions?.bun)) {
|
|
14
|
-
_httpImportPromise = import("node:http").then((m) => {
|
|
15
|
-
_createServer = m.createServer;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
const decode = (s) => atob(s);
|
|
19
|
-
const CLIENT_ID = decode("NjgxMjU1ODA5Mzk1LW9vOGZ0Mm9wcmRybnA5ZTNhcWY2YXYzaG1kaWIxMzVqLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29t");
|
|
20
|
-
const CLIENT_SECRET = decode("R09DU1BYLTR1SGdNUG0tMW83U2stZ2VWNkN1NWNsWEZzeGw=");
|
|
21
|
-
const REDIRECT_URI = "http://localhost:8085/oauth2callback";
|
|
22
|
-
const SCOPES = [
|
|
23
|
-
"https://www.googleapis.com/auth/cloud-platform",
|
|
24
|
-
"https://www.googleapis.com/auth/userinfo.email",
|
|
25
|
-
"https://www.googleapis.com/auth/userinfo.profile",
|
|
26
|
-
];
|
|
27
|
-
const AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
28
|
-
const TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
29
|
-
const CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
|
30
|
-
/**
|
|
31
|
-
* Start a local HTTP server to receive the OAuth callback
|
|
32
|
-
*/
|
|
33
|
-
async function getNodeCreateServer() {
|
|
34
|
-
if (_createServer)
|
|
35
|
-
return _createServer;
|
|
36
|
-
if (_httpImportPromise) {
|
|
37
|
-
await _httpImportPromise;
|
|
38
|
-
}
|
|
39
|
-
if (_createServer)
|
|
40
|
-
return _createServer;
|
|
41
|
-
throw new Error("Gemini CLI OAuth is only available in Node.js environments");
|
|
42
|
-
}
|
|
43
|
-
async function startCallbackServer() {
|
|
44
|
-
const createServer = await getNodeCreateServer();
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
let settleWait;
|
|
47
|
-
const waitForCodePromise = new Promise((resolveWait) => {
|
|
48
|
-
let settled = false;
|
|
49
|
-
settleWait = (value) => {
|
|
50
|
-
if (settled)
|
|
51
|
-
return;
|
|
52
|
-
settled = true;
|
|
53
|
-
resolveWait(value);
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
const server = createServer((req, res) => {
|
|
57
|
-
const url = new URL(req.url || "", `http://localhost:8085`);
|
|
58
|
-
if (url.pathname === "/oauth2callback") {
|
|
59
|
-
const code = url.searchParams.get("code");
|
|
60
|
-
const state = url.searchParams.get("state");
|
|
61
|
-
const error = url.searchParams.get("error");
|
|
62
|
-
if (error) {
|
|
63
|
-
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
64
|
-
res.end(oauthErrorHtml("Google authentication did not complete.", `Error: ${error}`));
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
if (code && state) {
|
|
68
|
-
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
69
|
-
res.end(oauthSuccessHtml("Google authentication completed. You can close this window."));
|
|
70
|
-
settleWait?.({ code, state });
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
74
|
-
res.end(oauthErrorHtml("Missing code or state parameter."));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
res.writeHead(404, { "Content-Type": "text/html; charset=utf-8" });
|
|
79
|
-
res.end(oauthErrorHtml("Callback route not found."));
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
server.on("error", (err) => {
|
|
83
|
-
reject(err);
|
|
84
|
-
});
|
|
85
|
-
server.listen(8085, CALLBACK_HOST, () => {
|
|
86
|
-
resolve({
|
|
87
|
-
server,
|
|
88
|
-
cancelWait: () => {
|
|
89
|
-
settleWait?.(null);
|
|
90
|
-
},
|
|
91
|
-
waitForCode: () => waitForCodePromise,
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Parse redirect URL to extract code and state
|
|
98
|
-
*/
|
|
99
|
-
function parseRedirectUrl(input) {
|
|
100
|
-
const value = input.trim();
|
|
101
|
-
if (!value)
|
|
102
|
-
return {};
|
|
103
|
-
try {
|
|
104
|
-
const url = new URL(value);
|
|
105
|
-
return {
|
|
106
|
-
code: url.searchParams.get("code") ?? undefined,
|
|
107
|
-
state: url.searchParams.get("state") ?? undefined,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
// Not a URL, return empty
|
|
112
|
-
return {};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// Tier IDs as used by the Cloud Code API
|
|
116
|
-
const TIER_FREE = "free-tier";
|
|
117
|
-
const TIER_LEGACY = "legacy-tier";
|
|
118
|
-
const TIER_STANDARD = "standard-tier";
|
|
119
|
-
/**
|
|
120
|
-
* Wait helper for onboarding retries
|
|
121
|
-
*/
|
|
122
|
-
function wait(ms) {
|
|
123
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Get default tier from allowed tiers
|
|
127
|
-
*/
|
|
128
|
-
function getDefaultTier(allowedTiers) {
|
|
129
|
-
if (!allowedTiers || allowedTiers.length === 0)
|
|
130
|
-
return { id: TIER_LEGACY };
|
|
131
|
-
const defaultTier = allowedTiers.find((t) => t.isDefault);
|
|
132
|
-
return defaultTier ?? { id: TIER_LEGACY };
|
|
133
|
-
}
|
|
134
|
-
function isVpcScAffectedUser(payload) {
|
|
135
|
-
if (!payload || typeof payload !== "object")
|
|
136
|
-
return false;
|
|
137
|
-
if (!("error" in payload))
|
|
138
|
-
return false;
|
|
139
|
-
const error = payload.error;
|
|
140
|
-
if (!error?.details || !Array.isArray(error.details))
|
|
141
|
-
return false;
|
|
142
|
-
return error.details.some((detail) => detail.reason === "SECURITY_POLICY_VIOLATED");
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Poll a long-running operation until completion
|
|
146
|
-
*/
|
|
147
|
-
async function pollOperation(operationName, headers, onProgress) {
|
|
148
|
-
let attempt = 0;
|
|
149
|
-
while (true) {
|
|
150
|
-
if (attempt > 0) {
|
|
151
|
-
onProgress?.(`Waiting for project provisioning (attempt ${attempt + 1})...`);
|
|
152
|
-
await wait(5000);
|
|
153
|
-
}
|
|
154
|
-
const response = await fetch(`${CODE_ASSIST_ENDPOINT}/v1internal/${operationName}`, {
|
|
155
|
-
method: "GET",
|
|
156
|
-
headers,
|
|
157
|
-
});
|
|
158
|
-
if (!response.ok) {
|
|
159
|
-
throw new Error(`Failed to poll operation: ${response.status} ${response.statusText}`);
|
|
160
|
-
}
|
|
161
|
-
const data = (await response.json());
|
|
162
|
-
if (data.done) {
|
|
163
|
-
return data;
|
|
164
|
-
}
|
|
165
|
-
attempt += 1;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Discover or provision a Google Cloud project for the user
|
|
170
|
-
*/
|
|
171
|
-
async function discoverProject(accessToken, onProgress) {
|
|
172
|
-
// Check for user-provided project ID via environment variable
|
|
173
|
-
const envProjectId = process.env.GOOGLE_CLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT_ID;
|
|
174
|
-
const headers = {
|
|
175
|
-
Authorization: `Bearer ${accessToken}`,
|
|
176
|
-
"Content-Type": "application/json",
|
|
177
|
-
"User-Agent": "google-api-nodejs-client/9.15.1",
|
|
178
|
-
"X-Goog-Api-Client": "gl-node/22.17.0",
|
|
179
|
-
};
|
|
180
|
-
// Try to load existing project via loadCodeAssist
|
|
181
|
-
onProgress?.("Checking for existing Cloud Code Assist project...");
|
|
182
|
-
const loadResponse = await fetch(`${CODE_ASSIST_ENDPOINT}/v1internal:loadCodeAssist`, {
|
|
183
|
-
method: "POST",
|
|
184
|
-
headers,
|
|
185
|
-
body: JSON.stringify({
|
|
186
|
-
cloudaicompanionProject: envProjectId,
|
|
187
|
-
metadata: {
|
|
188
|
-
ideType: "IDE_UNSPECIFIED",
|
|
189
|
-
platform: "PLATFORM_UNSPECIFIED",
|
|
190
|
-
pluginType: "GEMINI",
|
|
191
|
-
duetProject: envProjectId,
|
|
192
|
-
},
|
|
193
|
-
}),
|
|
194
|
-
});
|
|
195
|
-
let data;
|
|
196
|
-
if (!loadResponse.ok) {
|
|
197
|
-
let errorPayload;
|
|
198
|
-
try {
|
|
199
|
-
errorPayload = await loadResponse.clone().json();
|
|
200
|
-
}
|
|
201
|
-
catch {
|
|
202
|
-
errorPayload = undefined;
|
|
203
|
-
}
|
|
204
|
-
if (isVpcScAffectedUser(errorPayload)) {
|
|
205
|
-
data = { currentTier: { id: TIER_STANDARD } };
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
const errorText = await loadResponse.text();
|
|
209
|
-
throw new Error(`loadCodeAssist failed: ${loadResponse.status} ${loadResponse.statusText}: ${errorText}`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
data = (await loadResponse.json());
|
|
214
|
-
}
|
|
215
|
-
// If user already has a current tier and project, use it
|
|
216
|
-
if (data.currentTier) {
|
|
217
|
-
if (data.cloudaicompanionProject) {
|
|
218
|
-
return data.cloudaicompanionProject;
|
|
219
|
-
}
|
|
220
|
-
// User has a tier but no managed project - they need to provide one via env var
|
|
221
|
-
if (envProjectId) {
|
|
222
|
-
return envProjectId;
|
|
223
|
-
}
|
|
224
|
-
throw new Error("This account requires setting the GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_PROJECT_ID environment variable. " +
|
|
225
|
-
"See https://goo.gle/gemini-cli-auth-docs#workspace-gca");
|
|
226
|
-
}
|
|
227
|
-
// User needs to be onboarded - get the default tier
|
|
228
|
-
const tier = getDefaultTier(data.allowedTiers);
|
|
229
|
-
const tierId = tier?.id ?? TIER_FREE;
|
|
230
|
-
if (tierId !== TIER_FREE && !envProjectId) {
|
|
231
|
-
throw new Error("This account requires setting the GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_PROJECT_ID environment variable. " +
|
|
232
|
-
"See https://goo.gle/gemini-cli-auth-docs#workspace-gca");
|
|
233
|
-
}
|
|
234
|
-
onProgress?.("Provisioning Cloud Code Assist project (this may take a moment)...");
|
|
235
|
-
// Build onboard request - for free tier, don't include project ID (Google provisions one)
|
|
236
|
-
// For other tiers, include the user's project ID if available
|
|
237
|
-
const onboardBody = {
|
|
238
|
-
tierId,
|
|
239
|
-
metadata: {
|
|
240
|
-
ideType: "IDE_UNSPECIFIED",
|
|
241
|
-
platform: "PLATFORM_UNSPECIFIED",
|
|
242
|
-
pluginType: "GEMINI",
|
|
243
|
-
},
|
|
244
|
-
};
|
|
245
|
-
if (tierId !== TIER_FREE && envProjectId) {
|
|
246
|
-
onboardBody.cloudaicompanionProject = envProjectId;
|
|
247
|
-
onboardBody.metadata.duetProject = envProjectId;
|
|
248
|
-
}
|
|
249
|
-
// Start onboarding - this returns a long-running operation
|
|
250
|
-
const onboardResponse = await fetch(`${CODE_ASSIST_ENDPOINT}/v1internal:onboardUser`, {
|
|
251
|
-
method: "POST",
|
|
252
|
-
headers,
|
|
253
|
-
body: JSON.stringify(onboardBody),
|
|
254
|
-
});
|
|
255
|
-
if (!onboardResponse.ok) {
|
|
256
|
-
const errorText = await onboardResponse.text();
|
|
257
|
-
throw new Error(`onboardUser failed: ${onboardResponse.status} ${onboardResponse.statusText}: ${errorText}`);
|
|
258
|
-
}
|
|
259
|
-
let lroData = (await onboardResponse.json());
|
|
260
|
-
// If the operation isn't done yet, poll until completion
|
|
261
|
-
if (!lroData.done && lroData.name) {
|
|
262
|
-
lroData = await pollOperation(lroData.name, headers, onProgress);
|
|
263
|
-
}
|
|
264
|
-
// Try to get project ID from the response
|
|
265
|
-
const projectId = lroData.response?.cloudaicompanionProject?.id;
|
|
266
|
-
if (projectId) {
|
|
267
|
-
return projectId;
|
|
268
|
-
}
|
|
269
|
-
// If no project ID from onboarding, fall back to env var
|
|
270
|
-
if (envProjectId) {
|
|
271
|
-
return envProjectId;
|
|
272
|
-
}
|
|
273
|
-
throw new Error("Could not discover or provision a Google Cloud project. " +
|
|
274
|
-
"Try setting the GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_PROJECT_ID environment variable. " +
|
|
275
|
-
"See https://goo.gle/gemini-cli-auth-docs#workspace-gca");
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Get user email from the access token
|
|
279
|
-
*/
|
|
280
|
-
async function getUserEmail(accessToken) {
|
|
281
|
-
try {
|
|
282
|
-
const response = await fetch("https://www.googleapis.com/oauth2/v1/userinfo?alt=json", {
|
|
283
|
-
headers: {
|
|
284
|
-
Authorization: `Bearer ${accessToken}`,
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
if (response.ok) {
|
|
288
|
-
const data = (await response.json());
|
|
289
|
-
return data.email;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
catch {
|
|
293
|
-
// Ignore errors, email is optional
|
|
294
|
-
}
|
|
295
|
-
return undefined;
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Refresh Google Cloud Code Assist token
|
|
299
|
-
*/
|
|
300
|
-
export async function refreshGoogleCloudToken(refreshToken, projectId) {
|
|
301
|
-
const response = await fetch(TOKEN_URL, {
|
|
302
|
-
method: "POST",
|
|
303
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
304
|
-
body: new URLSearchParams({
|
|
305
|
-
client_id: CLIENT_ID,
|
|
306
|
-
client_secret: CLIENT_SECRET,
|
|
307
|
-
refresh_token: refreshToken,
|
|
308
|
-
grant_type: "refresh_token",
|
|
309
|
-
}),
|
|
310
|
-
});
|
|
311
|
-
if (!response.ok) {
|
|
312
|
-
const error = await response.text();
|
|
313
|
-
throw new Error(`Google Cloud token refresh failed: ${error}`);
|
|
314
|
-
}
|
|
315
|
-
const data = (await response.json());
|
|
316
|
-
return {
|
|
317
|
-
refresh: data.refresh_token || refreshToken,
|
|
318
|
-
access: data.access_token,
|
|
319
|
-
expires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,
|
|
320
|
-
projectId,
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Login with Gemini CLI (Google Cloud Code Assist) OAuth
|
|
325
|
-
*
|
|
326
|
-
* @param onAuth - Callback with URL and optional instructions
|
|
327
|
-
* @param onProgress - Optional progress callback
|
|
328
|
-
* @param onManualCodeInput - Optional promise that resolves with user-pasted redirect URL.
|
|
329
|
-
* Races with browser callback - whichever completes first wins.
|
|
330
|
-
*/
|
|
331
|
-
export async function loginGeminiCli(onAuth, onProgress, onManualCodeInput) {
|
|
332
|
-
const { verifier, challenge } = await generatePKCE();
|
|
333
|
-
// Start local server for callback
|
|
334
|
-
onProgress?.("Starting local server for OAuth callback...");
|
|
335
|
-
const server = await startCallbackServer();
|
|
336
|
-
let code;
|
|
337
|
-
try {
|
|
338
|
-
// Build authorization URL
|
|
339
|
-
const authParams = new URLSearchParams({
|
|
340
|
-
client_id: CLIENT_ID,
|
|
341
|
-
response_type: "code",
|
|
342
|
-
redirect_uri: REDIRECT_URI,
|
|
343
|
-
scope: SCOPES.join(" "),
|
|
344
|
-
code_challenge: challenge,
|
|
345
|
-
code_challenge_method: "S256",
|
|
346
|
-
state: verifier,
|
|
347
|
-
access_type: "offline",
|
|
348
|
-
prompt: "consent",
|
|
349
|
-
});
|
|
350
|
-
const authUrl = `${AUTH_URL}?${authParams.toString()}`;
|
|
351
|
-
// Notify caller with URL to open
|
|
352
|
-
onAuth({
|
|
353
|
-
url: authUrl,
|
|
354
|
-
instructions: "Complete the sign-in in your browser.",
|
|
355
|
-
});
|
|
356
|
-
// Wait for the callback, racing with manual input if provided
|
|
357
|
-
onProgress?.("Waiting for OAuth callback...");
|
|
358
|
-
if (onManualCodeInput) {
|
|
359
|
-
// Race between browser callback and manual input
|
|
360
|
-
let manualInput;
|
|
361
|
-
let manualError;
|
|
362
|
-
const manualPromise = onManualCodeInput()
|
|
363
|
-
.then((input) => {
|
|
364
|
-
manualInput = input;
|
|
365
|
-
server.cancelWait();
|
|
366
|
-
})
|
|
367
|
-
.catch((err) => {
|
|
368
|
-
manualError = err instanceof Error ? err : new Error(String(err));
|
|
369
|
-
server.cancelWait();
|
|
370
|
-
});
|
|
371
|
-
const result = await server.waitForCode();
|
|
372
|
-
// If manual input was cancelled, throw that error
|
|
373
|
-
if (manualError) {
|
|
374
|
-
throw manualError;
|
|
375
|
-
}
|
|
376
|
-
if (result?.code) {
|
|
377
|
-
// Browser callback won - verify state
|
|
378
|
-
if (result.state !== verifier) {
|
|
379
|
-
throw new Error("OAuth state mismatch - possible CSRF attack");
|
|
380
|
-
}
|
|
381
|
-
code = result.code;
|
|
382
|
-
}
|
|
383
|
-
else if (manualInput) {
|
|
384
|
-
// Manual input won
|
|
385
|
-
const parsed = parseRedirectUrl(manualInput);
|
|
386
|
-
if (parsed.state && parsed.state !== verifier) {
|
|
387
|
-
throw new Error("OAuth state mismatch - possible CSRF attack");
|
|
388
|
-
}
|
|
389
|
-
code = parsed.code;
|
|
390
|
-
}
|
|
391
|
-
// If still no code, wait for manual promise and try that
|
|
392
|
-
if (!code) {
|
|
393
|
-
await manualPromise;
|
|
394
|
-
if (manualError) {
|
|
395
|
-
throw manualError;
|
|
396
|
-
}
|
|
397
|
-
if (manualInput) {
|
|
398
|
-
const parsed = parseRedirectUrl(manualInput);
|
|
399
|
-
if (parsed.state && parsed.state !== verifier) {
|
|
400
|
-
throw new Error("OAuth state mismatch - possible CSRF attack");
|
|
401
|
-
}
|
|
402
|
-
code = parsed.code;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
else {
|
|
407
|
-
// Original flow: just wait for callback
|
|
408
|
-
const result = await server.waitForCode();
|
|
409
|
-
if (result?.code) {
|
|
410
|
-
if (result.state !== verifier) {
|
|
411
|
-
throw new Error("OAuth state mismatch - possible CSRF attack");
|
|
412
|
-
}
|
|
413
|
-
code = result.code;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
if (!code) {
|
|
417
|
-
throw new Error("No authorization code received");
|
|
418
|
-
}
|
|
419
|
-
// Exchange code for tokens
|
|
420
|
-
onProgress?.("Exchanging authorization code for tokens...");
|
|
421
|
-
const tokenResponse = await fetch(TOKEN_URL, {
|
|
422
|
-
method: "POST",
|
|
423
|
-
headers: {
|
|
424
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
425
|
-
},
|
|
426
|
-
body: new URLSearchParams({
|
|
427
|
-
client_id: CLIENT_ID,
|
|
428
|
-
client_secret: CLIENT_SECRET,
|
|
429
|
-
code,
|
|
430
|
-
grant_type: "authorization_code",
|
|
431
|
-
redirect_uri: REDIRECT_URI,
|
|
432
|
-
code_verifier: verifier,
|
|
433
|
-
}),
|
|
434
|
-
});
|
|
435
|
-
if (!tokenResponse.ok) {
|
|
436
|
-
const error = await tokenResponse.text();
|
|
437
|
-
throw new Error(`Token exchange failed: ${error}`);
|
|
438
|
-
}
|
|
439
|
-
const tokenData = (await tokenResponse.json());
|
|
440
|
-
if (!tokenData.refresh_token) {
|
|
441
|
-
throw new Error("No refresh token received. Please try again.");
|
|
442
|
-
}
|
|
443
|
-
// Get user email
|
|
444
|
-
onProgress?.("Getting user info...");
|
|
445
|
-
const email = await getUserEmail(tokenData.access_token);
|
|
446
|
-
// Discover project
|
|
447
|
-
const projectId = await discoverProject(tokenData.access_token, onProgress);
|
|
448
|
-
// Calculate expiry time (current time + expires_in seconds - 5 min buffer)
|
|
449
|
-
const expiresAt = Date.now() + tokenData.expires_in * 1000 - 5 * 60 * 1000;
|
|
450
|
-
const credentials = {
|
|
451
|
-
refresh: tokenData.refresh_token,
|
|
452
|
-
access: tokenData.access_token,
|
|
453
|
-
expires: expiresAt,
|
|
454
|
-
projectId,
|
|
455
|
-
email,
|
|
456
|
-
};
|
|
457
|
-
return credentials;
|
|
458
|
-
}
|
|
459
|
-
finally {
|
|
460
|
-
server.server.close();
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
export const geminiCliOAuthProvider = {
|
|
464
|
-
id: "google-gemini-cli",
|
|
465
|
-
name: "Google Cloud Code Assist (Gemini CLI)",
|
|
466
|
-
usesCallbackServer: true,
|
|
467
|
-
async login(callbacks) {
|
|
468
|
-
return loginGeminiCli(callbacks.onAuth, callbacks.onProgress, callbacks.onManualCodeInput);
|
|
469
|
-
},
|
|
470
|
-
async refreshToken(credentials) {
|
|
471
|
-
const creds = credentials;
|
|
472
|
-
if (!creds.projectId) {
|
|
473
|
-
throw new Error("Google Cloud credentials missing projectId");
|
|
474
|
-
}
|
|
475
|
-
return refreshGoogleCloudToken(creds.refresh, creds.projectId);
|
|
476
|
-
},
|
|
477
|
-
getApiKey(credentials) {
|
|
478
|
-
const creds = credentials;
|
|
479
|
-
return JSON.stringify({ token: creds.access, projectId: creds.projectId });
|
|
480
|
-
},
|
|
481
|
-
};
|
|
482
|
-
//# sourceMappingURL=google-gemini-cli.js.map
|