@google/gemini-cli 0.45.0-preview.0 → 0.45.0-preview.1
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/bundle/{chunk-I7UI7NB6.js → chunk-2ZH72RHY.js} +3 -3
- package/bundle/{chunk-EZCW6IDX.js → chunk-3NDAYKF4.js} +1 -1
- package/bundle/{chunk-IPQLMJS5.js → chunk-4KX3ETW3.js} +1 -1
- package/bundle/{chunk-4FNXKOEB.js → chunk-565MWDPP.js} +23 -13
- package/bundle/{chunk-J4QUIOHJ.js → chunk-5BX5PJIE.js} +7 -7
- package/bundle/{chunk-J7SEBVDD.js → chunk-5YTIYFJO.js} +7544 -14042
- package/bundle/{chunk-GIXFMPPJ.js → chunk-6WWGBNKT.js} +1 -1
- package/bundle/{chunk-4M3TG6ZU.js → chunk-BLUAEAZN.js} +1 -1
- package/bundle/{chunk-2RRZM3IR.js → chunk-BO72FGK2.js} +7 -7
- package/bundle/{chunk-NOJPXYUJ.js → chunk-CJHCK2YW.js} +1 -1
- package/bundle/{chunk-S4CJ6KAO.js → chunk-CJTRYZPP.js} +3 -3
- package/bundle/chunk-DDJWQSDN.js +394439 -0
- package/bundle/{chunk-APSDEHHA.js → chunk-E3KBY4EQ.js} +1 -1
- package/bundle/{chunk-WPCNMQ6J.js → chunk-FEY3T6LA.js} +9 -8
- package/bundle/{chunk-Q3UZDZZV.js → chunk-HA5VES5S.js} +3 -3
- package/bundle/{chunk-Y5REX36P.js → chunk-HVWNKZSB.js} +1 -1
- package/bundle/{chunk-2O7YSVPU.js → chunk-HZCAEM2F.js} +2 -2
- package/bundle/{chunk-DMCSPKNM.js → chunk-IGJG7DNZ.js} +1 -1
- package/bundle/{chunk-TH3OOWK4.js → chunk-JWWA32XO.js} +67 -54
- package/bundle/{chunk-LUQGJPIY.js → chunk-JXVK53RJ.js} +2 -2
- package/bundle/{chunk-VS2OY6HJ.js → chunk-K43EAKOP.js} +8 -5
- package/bundle/{chunk-N4X4WHSW.js → chunk-NB2NOE4L.js} +2 -2
- package/bundle/chunk-NVJOR76X.js +1571 -0
- package/bundle/chunk-NYWYNF2Z.js +81685 -0
- package/bundle/chunk-OQLEYMM2.js +512 -0
- package/bundle/{chunk-OY6QYVTR.js → chunk-OWSYSTWM.js} +1 -1
- package/bundle/{chunk-CWAXEILN.js → chunk-R52453KY.js} +26 -16
- package/bundle/{chunk-R5OZKB4U.js → chunk-S6AQSJNU.js} +1 -1
- package/bundle/chunk-SKDT4PWC.js +118 -0
- package/bundle/chunk-TCAVPMJX.js +17320 -0
- package/bundle/chunk-WTRP3GGZ.js +154 -0
- package/bundle/chunk-Y6SLZFPD.js +398 -0
- package/bundle/{cleanup-2WCUS5XU.js → cleanup-2FHZMQ3Z.js} +2 -2
- package/bundle/{cleanup-7FHLTEXT.js → cleanup-F7XRM3DT.js} +2 -2
- package/bundle/{cleanup-WGOZFAQJ.js → cleanup-OZH3SJVM.js} +2 -2
- package/bundle/cleanup-ZO5CVKGH.js +32 -0
- package/bundle/{core-SIRU2VWJ.js → core-B47ZXN3Y.js} +1 -1
- package/bundle/{devtoolsService-IANYOK3R.js → devtoolsService-L7PYKOHR.js} +2 -2
- package/bundle/{devtoolsService-4Y2RGEUE.js → devtoolsService-OYQJHPEW.js} +4 -3
- package/bundle/devtoolsService-SGV7MSUA.js +856 -0
- package/bundle/{devtoolsService-F5XFL4BF.js → devtoolsService-XYSZCMQM.js} +2 -2
- package/bundle/{dist-67ZORME5.js → dist-C6L3MGQS.js} +1 -1
- package/bundle/{core-LD6MHGD6.js → dist-MOEHPHUN.js} +1 -1
- package/bundle/dist-WLKMTHZQ.js +2134 -0
- package/bundle/{gemini-5ZI322FJ.js → gemini-2XSNIT2N.js} +212 -196
- package/bundle/{gemini-24ENZ343.js → gemini-CHS2YNJG.js} +13 -13
- package/bundle/gemini-CQDPCFEE.js +16406 -0
- package/bundle/{gemini-74UML3PJ.js → gemini-LT5MWLZQ.js} +13 -13
- package/bundle/gemini.js +10 -9
- package/bundle/{interactiveCli-7GM3U7SA.js → interactiveCli-2YFAMDR5.js} +8 -8
- package/bundle/{interactiveCli-XM5HDVD7.js → interactiveCli-6EFCVZP7.js} +314 -295
- package/bundle/interactiveCli-HA3BASZN.js +34726 -0
- package/bundle/{interactiveCli-BVZLMTVC.js → interactiveCli-UUI7OUZK.js} +8 -8
- package/bundle/{liteRtServerManager-6N5DYDEQ.js → liteRtServerManager-2VKZTPMY.js} +4 -4
- package/bundle/{liteRtServerManager-JVMDH3TN.js → liteRtServerManager-4PZ3X7SS.js} +4 -4
- package/bundle/{liteRtServerManager-3HS3VUPU.js → liteRtServerManager-GH6VHWTU.js} +4 -4
- package/bundle/liteRtServerManager-OMSM6SJU.js +65 -0
- package/bundle/{oauth2-provider-U72EWZHQ.js → oauth2-provider-4UIWNIX3.js} +1 -1
- package/bundle/{oauth2-provider-RUFABDNL.js → oauth2-provider-BDX6V2YX.js} +1 -1
- package/bundle/{oauth2-provider-WS7LUQ5V.js → oauth2-provider-N2ZY2DXQ.js} +38 -72
- package/bundle/oauth2-provider-TRRJCE2P.js +235 -0
- package/bundle/{start-KOAGXRA2.js → start-3LEQZELI.js} +6 -6
- package/bundle/{start-XLIGOOW3.js → start-FH2E2VQ2.js} +6 -6
- package/bundle/{start-DJ6EBFEA.js → start-FPEO7KCZ.js} +6 -6
- package/bundle/start-J7G6YXDJ.js +18 -0
- package/package.json +1 -1
|
@@ -155,13 +155,13 @@ import {
|
|
|
155
155
|
widestLineFromStyledChars,
|
|
156
156
|
wordBreakStyledChars,
|
|
157
157
|
wrapStyledChars
|
|
158
|
-
} from "./chunk-
|
|
158
|
+
} from "./chunk-BO72FGK2.js";
|
|
159
159
|
import {
|
|
160
160
|
appEvents
|
|
161
161
|
} from "./chunk-5PS3AYFU.js";
|
|
162
162
|
import {
|
|
163
163
|
require_source
|
|
164
|
-
} from "./chunk-
|
|
164
|
+
} from "./chunk-4KX3ETW3.js";
|
|
165
165
|
import {
|
|
166
166
|
ACTIVE_SHELL_MAX_LINES,
|
|
167
167
|
COMPACT_TOOL_SUBVIEW_MAX_LINES,
|
|
@@ -211,24 +211,24 @@ import {
|
|
|
211
211
|
stringWidth,
|
|
212
212
|
stripUnsafeCharacters,
|
|
213
213
|
toCodePoints
|
|
214
|
-
} from "./chunk-
|
|
214
|
+
} from "./chunk-6WWGBNKT.js";
|
|
215
215
|
import {
|
|
216
216
|
handleAutoUpdate,
|
|
217
217
|
isDevelopment,
|
|
218
218
|
relaunchApp,
|
|
219
219
|
setUpdateHandler
|
|
220
|
-
} from "./chunk-
|
|
220
|
+
} from "./chunk-NB2NOE4L.js";
|
|
221
221
|
import {
|
|
222
222
|
isTodoList,
|
|
223
223
|
mapCoreStatusToDisplayStatus,
|
|
224
224
|
require_react
|
|
225
|
-
} from "./chunk-
|
|
225
|
+
} from "./chunk-E3KBY4EQ.js";
|
|
226
226
|
import {
|
|
227
227
|
registerCleanup,
|
|
228
228
|
removeCleanup,
|
|
229
229
|
runExitCleanup,
|
|
230
230
|
setupTtyCheck
|
|
231
|
-
} from "./chunk-
|
|
231
|
+
} from "./chunk-HVWNKZSB.js";
|
|
232
232
|
import {
|
|
233
233
|
ACTIVATE_SKILL_TOOL_NAME,
|
|
234
234
|
AGENT_TOOL_NAME,
|
|
@@ -410,7 +410,7 @@ import {
|
|
|
410
410
|
validatePlanContent,
|
|
411
411
|
validatePlanPath,
|
|
412
412
|
writeToStdout
|
|
413
|
-
} from "./chunk-
|
|
413
|
+
} from "./chunk-R52453KY.js";
|
|
414
414
|
import "./chunk-6HI7VNOG.js";
|
|
415
415
|
import "./chunk-TUDYL3X4.js";
|
|
416
416
|
import "./chunk-IUUIT4SU.js";
|
|
@@ -33702,7 +33702,7 @@ ${queuedText}` : queuedText;
|
|
|
33702
33702
|
if (keyMatchers["app.showErrorDetails" /* SHOW_ERROR_DETAILS */](key)) {
|
|
33703
33703
|
if (settings.merged.general.devtools) {
|
|
33704
33704
|
void (async () => {
|
|
33705
|
-
const { toggleDevToolsPanel } = await import("./devtoolsService-
|
|
33705
|
+
const { toggleDevToolsPanel } = await import("./devtoolsService-XYSZCMQM.js");
|
|
33706
33706
|
await toggleDevToolsPanel(
|
|
33707
33707
|
config,
|
|
33708
33708
|
showErrorDetails,
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
DEFAULT_PORT,
|
|
4
4
|
getBinaryPath,
|
|
5
5
|
isServerRunning
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-TCAVPMJX.js";
|
|
7
|
+
import "./chunk-CJHCK2YW.js";
|
|
8
8
|
import {
|
|
9
9
|
debugLogger
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-5YTIYFJO.js";
|
|
11
11
|
import "./chunk-6HI7VNOG.js";
|
|
12
12
|
import "./chunk-TUDYL3X4.js";
|
|
13
13
|
import "./chunk-IUUIT4SU.js";
|
|
@@ -41,7 +41,7 @@ var LiteRtServerManager = class {
|
|
|
41
41
|
`[LiteRtServerManager] Auto-starting LiteRT server on port ${port}...`
|
|
42
42
|
);
|
|
43
43
|
try {
|
|
44
|
-
const { startServer } = await import("./start-
|
|
44
|
+
const { startServer } = await import("./start-3LEQZELI.js");
|
|
45
45
|
const started = await startServer(binaryPath, port);
|
|
46
46
|
if (started) {
|
|
47
47
|
debugLogger.log(`[LiteRtServerManager] Server started on port ${port}`);
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
DEFAULT_PORT,
|
|
4
4
|
getBinaryPath,
|
|
5
5
|
isServerRunning
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-IGJG7DNZ.js";
|
|
7
|
+
import "./chunk-OQLEYMM2.js";
|
|
8
8
|
import {
|
|
9
9
|
debugLogger
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-565MWDPP.js";
|
|
11
11
|
import "./chunk-6HI7VNOG.js";
|
|
12
12
|
import "./chunk-TUDYL3X4.js";
|
|
13
13
|
import "./chunk-IUUIT4SU.js";
|
|
@@ -41,7 +41,7 @@ var LiteRtServerManager = class {
|
|
|
41
41
|
`[LiteRtServerManager] Auto-starting LiteRT server on port ${port}...`
|
|
42
42
|
);
|
|
43
43
|
try {
|
|
44
|
-
const { startServer } = await import("./start-
|
|
44
|
+
const { startServer } = await import("./start-J7G6YXDJ.js");
|
|
45
45
|
const started = await startServer(binaryPath, port);
|
|
46
46
|
if (started) {
|
|
47
47
|
debugLogger.log(`[LiteRtServerManager] Server started on port ${port}`);
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
DEFAULT_PORT,
|
|
4
4
|
getBinaryPath,
|
|
5
5
|
isServerRunning
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-6WWGBNKT.js";
|
|
7
|
+
import "./chunk-E3KBY4EQ.js";
|
|
8
8
|
import {
|
|
9
9
|
debugLogger
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-R52453KY.js";
|
|
11
11
|
import "./chunk-6HI7VNOG.js";
|
|
12
12
|
import "./chunk-TUDYL3X4.js";
|
|
13
13
|
import "./chunk-IUUIT4SU.js";
|
|
@@ -41,7 +41,7 @@ var LiteRtServerManager = class {
|
|
|
41
41
|
`[LiteRtServerManager] Auto-starting LiteRT server on port ${port}...`
|
|
42
42
|
);
|
|
43
43
|
try {
|
|
44
|
-
const { startServer } = await import("./start-
|
|
44
|
+
const { startServer } = await import("./start-FPEO7KCZ.js");
|
|
45
45
|
const started = await startServer(binaryPath, port);
|
|
46
46
|
if (started) {
|
|
47
47
|
debugLogger.log(`[LiteRtServerManager] Server started on port ${port}`);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const require = (await import('node:module')).createRequire(import.meta.url); const __chunk_filename = (await import('node:url')).fileURLToPath(import.meta.url); const __chunk_dirname = (await import('node:path')).dirname(__chunk_filename);
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_PORT,
|
|
4
|
+
getBinaryPath,
|
|
5
|
+
isServerRunning
|
|
6
|
+
} from "./chunk-K43EAKOP.js";
|
|
7
|
+
import "./chunk-FEY3T6LA.js";
|
|
8
|
+
import {
|
|
9
|
+
debugLogger
|
|
10
|
+
} from "./chunk-DDJWQSDN.js";
|
|
11
|
+
import "./chunk-6HI7VNOG.js";
|
|
12
|
+
import "./chunk-TUDYL3X4.js";
|
|
13
|
+
import "./chunk-IUUIT4SU.js";
|
|
14
|
+
import "./chunk-34MYV7JD.js";
|
|
15
|
+
|
|
16
|
+
// packages/cli/src/services/liteRtServerManager.ts
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
var LiteRtServerManager = class {
|
|
19
|
+
static async ensureRunning(gemmaSettings) {
|
|
20
|
+
if (!gemmaSettings?.enabled) return;
|
|
21
|
+
if (gemmaSettings.autoStartServer === false) return;
|
|
22
|
+
const binaryPath = getBinaryPath();
|
|
23
|
+
if (!binaryPath || !fs.existsSync(binaryPath)) {
|
|
24
|
+
debugLogger.log(
|
|
25
|
+
'[LiteRtServerManager] Binary not installed, skipping auto-start. Run "gemini gemma setup".'
|
|
26
|
+
);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const port = parseInt(
|
|
30
|
+
gemmaSettings.classifier?.host?.match(/:(\d+)/)?.[1] ?? "",
|
|
31
|
+
10
|
|
32
|
+
) || DEFAULT_PORT;
|
|
33
|
+
const running = await isServerRunning(port);
|
|
34
|
+
if (running) {
|
|
35
|
+
debugLogger.log(
|
|
36
|
+
`[LiteRtServerManager] Server already running on port ${port}`
|
|
37
|
+
);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
debugLogger.log(
|
|
41
|
+
`[LiteRtServerManager] Auto-starting LiteRT server on port ${port}...`
|
|
42
|
+
);
|
|
43
|
+
try {
|
|
44
|
+
const { startServer } = await import("./start-FH2E2VQ2.js");
|
|
45
|
+
const started = await startServer(binaryPath, port);
|
|
46
|
+
if (started) {
|
|
47
|
+
debugLogger.log(`[LiteRtServerManager] Server started on port ${port}`);
|
|
48
|
+
} else {
|
|
49
|
+
debugLogger.warn(
|
|
50
|
+
`[LiteRtServerManager] Server may not have started correctly on port ${port}`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
} catch (error) {
|
|
54
|
+
debugLogger.warn("[LiteRtServerManager] Auto-start failed:", error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
export {
|
|
59
|
+
LiteRtServerManager
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* @license
|
|
63
|
+
* Copyright 2026 Google LLC
|
|
64
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
65
|
+
*/
|
|
@@ -16,35 +16,35 @@ import {
|
|
|
16
16
|
openBrowserSecurely,
|
|
17
17
|
refreshAccessToken,
|
|
18
18
|
startCallbackServer
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-565MWDPP.js";
|
|
20
20
|
import "./chunk-6HI7VNOG.js";
|
|
21
21
|
import "./chunk-TUDYL3X4.js";
|
|
22
22
|
import "./chunk-IUUIT4SU.js";
|
|
23
23
|
import "./chunk-34MYV7JD.js";
|
|
24
24
|
|
|
25
|
-
// packages/core/src/agents/auth-provider/oauth2-provider.
|
|
25
|
+
// packages/core/dist/src/agents/auth-provider/oauth2-provider.js
|
|
26
26
|
var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
27
|
+
config;
|
|
28
|
+
agentName;
|
|
29
|
+
agentCardUrl;
|
|
30
|
+
type = "oauth2";
|
|
31
|
+
tokenStorage;
|
|
32
|
+
cachedToken = null;
|
|
33
|
+
/** Resolved OAuth URLs — may come from config or agent card. */
|
|
34
|
+
authorizationUrl;
|
|
35
|
+
tokenUrl;
|
|
36
|
+
scopes;
|
|
27
37
|
constructor(config, agentName, agentCard, agentCardUrl) {
|
|
28
38
|
super();
|
|
29
39
|
this.config = config;
|
|
30
40
|
this.agentName = agentName;
|
|
31
41
|
this.agentCardUrl = agentCardUrl;
|
|
32
|
-
this.tokenStorage = new MCPOAuthTokenStorage(
|
|
33
|
-
Storage.getA2AOAuthTokensPath(),
|
|
34
|
-
"gemini-cli-a2a"
|
|
35
|
-
);
|
|
42
|
+
this.tokenStorage = new MCPOAuthTokenStorage(Storage.getA2AOAuthTokensPath(), "gemini-cli-a2a");
|
|
36
43
|
this.authorizationUrl = config.authorization_url;
|
|
37
44
|
this.tokenUrl = config.token_url;
|
|
38
45
|
this.scopes = config.scopes;
|
|
39
46
|
this.mergeAgentCardDefaults(agentCard);
|
|
40
47
|
}
|
|
41
|
-
type = "oauth2";
|
|
42
|
-
tokenStorage;
|
|
43
|
-
cachedToken = null;
|
|
44
|
-
/** Resolved OAuth URLs — may come from config or agent card. */
|
|
45
|
-
authorizationUrl;
|
|
46
|
-
tokenUrl;
|
|
47
|
-
scopes;
|
|
48
48
|
/**
|
|
49
49
|
* Initialize the provider by loading any persisted token from storage.
|
|
50
50
|
* Also discovers OAuth URLs from the agent card if not yet resolved.
|
|
@@ -56,9 +56,7 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
56
56
|
const credentials = await this.tokenStorage.getCredentials(this.agentName);
|
|
57
57
|
if (credentials && !this.tokenStorage.isTokenExpired(credentials.token)) {
|
|
58
58
|
this.cachedToken = credentials.token;
|
|
59
|
-
debugLogger.debug(
|
|
60
|
-
`[OAuth2AuthProvider] Loaded valid cached token for "${this.agentName}"`
|
|
61
|
-
);
|
|
59
|
+
debugLogger.debug(`[OAuth2AuthProvider] Loaded valid cached token for "${this.agentName}"`);
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
/**
|
|
@@ -71,25 +69,16 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
71
69
|
}
|
|
72
70
|
if (this.cachedToken?.refreshToken && this.tokenUrl && this.config.client_id) {
|
|
73
71
|
try {
|
|
74
|
-
const refreshed = await refreshAccessToken(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
this.cachedToken.refreshToken,
|
|
81
|
-
this.tokenUrl
|
|
82
|
-
);
|
|
83
|
-
this.cachedToken = this.toOAuthToken(
|
|
84
|
-
refreshed,
|
|
85
|
-
this.cachedToken.refreshToken
|
|
86
|
-
);
|
|
72
|
+
const refreshed = await refreshAccessToken({
|
|
73
|
+
clientId: this.config.client_id,
|
|
74
|
+
clientSecret: this.config.client_secret,
|
|
75
|
+
scopes: this.scopes
|
|
76
|
+
}, this.cachedToken.refreshToken, this.tokenUrl);
|
|
77
|
+
this.cachedToken = this.toOAuthToken(refreshed, this.cachedToken.refreshToken);
|
|
87
78
|
await this.persistToken();
|
|
88
79
|
return { Authorization: `Bearer ${this.cachedToken.accessToken}` };
|
|
89
80
|
} catch (error) {
|
|
90
|
-
debugLogger.debug(
|
|
91
|
-
`[OAuth2AuthProvider] Refresh failed, falling back to interactive flow: ${getErrorMessage(error)}`
|
|
92
|
-
);
|
|
81
|
+
debugLogger.debug(`[OAuth2AuthProvider] Refresh failed, falling back to interactive flow: ${getErrorMessage(error)}`);
|
|
93
82
|
await this.tokenStorage.deleteCredentials(this.agentName);
|
|
94
83
|
}
|
|
95
84
|
}
|
|
@@ -108,9 +97,7 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
108
97
|
return void 0;
|
|
109
98
|
}
|
|
110
99
|
this.authRetryCount++;
|
|
111
|
-
debugLogger.debug(
|
|
112
|
-
"[OAuth2AuthProvider] Auth failure, clearing token and re-authenticating"
|
|
113
|
-
);
|
|
100
|
+
debugLogger.debug("[OAuth2AuthProvider] Auth failure, clearing token and re-authenticating");
|
|
114
101
|
this.cachedToken = null;
|
|
115
102
|
await this.tokenStorage.deleteCredentials(this.agentName);
|
|
116
103
|
return this.headers();
|
|
@@ -123,7 +110,8 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
123
110
|
* `securitySchemes` when not already provided via user config.
|
|
124
111
|
*/
|
|
125
112
|
mergeAgentCardDefaults(agentCard) {
|
|
126
|
-
if (!agentCard?.securitySchemes)
|
|
113
|
+
if (!agentCard?.securitySchemes)
|
|
114
|
+
return;
|
|
127
115
|
for (const scheme of Object.values(agentCard.securitySchemes)) {
|
|
128
116
|
if (scheme.type === "oauth2" && scheme.flows.authorizationCode) {
|
|
129
117
|
const flow = scheme.flows.authorizationCode;
|
|
@@ -139,18 +127,15 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
139
127
|
* (which normalizes proto-format cards) and extract OAuth2 URLs.
|
|
140
128
|
*/
|
|
141
129
|
async fetchAgentCardDefaults() {
|
|
142
|
-
if (!this.agentCardUrl)
|
|
130
|
+
if (!this.agentCardUrl)
|
|
131
|
+
return;
|
|
143
132
|
try {
|
|
144
|
-
debugLogger.debug(
|
|
145
|
-
`[OAuth2AuthProvider] Fetching agent card from ${this.agentCardUrl}`
|
|
146
|
-
);
|
|
133
|
+
debugLogger.debug(`[OAuth2AuthProvider] Fetching agent card from ${this.agentCardUrl}`);
|
|
147
134
|
const resolver = new DefaultAgentCardResolver();
|
|
148
135
|
const card = await resolver.resolve(this.agentCardUrl, "");
|
|
149
136
|
this.mergeAgentCardDefaults(card);
|
|
150
137
|
} catch (error) {
|
|
151
|
-
debugLogger.warn(
|
|
152
|
-
`[OAuth2AuthProvider] Could not fetch agent card for OAuth URL discovery: ${getErrorMessage(error)}`
|
|
153
|
-
);
|
|
138
|
+
debugLogger.warn(`[OAuth2AuthProvider] Could not fetch agent card for OAuth URL discovery: ${getErrorMessage(error)}`);
|
|
154
139
|
}
|
|
155
140
|
}
|
|
156
141
|
/**
|
|
@@ -158,14 +143,10 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
158
143
|
*/
|
|
159
144
|
async authenticateInteractively() {
|
|
160
145
|
if (!this.config.client_id) {
|
|
161
|
-
throw new Error(
|
|
162
|
-
`OAuth2 authentication for agent "${this.agentName}" requires a client_id. Add client_id to the auth config in your agent definition.`
|
|
163
|
-
);
|
|
146
|
+
throw new Error(`OAuth2 authentication for agent "${this.agentName}" requires a client_id. Add client_id to the auth config in your agent definition.`);
|
|
164
147
|
}
|
|
165
148
|
if (!this.authorizationUrl || !this.tokenUrl) {
|
|
166
|
-
throw new Error(
|
|
167
|
-
`OAuth2 authentication for agent "${this.agentName}" requires authorization_url and token_url. Provide them in the auth config or ensure the agent card exposes an oauth2 security scheme.`
|
|
168
|
-
);
|
|
149
|
+
throw new Error(`OAuth2 authentication for agent "${this.agentName}" requires authorization_url and token_url. Provide them in the auth config or ensure the agent card exposes an oauth2 security scheme.`);
|
|
169
150
|
}
|
|
170
151
|
const flowConfig = {
|
|
171
152
|
clientId: this.config.client_id,
|
|
@@ -184,36 +165,25 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
184
165
|
redirectPort,
|
|
185
166
|
/* resource= */
|
|
186
167
|
void 0
|
|
187
|
-
// No MCP resource parameter for A2A.
|
|
188
|
-
);
|
|
189
|
-
const consent = await getConsentForOauth(
|
|
190
|
-
`Authentication required for A2A agent: '${this.agentName}'.`
|
|
191
168
|
);
|
|
169
|
+
const consent = await getConsentForOauth(`Authentication required for A2A agent: '${this.agentName}'.`);
|
|
192
170
|
if (!consent) {
|
|
193
171
|
throw new FatalCancellationError("Authentication cancelled by user.");
|
|
194
172
|
}
|
|
195
|
-
coreEvents.emitFeedback(
|
|
196
|
-
"info",
|
|
197
|
-
`\u2192 Opening your browser for OAuth sign-in...
|
|
173
|
+
coreEvents.emitFeedback("info", `\u2192 Opening your browser for OAuth sign-in...
|
|
198
174
|
|
|
199
175
|
If the browser does not open, copy and paste this URL into your browser:
|
|
200
176
|
${authUrl}
|
|
201
177
|
|
|
202
178
|
\u{1F4A1} TIP: Triple-click to select the entire URL, then copy and paste it into your browser.
|
|
203
|
-
\u26A0\uFE0F Make sure to copy the COMPLETE URL - it may wrap across multiple lines.`
|
|
204
|
-
);
|
|
179
|
+
\u26A0\uFE0F Make sure to copy the COMPLETE URL - it may wrap across multiple lines.`);
|
|
205
180
|
try {
|
|
206
181
|
await openBrowserSecurely(authUrl);
|
|
207
182
|
} catch (error) {
|
|
208
|
-
debugLogger.warn(
|
|
209
|
-
"Failed to open browser automatically:",
|
|
210
|
-
getErrorMessage(error)
|
|
211
|
-
);
|
|
183
|
+
debugLogger.warn("Failed to open browser automatically:", getErrorMessage(error));
|
|
212
184
|
}
|
|
213
185
|
const { code } = await callbackServer.response;
|
|
214
|
-
debugLogger.debug(
|
|
215
|
-
"\u2713 Authorization code received, exchanging for tokens..."
|
|
216
|
-
);
|
|
186
|
+
debugLogger.debug("\u2713 Authorization code received, exchanging for tokens...");
|
|
217
187
|
const tokenResponse = await exchangeCodeForToken(
|
|
218
188
|
flowConfig,
|
|
219
189
|
code,
|
|
@@ -250,13 +220,9 @@ ${authUrl}
|
|
|
250
220
|
* Persist the current cached token to disk.
|
|
251
221
|
*/
|
|
252
222
|
async persistToken() {
|
|
253
|
-
if (!this.cachedToken)
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
this.cachedToken,
|
|
257
|
-
this.config.client_id,
|
|
258
|
-
this.tokenUrl
|
|
259
|
-
);
|
|
223
|
+
if (!this.cachedToken)
|
|
224
|
+
return;
|
|
225
|
+
await this.tokenStorage.saveToken(this.agentName, this.cachedToken, this.config.client_id, this.tokenUrl);
|
|
260
226
|
}
|
|
261
227
|
};
|
|
262
228
|
export {
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
const require = (await import('node:module')).createRequire(import.meta.url); const __chunk_filename = (await import('node:url')).fileURLToPath(import.meta.url); const __chunk_dirname = (await import('node:path')).dirname(__chunk_filename);
|
|
2
|
+
import {
|
|
3
|
+
BaseA2AAuthProvider,
|
|
4
|
+
DefaultAgentCardResolver,
|
|
5
|
+
FatalCancellationError,
|
|
6
|
+
MCPOAuthTokenStorage,
|
|
7
|
+
Storage,
|
|
8
|
+
buildAuthorizationUrl,
|
|
9
|
+
coreEvents,
|
|
10
|
+
debugLogger,
|
|
11
|
+
exchangeCodeForToken,
|
|
12
|
+
generatePKCEParams,
|
|
13
|
+
getConsentForOauth,
|
|
14
|
+
getErrorMessage,
|
|
15
|
+
getPortFromUrl,
|
|
16
|
+
openBrowserSecurely,
|
|
17
|
+
refreshAccessToken,
|
|
18
|
+
startCallbackServer
|
|
19
|
+
} from "./chunk-5YTIYFJO.js";
|
|
20
|
+
import "./chunk-6HI7VNOG.js";
|
|
21
|
+
import "./chunk-TUDYL3X4.js";
|
|
22
|
+
import "./chunk-IUUIT4SU.js";
|
|
23
|
+
import "./chunk-34MYV7JD.js";
|
|
24
|
+
|
|
25
|
+
// packages/core/dist/src/agents/auth-provider/oauth2-provider.js
|
|
26
|
+
var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
27
|
+
config;
|
|
28
|
+
agentName;
|
|
29
|
+
agentCardUrl;
|
|
30
|
+
type = "oauth2";
|
|
31
|
+
tokenStorage;
|
|
32
|
+
cachedToken = null;
|
|
33
|
+
/** Resolved OAuth URLs — may come from config or agent card. */
|
|
34
|
+
authorizationUrl;
|
|
35
|
+
tokenUrl;
|
|
36
|
+
scopes;
|
|
37
|
+
constructor(config, agentName, agentCard, agentCardUrl) {
|
|
38
|
+
super();
|
|
39
|
+
this.config = config;
|
|
40
|
+
this.agentName = agentName;
|
|
41
|
+
this.agentCardUrl = agentCardUrl;
|
|
42
|
+
this.tokenStorage = new MCPOAuthTokenStorage(Storage.getA2AOAuthTokensPath(), "gemini-cli-a2a");
|
|
43
|
+
this.authorizationUrl = config.authorization_url;
|
|
44
|
+
this.tokenUrl = config.token_url;
|
|
45
|
+
this.scopes = config.scopes;
|
|
46
|
+
this.mergeAgentCardDefaults(agentCard);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Initialize the provider by loading any persisted token from storage.
|
|
50
|
+
* Also discovers OAuth URLs from the agent card if not yet resolved.
|
|
51
|
+
*/
|
|
52
|
+
async initialize() {
|
|
53
|
+
if ((!this.authorizationUrl || !this.tokenUrl) && this.agentCardUrl) {
|
|
54
|
+
await this.fetchAgentCardDefaults();
|
|
55
|
+
}
|
|
56
|
+
const credentials = await this.tokenStorage.getCredentials(this.agentName);
|
|
57
|
+
if (credentials && !this.tokenStorage.isTokenExpired(credentials.token)) {
|
|
58
|
+
this.cachedToken = credentials.token;
|
|
59
|
+
debugLogger.debug(`[OAuth2AuthProvider] Loaded valid cached token for "${this.agentName}"`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Return an Authorization header with a valid Bearer token.
|
|
64
|
+
* Refreshes or triggers interactive auth as needed.
|
|
65
|
+
*/
|
|
66
|
+
async headers() {
|
|
67
|
+
if (this.cachedToken && !this.tokenStorage.isTokenExpired(this.cachedToken)) {
|
|
68
|
+
return { Authorization: `Bearer ${this.cachedToken.accessToken}` };
|
|
69
|
+
}
|
|
70
|
+
if (this.cachedToken?.refreshToken && this.tokenUrl && this.config.client_id) {
|
|
71
|
+
try {
|
|
72
|
+
const refreshed = await refreshAccessToken({
|
|
73
|
+
clientId: this.config.client_id,
|
|
74
|
+
clientSecret: this.config.client_secret,
|
|
75
|
+
scopes: this.scopes
|
|
76
|
+
}, this.cachedToken.refreshToken, this.tokenUrl);
|
|
77
|
+
this.cachedToken = this.toOAuthToken(refreshed, this.cachedToken.refreshToken);
|
|
78
|
+
await this.persistToken();
|
|
79
|
+
return { Authorization: `Bearer ${this.cachedToken.accessToken}` };
|
|
80
|
+
} catch (error) {
|
|
81
|
+
debugLogger.debug(`[OAuth2AuthProvider] Refresh failed, falling back to interactive flow: ${getErrorMessage(error)}`);
|
|
82
|
+
await this.tokenStorage.deleteCredentials(this.agentName);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
this.cachedToken = await this.authenticateInteractively();
|
|
86
|
+
return { Authorization: `Bearer ${this.cachedToken.accessToken}` };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* On 401/403, clear the cached token and re-authenticate (up to MAX_AUTH_RETRIES).
|
|
90
|
+
*/
|
|
91
|
+
async shouldRetryWithHeaders(_req, res) {
|
|
92
|
+
if (res.status !== 401 && res.status !== 403) {
|
|
93
|
+
this.authRetryCount = 0;
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
if (this.authRetryCount >= BaseA2AAuthProvider.MAX_AUTH_RETRIES) {
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
this.authRetryCount++;
|
|
100
|
+
debugLogger.debug("[OAuth2AuthProvider] Auth failure, clearing token and re-authenticating");
|
|
101
|
+
this.cachedToken = null;
|
|
102
|
+
await this.tokenStorage.deleteCredentials(this.agentName);
|
|
103
|
+
return this.headers();
|
|
104
|
+
}
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
// Private helpers
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
/**
|
|
109
|
+
* Merge authorization_url, token_url, and scopes from the agent card's
|
|
110
|
+
* `securitySchemes` when not already provided via user config.
|
|
111
|
+
*/
|
|
112
|
+
mergeAgentCardDefaults(agentCard) {
|
|
113
|
+
if (!agentCard?.securitySchemes)
|
|
114
|
+
return;
|
|
115
|
+
for (const scheme of Object.values(agentCard.securitySchemes)) {
|
|
116
|
+
if (scheme.type === "oauth2" && scheme.flows.authorizationCode) {
|
|
117
|
+
const flow = scheme.flows.authorizationCode;
|
|
118
|
+
this.authorizationUrl ??= flow.authorizationUrl;
|
|
119
|
+
this.tokenUrl ??= flow.tokenUrl;
|
|
120
|
+
this.scopes ??= Object.keys(flow.scopes);
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Fetch the agent card from `agentCardUrl` using `DefaultAgentCardResolver`
|
|
127
|
+
* (which normalizes proto-format cards) and extract OAuth2 URLs.
|
|
128
|
+
*/
|
|
129
|
+
async fetchAgentCardDefaults() {
|
|
130
|
+
if (!this.agentCardUrl)
|
|
131
|
+
return;
|
|
132
|
+
try {
|
|
133
|
+
debugLogger.debug(`[OAuth2AuthProvider] Fetching agent card from ${this.agentCardUrl}`);
|
|
134
|
+
const resolver = new DefaultAgentCardResolver();
|
|
135
|
+
const card = await resolver.resolve(this.agentCardUrl, "");
|
|
136
|
+
this.mergeAgentCardDefaults(card);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
debugLogger.warn(`[OAuth2AuthProvider] Could not fetch agent card for OAuth URL discovery: ${getErrorMessage(error)}`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Run a full OAuth 2.0 Authorization Code + PKCE flow through the browser.
|
|
143
|
+
*/
|
|
144
|
+
async authenticateInteractively() {
|
|
145
|
+
if (!this.config.client_id) {
|
|
146
|
+
throw new Error(`OAuth2 authentication for agent "${this.agentName}" requires a client_id. Add client_id to the auth config in your agent definition.`);
|
|
147
|
+
}
|
|
148
|
+
if (!this.authorizationUrl || !this.tokenUrl) {
|
|
149
|
+
throw new Error(`OAuth2 authentication for agent "${this.agentName}" requires authorization_url and token_url. Provide them in the auth config or ensure the agent card exposes an oauth2 security scheme.`);
|
|
150
|
+
}
|
|
151
|
+
const flowConfig = {
|
|
152
|
+
clientId: this.config.client_id,
|
|
153
|
+
clientSecret: this.config.client_secret,
|
|
154
|
+
authorizationUrl: this.authorizationUrl,
|
|
155
|
+
tokenUrl: this.tokenUrl,
|
|
156
|
+
scopes: this.scopes
|
|
157
|
+
};
|
|
158
|
+
const pkceParams = generatePKCEParams();
|
|
159
|
+
const preferredPort = getPortFromUrl(flowConfig.redirectUri);
|
|
160
|
+
const callbackServer = startCallbackServer(pkceParams.state, preferredPort);
|
|
161
|
+
const redirectPort = await callbackServer.port;
|
|
162
|
+
const authUrl = buildAuthorizationUrl(
|
|
163
|
+
flowConfig,
|
|
164
|
+
pkceParams,
|
|
165
|
+
redirectPort,
|
|
166
|
+
/* resource= */
|
|
167
|
+
void 0
|
|
168
|
+
);
|
|
169
|
+
const consent = await getConsentForOauth(`Authentication required for A2A agent: '${this.agentName}'.`);
|
|
170
|
+
if (!consent) {
|
|
171
|
+
throw new FatalCancellationError("Authentication cancelled by user.");
|
|
172
|
+
}
|
|
173
|
+
coreEvents.emitFeedback("info", `\u2192 Opening your browser for OAuth sign-in...
|
|
174
|
+
|
|
175
|
+
If the browser does not open, copy and paste this URL into your browser:
|
|
176
|
+
${authUrl}
|
|
177
|
+
|
|
178
|
+
\u{1F4A1} TIP: Triple-click to select the entire URL, then copy and paste it into your browser.
|
|
179
|
+
\u26A0\uFE0F Make sure to copy the COMPLETE URL - it may wrap across multiple lines.`);
|
|
180
|
+
try {
|
|
181
|
+
await openBrowserSecurely(authUrl);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
debugLogger.warn("Failed to open browser automatically:", getErrorMessage(error));
|
|
184
|
+
}
|
|
185
|
+
const { code } = await callbackServer.response;
|
|
186
|
+
debugLogger.debug("\u2713 Authorization code received, exchanging for tokens...");
|
|
187
|
+
const tokenResponse = await exchangeCodeForToken(
|
|
188
|
+
flowConfig,
|
|
189
|
+
code,
|
|
190
|
+
pkceParams.codeVerifier,
|
|
191
|
+
redirectPort,
|
|
192
|
+
/* resource= */
|
|
193
|
+
void 0
|
|
194
|
+
);
|
|
195
|
+
if (!tokenResponse.access_token) {
|
|
196
|
+
throw new Error("No access token received from token endpoint");
|
|
197
|
+
}
|
|
198
|
+
const token = this.toOAuthToken(tokenResponse);
|
|
199
|
+
this.cachedToken = token;
|
|
200
|
+
await this.persistToken();
|
|
201
|
+
debugLogger.debug("\u2713 OAuth2 authentication successful! Token saved.");
|
|
202
|
+
return token;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Convert an `OAuthTokenResponse` into the internal `OAuthToken` format.
|
|
206
|
+
*/
|
|
207
|
+
toOAuthToken(response, fallbackRefreshToken) {
|
|
208
|
+
const token = {
|
|
209
|
+
accessToken: response.access_token,
|
|
210
|
+
tokenType: response.token_type || "Bearer",
|
|
211
|
+
refreshToken: response.refresh_token || fallbackRefreshToken,
|
|
212
|
+
scope: response.scope
|
|
213
|
+
};
|
|
214
|
+
if (response.expires_in) {
|
|
215
|
+
token.expiresAt = Date.now() + response.expires_in * 1e3;
|
|
216
|
+
}
|
|
217
|
+
return token;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Persist the current cached token to disk.
|
|
221
|
+
*/
|
|
222
|
+
async persistToken() {
|
|
223
|
+
if (!this.cachedToken)
|
|
224
|
+
return;
|
|
225
|
+
await this.tokenStorage.saveToken(this.agentName, this.cachedToken, this.config.client_id, this.tokenUrl);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
export {
|
|
229
|
+
OAuth2AuthProvider
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* @license
|
|
233
|
+
* Copyright 2026 Google LLC
|
|
234
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
235
|
+
*/
|