@psnext/slingcli 2.4.20260505-4 → 2.4.20260505-6

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