opencode-gemini-cli-oauth 1.1.13 → 1.1.14
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/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +3 -17
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +54 -51
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Main entry point for the plugin
|
|
10
10
|
*/
|
|
11
|
-
export {
|
|
12
|
-
export type { OAuthCredentials, GoogleAccount, AccountPoolEntry, AccountPool, PluginConfig, } from './types.js';
|
|
11
|
+
export { default } from './plugin.js';
|
|
13
12
|
export { oauth } from './auth/oauth.js';
|
|
14
13
|
export { accountManager } from './auth/account-manager.js';
|
|
15
14
|
export { StorageManager } from './storage/storage.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAGH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Main entry point for the plugin
|
|
10
10
|
*/
|
|
11
|
-
//
|
|
12
|
-
export {
|
|
11
|
+
// Default export for OpenCode (Factory Function Pattern)
|
|
12
|
+
export { default } from './plugin.js';
|
|
13
13
|
// Export utilities for advanced usage
|
|
14
14
|
export { oauth } from './auth/oauth.js';
|
|
15
15
|
export { accountManager } from './auth/account-manager.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAEH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAEH,yDAAyD;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,sCAAsC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -6,20 +6,15 @@
|
|
|
6
6
|
import type { PluginContext } from './types.js';
|
|
7
7
|
/**
|
|
8
8
|
* OpenCode Plugin for Gemini CLI OAuth Authentication
|
|
9
|
+
* Refactored based on Architectural Analysis (Factory Function Pattern)
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
+
export default function loadPlugin(context: PluginContext): Promise<{
|
|
11
12
|
auth: {
|
|
12
13
|
provider: string;
|
|
13
|
-
/**
|
|
14
|
-
* Auth loader - returns object with apiKey and fetch function
|
|
15
|
-
*/
|
|
16
14
|
loader: (getAuth: any, provider: string) => Promise<{
|
|
17
15
|
apiKey: string;
|
|
18
|
-
fetch(input: RequestInfo | URL, init?: RequestInit)
|
|
16
|
+
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
19
17
|
}>;
|
|
20
|
-
/**
|
|
21
|
-
* Auth methods
|
|
22
|
-
*/
|
|
23
18
|
methods: {
|
|
24
19
|
label: string;
|
|
25
20
|
type: string;
|
|
@@ -40,13 +35,4 @@ export declare const GeminiCLIOAuthPlugin: ({ client, directory }: PluginContext
|
|
|
40
35
|
}[];
|
|
41
36
|
};
|
|
42
37
|
}>;
|
|
43
|
-
export declare const metadata: {
|
|
44
|
-
name: string;
|
|
45
|
-
version: string;
|
|
46
|
-
description: string;
|
|
47
|
-
author: string;
|
|
48
|
-
compatibleWith: {
|
|
49
|
-
opencode: string;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
38
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;GAGG;AACH,wBAA8B,UAAU,CAAC,OAAO,EAAE,aAAa;;;0BA4DjC,GAAG,YAAY,MAAM;;2BAlDV,WAAW,GAAG,GAAG,SAAS,WAAW,KAAG,OAAO,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;GAkFjG"}
|
package/dist/plugin.js
CHANGED
|
@@ -4,53 +4,68 @@
|
|
|
4
4
|
* SPDX-License-Identifier: MIT
|
|
5
5
|
*/
|
|
6
6
|
import { oauth } from './auth/oauth.js';
|
|
7
|
-
// No instantiation needed
|
|
8
|
-
// const oauthManager = new OAuthManager();
|
|
9
7
|
/**
|
|
10
8
|
* OpenCode Plugin for Gemini CLI OAuth Authentication
|
|
9
|
+
* Refactored based on Architectural Analysis (Factory Function Pattern)
|
|
11
10
|
*/
|
|
12
|
-
export
|
|
13
|
-
console.log('🚀 Loading Gemini CLI OAuth plugin (v1.1.
|
|
11
|
+
export default async function loadPlugin(context) {
|
|
12
|
+
console.log('🚀 Loading Gemini CLI OAuth plugin (v1.1.14)...');
|
|
13
|
+
// 1. Capture original fetcher (Middleware pattern)
|
|
14
|
+
// Fallback to global fetch if context.client.fetch is not available
|
|
15
|
+
const nextFetch = (context.client && context.client.fetch)
|
|
16
|
+
? context.client.fetch.bind(context.client)
|
|
17
|
+
: globalThis.fetch.bind(globalThis);
|
|
18
|
+
// 2. Define the interceptor
|
|
19
|
+
const interceptedFetch = async (input, init) => {
|
|
20
|
+
const urlStr = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
21
|
+
// Filter: Only intercept Gemini API requests
|
|
22
|
+
if (!urlStr.includes('generativelanguage.googleapis.com')) {
|
|
23
|
+
return nextFetch(input, init);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
// 3. Auth Check & Token Retrieval
|
|
27
|
+
// This handles token refresh automatically via our functional module
|
|
28
|
+
const token = await oauth.getAccessToken();
|
|
29
|
+
// 4. Clone init to avoid mutation side-effects
|
|
30
|
+
const newInit = { ...init };
|
|
31
|
+
const headers = new Headers(newInit.headers);
|
|
32
|
+
// 5. Inject Header
|
|
33
|
+
headers.set('Authorization', `Bearer ${token}`);
|
|
34
|
+
newInit.headers = headers;
|
|
35
|
+
// Remove API key query param if present (cleanup)
|
|
36
|
+
let targetInput = input;
|
|
37
|
+
if (typeof input === 'string' && input.includes('key=')) {
|
|
38
|
+
const urlObj = new URL(input);
|
|
39
|
+
urlObj.searchParams.delete('key');
|
|
40
|
+
targetInput = urlObj.toString();
|
|
41
|
+
}
|
|
42
|
+
else if (input instanceof URL && input.searchParams.has('key')) {
|
|
43
|
+
const urlObj = new URL(input.toString());
|
|
44
|
+
urlObj.searchParams.delete('key');
|
|
45
|
+
targetInput = urlObj;
|
|
46
|
+
}
|
|
47
|
+
// 6. Forward to original fetcher
|
|
48
|
+
return nextFetch(targetInput, newInit);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error('❌ [Gemini OAuth] Token error:', error);
|
|
52
|
+
// Fallback: try request without auth injection (will likely fail 401/403 but preserves flow)
|
|
53
|
+
return nextFetch(input, init);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
// 7. Return the plugin instance with the auth loader structure
|
|
57
|
+
// The runtime expects an object that provides the auth strategy
|
|
14
58
|
return {
|
|
15
59
|
auth: {
|
|
16
60
|
provider: 'gemini-cli-oauth',
|
|
17
|
-
|
|
18
|
-
* Auth loader - returns object with apiKey and fetch function
|
|
19
|
-
*/
|
|
61
|
+
// The loader itself is a factory that returns the strategy implementation
|
|
20
62
|
loader: async (getAuth, provider) => {
|
|
63
|
+
console.log(`🔌 Initializing auth strategy for ${provider}`);
|
|
21
64
|
return {
|
|
22
65
|
apiKey: 'gemini-cli-oauth-placeholder',
|
|
23
|
-
|
|
24
|
-
async fetch(input, init) {
|
|
25
|
-
const urlStr = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
26
|
-
// Only intercept Gemini API requests
|
|
27
|
-
if (!urlStr.includes('generativelanguage.googleapis.com')) {
|
|
28
|
-
return fetch(input, init);
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
// Get OAuth token using functional module
|
|
32
|
-
const token = await oauth.getAccessToken();
|
|
33
|
-
// Inject Authorization header
|
|
34
|
-
const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
|
|
35
|
-
headers.set('Authorization', `Bearer ${token}`);
|
|
36
|
-
// Remove API key from URL if present
|
|
37
|
-
const urlObj = new URL(urlStr);
|
|
38
|
-
urlObj.searchParams.delete('key');
|
|
39
|
-
return fetch(urlObj.toString(), {
|
|
40
|
-
...init,
|
|
41
|
-
headers
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
console.error('❌ [Gemini OAuth] Token error:', error);
|
|
46
|
-
return fetch(input, init);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
66
|
+
fetch: interceptedFetch
|
|
49
67
|
};
|
|
50
68
|
},
|
|
51
|
-
/**
|
|
52
|
-
* Auth methods
|
|
53
|
-
*/
|
|
54
69
|
methods: [
|
|
55
70
|
{
|
|
56
71
|
label: "Google Account (via Gemini CLI)",
|
|
@@ -68,25 +83,13 @@ export const GeminiCLIOAuthPlugin = async ({ client, directory }) => {
|
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
85
|
catch (_a) { }
|
|
71
|
-
return {
|
|
72
|
-
type: "failed",
|
|
73
|
-
error: "Authentication failed. Run 'opencode-gemini-setup'."
|
|
74
|
-
};
|
|
86
|
+
return { type: "failed", error: "Run 'opencode-gemini-setup' first." };
|
|
75
87
|
}
|
|
76
88
|
};
|
|
77
89
|
}
|
|
78
90
|
}
|
|
79
91
|
]
|
|
80
|
-
}
|
|
92
|
+
}
|
|
81
93
|
};
|
|
82
|
-
}
|
|
83
|
-
export const metadata = {
|
|
84
|
-
name: 'opencode-gemini-cli-oauth',
|
|
85
|
-
version: '1.1.8',
|
|
86
|
-
description: 'Use Gemini CLI OAuth credentials in OpenCode',
|
|
87
|
-
author: 'Yusuf',
|
|
88
|
-
compatibleWith: {
|
|
89
|
-
opencode: '^1.0.0',
|
|
90
|
-
},
|
|
91
|
-
};
|
|
94
|
+
}
|
|
92
95
|
//# sourceMappingURL=plugin.js.map
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC;;;GAGG;AACH,MAAM,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